2025-02-12 17:36:00 +08:00
|
|
|
|
using QFramework;
|
|
|
|
|
|
using QFramework.Example;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
2025-04-18 13:53:59 +08:00
|
|
|
|
using Turing.Core.TuringInput;
|
2025-03-26 14:11:26 +08:00
|
|
|
|
using Turing.Samples;
|
|
|
|
|
|
using UnityEditor;
|
2025-02-12 17:36:00 +08:00
|
|
|
|
using UnityEngine;
|
2025-05-20 16:13:27 +08:00
|
|
|
|
using UnityEngine.EventSystems;
|
2025-02-12 17:36:00 +08:00
|
|
|
|
using XMLTool;
|
|
|
|
|
|
|
2025-04-15 11:00:04 +08:00
|
|
|
|
public class Body3DObjItem : MonoBehaviour
|
2025-02-12 17:36:00 +08:00
|
|
|
|
{
|
2025-02-13 11:02:16 +08:00
|
|
|
|
public Body3D.Body body;
|
2025-02-12 17:36:00 +08:00
|
|
|
|
|
2025-02-19 17:23:39 +08:00
|
|
|
|
public ObjectToggle objToggle;
|
2025-03-26 14:11:26 +08:00
|
|
|
|
IObjDrag objDrag;
|
2025-02-14 13:20:54 +08:00
|
|
|
|
// <20><>¼<EFBFBD><C2BC>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>갴<EFBFBD>µ<EFBFBD>ʱ<EFBFBD><CAB1>
|
|
|
|
|
|
private float lastClickTime;
|
|
|
|
|
|
// ˫<><CBAB><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
|
private const float doubleClickTimeThreshold = 0.3f;
|
2025-03-26 14:11:26 +08:00
|
|
|
|
|
2025-02-13 11:02:16 +08:00
|
|
|
|
private void Awake()
|
2025-02-12 17:36:00 +08:00
|
|
|
|
{
|
2025-05-09 16:27:09 +08:00
|
|
|
|
|
2025-03-26 14:11:26 +08:00
|
|
|
|
#if VR
|
|
|
|
|
|
#if Turing
|
2025-04-18 13:53:59 +08:00
|
|
|
|
|
|
|
|
|
|
UIRoot.Instance.transform.Find("ZStylus").GetComponent<TuringStylus>().OnButtonPressed.AddListener(OnButtonPressed);
|
|
|
|
|
|
UIRoot.Instance.transform.Find("ZStylus").GetComponent<TuringStylus>().OnButtonReleased.AddListener(OnButtonReleased);
|
|
|
|
|
|
UIRoot.Instance.transform.Find("ZStylus").GetComponent<TuringStylus>().OnObjectEntered.AddListener(OnEnter);
|
|
|
|
|
|
UIRoot.Instance.transform.Find("ZStylus").GetComponent<TuringStylus>().OnObjectExited.AddListener(OnExit);
|
|
|
|
|
|
UIRoot.Instance.transform.Find("ZMouse").GetComponent<TuringMouse>().OnButtonPressed.AddListener(OnButtonPressed);
|
|
|
|
|
|
UIRoot.Instance.transform.Find("ZMouse").GetComponent<TuringMouse>().OnButtonReleased.AddListener(OnButtonReleased);
|
|
|
|
|
|
UIRoot.Instance.transform.Find("ZMouse").GetComponent<TuringMouse>().OnObjectEntered.AddListener(OnEnter);
|
|
|
|
|
|
UIRoot.Instance.transform.Find("ZMouse").GetComponent<TuringMouse>().OnObjectExited.AddListener(OnExit);
|
|
|
|
|
|
|
|
|
|
|
|
gameObject.GetOrAddComponent<TuringDraggableEx>();
|
|
|
|
|
|
|
2025-03-26 14:11:26 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
#endif
|
2025-03-17 17:21:06 +08:00
|
|
|
|
}
|
2025-04-18 13:53:59 +08:00
|
|
|
|
#if Turing
|
|
|
|
|
|
bool isEnter = false;
|
|
|
|
|
|
private void OnExit(TuringPointer arg0, GameObject arg1)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (arg1 == gameObject)
|
|
|
|
|
|
{
|
|
|
|
|
|
isEnter = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-17 17:21:06 +08:00
|
|
|
|
|
2025-04-18 13:53:59 +08:00
|
|
|
|
private void OnEnter(TuringPointer arg0, GameObject arg1)
|
2025-04-18 15:03:20 +08:00
|
|
|
|
{
|
2025-04-18 13:53:59 +08:00
|
|
|
|
if (arg1 == gameObject)
|
|
|
|
|
|
{
|
|
|
|
|
|
isEnter = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnButtonReleased(TuringPointer arg0, int arg1)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (arg1 == 0 && isEnter)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnButtonPressed(TuringPointer arg0, int arg1)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (arg1 == 0 && isEnter)
|
|
|
|
|
|
{
|
|
|
|
|
|
OnMouseDown();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
2025-03-17 17:21:06 +08:00
|
|
|
|
|
2025-02-12 17:36:00 +08:00
|
|
|
|
|
|
|
|
|
|
public void Init(Body3D.Body body)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.body = body;
|
|
|
|
|
|
if (body.subBody == null || body.subBody.Count == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (body.toggle != null)
|
|
|
|
|
|
{
|
2025-02-13 11:02:16 +08:00
|
|
|
|
objToggle = gameObject.GetOrAddComponent<ObjectToggle>();
|
2025-02-12 17:36:00 +08:00
|
|
|
|
ObjectColorToggle colorToggle = null;
|
|
|
|
|
|
if (body.toggle.color != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
colorToggle = gameObject.GetOrAddComponent<ObjectColorToggle>();
|
2025-02-14 17:09:41 +08:00
|
|
|
|
if (string.IsNullOrEmpty(body.toggle.color.isOn) == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
colorToggle.isOnColor = Utility.ToColor(body.toggle.color.isOn);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (string.IsNullOrEmpty(body.toggle.color.isOff) == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
colorToggle.isOffColor = Utility.ToColor(body.toggle.color.isOff);
|
|
|
|
|
|
}
|
2025-02-12 17:36:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
objToggle.OnValueChanged.AddListener(isOn =>
|
|
|
|
|
|
{
|
2025-02-13 17:39:33 +08:00
|
|
|
|
if (Body3DController.Instance.CheckStatus(Body3DController.Status.Active))
|
2025-02-12 17:36:00 +08:00
|
|
|
|
{
|
2025-02-13 17:39:33 +08:00
|
|
|
|
if (isOn == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
gameObject.SetActive(false);
|
2025-02-14 08:58:46 +08:00
|
|
|
|
Body3DController.Instance.AddActiveObj(gameObject);
|
2025-02-13 17:39:33 +08:00
|
|
|
|
}
|
2025-02-13 11:02:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-03-17 14:51:03 +08:00
|
|
|
|
if (colorToggle != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (isOn)
|
|
|
|
|
|
{
|
|
|
|
|
|
colorToggle.SetColor(ObjectColorToggle.State.On);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
colorToggle.SetColor(ObjectColorToggle.State.Off);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-26 14:11:26 +08:00
|
|
|
|
#if VR
|
|
|
|
|
|
#if Turing
|
|
|
|
|
|
objDrag = gameObject.GetOrAddComponent<TuringDraggableEx>();
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#else
|
2025-02-13 17:39:33 +08:00
|
|
|
|
objDrag = gameObject.GetOrAddComponent<ObjDrag>();
|
2025-03-26 14:11:26 +08:00
|
|
|
|
#endif
|
2025-02-14 13:20:54 +08:00
|
|
|
|
objDrag.OnDragEnd.AddListener(obj =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Body3DController.Instance.AddMoveObj(gameObject);
|
|
|
|
|
|
});
|
2025-03-26 14:11:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-02-13 17:39:33 +08:00
|
|
|
|
RefreshDrag();
|
|
|
|
|
|
if (isOn)
|
|
|
|
|
|
{
|
|
|
|
|
|
TypeEventSystem.Global.Register<OnBody3DDragChanged>(OnBody3DDragHandler);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
TypeEventSystem.Global.UnRegister<OnBody3DDragChanged>(OnBody3DDragHandler);
|
|
|
|
|
|
}
|
2025-02-12 17:36:00 +08:00
|
|
|
|
}
|
2025-02-17 15:14:40 +08:00
|
|
|
|
TypeEventSystem.Global.Send<OnBody3DSelected>(new OnBody3DSelected() { isOn = isOn, obj = gameObject });
|
2025-02-13 17:39:33 +08:00
|
|
|
|
|
2025-02-12 17:36:00 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-02-14 13:20:54 +08:00
|
|
|
|
private void OnMouseDown()
|
|
|
|
|
|
{
|
2025-05-20 16:13:27 +08:00
|
|
|
|
|
|
|
|
|
|
if (EventSystem.current.IsPointerOverGameObject() == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-02-14 13:20:54 +08:00
|
|
|
|
// <20><><EFBFBD>㵱ǰʱ<C7B0><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ε<EFBFBD><CEB5><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
|
|
|
|
|
float currentTime = Time.time;
|
|
|
|
|
|
if (currentTime - lastClickTime < doubleClickTimeThreshold)
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>˫<EFBFBD><CBAB><EFBFBD>¼<EFBFBD>
|
|
|
|
|
|
OnDoubleClick();
|
|
|
|
|
|
}
|
|
|
|
|
|
lastClickTime = currentTime;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void OnDoubleClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Body3DController.Instance.CheckStatus(Body3DController.Status.Drag))
|
|
|
|
|
|
{
|
2025-03-26 14:11:26 +08:00
|
|
|
|
var drag = gameObject.GetComponent<IObjDrag>();
|
2025-02-14 13:20:54 +08:00
|
|
|
|
if (drag != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
drag.OnDoubleClick();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (Body3DController.Instance.CheckStatus(Body3DController.Status.Active) == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
float distance = 1;
|
|
|
|
|
|
if (float.TryParse(body.FocusDistance, out distance))
|
|
|
|
|
|
{
|
2025-02-14 17:09:41 +08:00
|
|
|
|
Show3DCamera.instance.FocusObj(gameObject.transform.position, distance, 0.5f);
|
2025-02-14 13:20:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-02-14 17:09:41 +08:00
|
|
|
|
Show3DCamera.instance.FocusObj(gameObject.transform.position, moveTime: 0.5f);
|
2025-02-14 13:20:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-02-12 17:36:00 +08:00
|
|
|
|
|
2025-02-13 11:02:16 +08:00
|
|
|
|
private void OnBody3DDragHandler(OnBody3DDragChanged drag)
|
|
|
|
|
|
{
|
|
|
|
|
|
RefreshDrag();
|
|
|
|
|
|
}
|
2025-02-12 17:36:00 +08:00
|
|
|
|
|
2025-02-13 11:02:16 +08:00
|
|
|
|
public void RefreshDrag()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (objToggle != null && objDrag != null)
|
|
|
|
|
|
{
|
2025-02-13 17:39:33 +08:00
|
|
|
|
objDrag.isOn = objToggle.isOn && Body3DController.Instance.CheckStatus(Body3DController.Status.Drag);
|
2025-02-13 11:02:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-17 14:51:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-12 17:36:00 +08:00
|
|
|
|
}
|