127 lines
3.4 KiB
C#
Raw Normal View History

2025-03-31 16:07:26 +08:00
using GCSeries.Core.Input;
2025-01-13 14:05:32 +08:00
using QFramework;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XMLTool;
2025-01-21 11:47:12 +08:00
using static OperationController;
2025-01-13 14:05:32 +08:00
public class Point3DItem : MonoBehaviour
{
Point3DQuestion.Data data;
[SerializeField]
private float rotSpeed = 180.0f;
public void Init(Point3DQuestion.Data data)
{
this.data = data;
2025-01-13 15:14:02 +08:00
if (string.IsNullOrEmpty(data.name) == false)
{
gameObject.name = data.name;
}
2025-01-13 14:05:32 +08:00
if (string.IsNullOrEmpty(data.deviceName))
{
gameObject.transform.position = data.pos;
gameObject.transform.eulerAngles = data.rotate;
gameObject.transform.localScale = data.scale;
}
else
{
GameObject device = DeviceController.Instance.GetDeviceObj(data.deviceName);
gameObject.transform.parent = device.transform;
2025-01-13 15:14:02 +08:00
gameObject.transform.localPosition = Vector3.zero;
gameObject.transform.localEulerAngles = Vector3.zero;
gameObject.transform.localScale = Vector3.one;
2025-01-13 14:05:32 +08:00
}
rotSpeed = data.rotateSpeed;
2025-01-19 19:47:16 +08:00
gameObject.GetComponent<SpriteRenderer>().sortingOrder = data.order;
2025-01-22 12:58:27 +08:00
TypeEventSystem.Global.Register<OnPoint3DQuestionDestroy>(OnObjDestroy);
2025-01-21 11:47:12 +08:00
TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged);
2025-01-13 14:05:32 +08:00
2025-03-31 16:07:26 +08:00
#if VR
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnObjectEntered.AddListener(OnObjEnter);
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnObjectExited.AddListener(OnObjExit);
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnClick.AddListener(OnClick);
#endif
}
#if VR
private void OnClick(ZPointer arg0, int arg1, GameObject arg2)
{
if (gameObject == arg2)
{
if (string.IsNullOrEmpty(data.clickEvent) == false)
{
StringEventSystem.Global.Send(data.clickEvent);
}
TypeEventSystem.Global.Send<OnPoint3DQuestionDestroy>();
}
}
private void OnObjExit(ZPointer arg0, GameObject arg1)
{
if (gameObject == arg1)
{
isEnter = false;
}
}
private void OnObjEnter(ZPointer arg0, GameObject arg1)
{
if (gameObject == arg1)
{
isEnter = true;
}
}
bool isEnter = false;
private void Update()
{
if (isEnter)
{
transform.Rotate(Vector3.forward * Time.deltaTime * rotSpeed);
}
2025-01-13 14:05:32 +08:00
}
2025-03-31 16:07:26 +08:00
#endif
2025-01-13 14:05:32 +08:00
2025-01-21 11:47:12 +08:00
private void OnStepChanged(StepStatusOnChange change)
{
OnObjDestroy(default);
}
2025-01-13 14:05:32 +08:00
private void OnObjDestroy(OnPoint3DQuestionDestroy destroy)
{
2025-01-22 12:58:27 +08:00
if (gameObject != null)
{
GameObject.Destroy(gameObject);
}
}
private void OnDestroy()
{
2025-01-21 11:47:12 +08:00
TypeEventSystem.Global.UnRegister<StepStatusOnChange>(OnStepChanged);
2025-01-22 12:58:27 +08:00
TypeEventSystem.Global.UnRegister<OnPoint3DQuestionDestroy>(OnObjDestroy);
2025-01-13 14:05:32 +08:00
}
private void OnMouseUpAsButton()
{
if (string.IsNullOrEmpty(data.clickEvent) == false)
{
StringEventSystem.Global.Send(data.clickEvent);
}
TypeEventSystem.Global.Send<OnPoint3DQuestionDestroy>();
}
private void OnMouseOver()
{
transform.Rotate(Vector3.forward * Time.deltaTime * rotSpeed);
}
}