111 lines
3.9 KiB
C#
111 lines
3.9 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using QFramework;
|
|
using XMLTool;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using GCSeries.Core;
|
|
using UnityEngine.EventSystems;
|
|
using System;
|
|
|
|
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 distanceMin = 0.2f;
|
|
public float distanceMax = 20f;
|
|
public float pitchMin = -30f;
|
|
public float pitchMax = 80;
|
|
public string deviceName;
|
|
}
|
|
public List<ObjData> datas;
|
|
}
|
|
public partial class UI3DObjShow : UIPanel
|
|
{
|
|
ResLoader loader;
|
|
GameObject curObj;
|
|
RectTransform rawImg;
|
|
protected override void OnInit(IUIData uiData = null)
|
|
{
|
|
loader = ResLoader.Allocate();
|
|
rawImg = DeviceRawImage.GetComponent<RectTransform>();
|
|
}
|
|
|
|
protected override void OnOpen(IUIData uiData = null)
|
|
{
|
|
mData = uiData as UI3DObjShowData ?? new UI3DObjShowData();
|
|
FreeCameraController.instance.SetLock(false, false);
|
|
Show3DCamera.instance.gameObject.SetActive(true);
|
|
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(curObj.transform, data.rotateSpeed, data.moveSpeed, data.distance, data.pitchMin, data.pitchMax, distanceMin: data.distanceMin, distanceMax: data.distanceMax, inputRect: rawImg);
|
|
}
|
|
else
|
|
{
|
|
if (curObj)
|
|
{
|
|
GameObject.Destroy(curObj);
|
|
curObj = null;
|
|
}
|
|
}
|
|
});
|
|
|
|
}
|
|
loader.LoadAsync(() =>
|
|
{
|
|
Right.gameObject.SetActive(mData.datas.Count > 1);
|
|
Content.GetChild(0).GetComponent<Toggle>().isOn = true;
|
|
});
|
|
}
|
|
|
|
|
|
protected override void OnShow()
|
|
{
|
|
}
|
|
|
|
protected override void OnHide()
|
|
{
|
|
FreeCameraController.instance.SetLock(true, true);
|
|
Show3DCamera.instance.gameObject.SetActive(false);
|
|
loader.Recycle2Cache();
|
|
}
|
|
|
|
protected override void OnClose()
|
|
{
|
|
}
|
|
|
|
}
|
|
}
|