Commit 8a423d39 authored by 潘梓豪's avatar 潘梓豪

更新预制体

parent 83af15aa
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class SensorDataManger : MonoBehaviour
{
// Start is called before the first frame update
public GameObject[] model1;
public GameObject[] model2;
public GameObject _prefab;
public GameObject _parent1;
public GameObject _parent2;
public Vector3 uiOffset = new Vector3(0, 2,3 ); // UI相对于模型的位置偏移
private GameObject uiInstance;
public string lineId1;
public string lineId2;
void Start()
{
//foreach (GameObject item in model1)
//{
// Create3dUI(item,_parent1);
//}
//foreach (GameObject item in model2)
//{
// Create3dUI(item, _parent2);
//}
}
// Update is called once per frame
void Update()
{
}
void Create3dUI(GameObject tagert_obj,GameObject _parent)
{
if (tagert_obj != null && _prefab != null)
{
// 在模型上方生成UI
uiInstance = Instantiate(_prefab, tagert_obj.transform.position + uiOffset, Quaternion.identity);
// 设置UI为世界空间
Canvas canvas = uiInstance.GetComponent<Canvas>();
if (canvas != null)
{
canvas.renderMode = RenderMode.WorldSpace;
}
// 设置UI跟随模型移动
uiInstance.transform.SetParent(_parent.transform);
uiInstance.transform.name = tagert_obj.name;
uiInstance.transform.localScale = new Vector3(0.01f, 0.01f, 0.01f);
//uiInstance.transform.position = tagert_obj.transform.position;
//uiInstance.GetComponent<RectTransform>().position=new Vector3()
}
else
{
Debug.LogError("目标模型或UI预制件未设置!");
}
}
public IEnumerator GetThreeModelSensorData1()
{
string jsonData = "{\"lineId\":\"" + lineId1 + "\"}";
string post = "";
while (true)
{
using (UnityWebRequest request = UnityWebRequest.PostWwwForm(post, jsonData))
{
// 设置请求头
request.SetRequestHeader("Content-Type", "application/json");
// 设置请求体
byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(jsonData);
request.uploadHandler = new UploadHandlerRaw(bodyRaw);
// 发送请求并等待响应
yield return request.SendWebRequest();
if (!string.IsNullOrEmpty(request.error))
{
Debug.LogError(request.error);
}
else
{
// 解析响应数据
string responseJson = request.downloadHandler.text;
}
}
yield return new WaitForSeconds(1f);
}
}
public IEnumerator GetThreeModelSensorData2()
{
string jsonData = "{\"lineId\":\"" + lineId2 + "\"}";
string post = "";
while (true)
{
using (UnityWebRequest request = UnityWebRequest.PostWwwForm(post, jsonData))
{
// 设置请求头
request.SetRequestHeader("Content-Type", "application/json");
// 设置请求体
byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(jsonData);
request.uploadHandler = new UploadHandlerRaw(bodyRaw);
// 发送请求并等待响应
yield return request.SendWebRequest();
if (!string.IsNullOrEmpty(request.error))
{
Debug.LogError(request.error);
}
else
{
// 解析响应数据
string responseJson = request.downloadHandler.text;
}
}
yield return new WaitForSeconds(1f);
}
}
}
fileFormatVersion: 2
guid: 05d56e7ba014d4848bc7a5d4f0ae7d38
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment