98 lines
3.4 KiB
C#
98 lines
3.4 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using QFramework;
|
|
using XMLTool;
|
|
using System.Collections.Generic;
|
|
using static UnityEditor.Progress;
|
|
using TMPro;
|
|
|
|
namespace QFramework.Example
|
|
{
|
|
public class UI3DObjShowData : UIPanelData
|
|
{
|
|
public class ObjData
|
|
{
|
|
public Vector3 rotate = Vector3.zero;
|
|
public Vector3 position = Vector3.zero;
|
|
public Vector3 scale = Vector3.one;
|
|
public float rotateSpeed = 10;
|
|
public float moveSpeed = 0.1f;
|
|
public float distance = 0.2f;
|
|
public float pitchMin = -30f;
|
|
public float pitchMax = 80;
|
|
public string deviceName;
|
|
}
|
|
public List<ObjData> datas;
|
|
}
|
|
public partial class UI3DObjShow : UIPanel
|
|
{
|
|
ResLoader loader;
|
|
GameObject curObj;
|
|
protected override void OnInit(IUIData uiData = null)
|
|
{
|
|
loader = ResLoader.Allocate();
|
|
}
|
|
|
|
protected override void OnOpen(IUIData uiData = null)
|
|
{
|
|
mData = uiData as UI3DObjShowData ?? new UI3DObjShowData();
|
|
FreeCameraController.instance.SetLock(false, false);
|
|
Content.RemoveAllChildren();
|
|
foreach (var data in mData.datas)
|
|
{
|
|
var item = DeviceController.Instance.GetDevice(data.deviceName);
|
|
GameObject obj = GameObject.Instantiate(ItemPrefab.gameObject, Content);
|
|
obj.name = item.Name;
|
|
obj.transform.Find("Name").GetComponent<TextMeshProUGUI>().text = item.Name;
|
|
Image icon = obj.transform.Find("IconBg/Icon").GetComponent<Image>();
|
|
var localImageUrl = Global.deviceIconsPath + item.Icon;
|
|
loader.Add2Load(localImageUrl.ToNetImageResName(),
|
|
(bool success, IRes res) =>
|
|
{
|
|
if (success)
|
|
{
|
|
icon.sprite = Utility.GetSprite(res.Asset as Texture2D);
|
|
}
|
|
});
|
|
obj.GetComponent<Toggle>().onValueChanged.AddListener(isOn =>
|
|
{
|
|
if (isOn)
|
|
{
|
|
curObj = GameObject.Instantiate(DeviceController.Instance.GetDeviceObj(data.deviceName));
|
|
curObj.transform.position = data.position;
|
|
curObj.transform.localScale = data.scale;
|
|
curObj.transform.eulerAngles = data.rotate;
|
|
curObj.gameObject.SetActive(true);
|
|
Show3DCamera.instance.Set(DeviceRawImage.texture.width, DeviceRawImage.texture.height, curObj.transform, data.rotateSpeed, data.moveSpeed, data.distance, data.pitchMin, data.pitchMax);
|
|
}
|
|
else
|
|
{
|
|
if (curObj)
|
|
{
|
|
Show3DCamera.instance.Clear();
|
|
GameObject.Destroy(curObj);
|
|
curObj = null;
|
|
}
|
|
}
|
|
});
|
|
|
|
}
|
|
loader.LoadAsync();
|
|
}
|
|
|
|
protected override void OnShow()
|
|
{
|
|
}
|
|
|
|
protected override void OnHide()
|
|
{
|
|
FreeCameraController.instance.SetLock(true, true);
|
|
loader.Recycle2Cache();
|
|
}
|
|
|
|
protected override void OnClose()
|
|
{
|
|
}
|
|
}
|
|
}
|