2025-03-24 10:32:48 +08:00

151 lines
4.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using GCSeries.Core.Input;
using HighlightPlus;
using QFramework;
using QFramework.Example;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using static OperationController;
public class DeviceItem : MonoBehaviour
{
public XMLTool.Device device;
public TipItem tipItem;
public void Init(XMLTool.Device device)
{
this.device = device;
if (string.IsNullOrEmpty(device.HighColor) == false)
{
var effect = gameObject.GetOrAddComponent<HighlightEffect>();
gameObject.GetOrAddComponent<HighlightTrigger>();
//¶ÁÈ¡xmlÑÕÉ«²¢×ª»¯
effect.outlineColor = Utility.ToColor(device.HighColor);
StringEventSystem.Global.Register<string[]>(Global.HighLightTrigger, OnHighLightTriggerEvent);
TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged);
#if VR
effect.constantWidth = false;
#endif
}
if (device.MeshCollider)
{
gameObject.GetOrAddComponent<MeshCollider>();
}
else if (string.IsNullOrEmpty(device.BoxColliderSize) == false)
{
BoxCollider box = gameObject.GetOrAddComponent<BoxCollider>();
box.size = Utility.GetVector3FromStrArray(device.BoxColliderSize);
if (string.IsNullOrEmpty(device.BoxColliderCenter) == false)
{
box.center = Utility.GetVector3FromStrArray(device.BoxColliderCenter);
}
}
if (string.IsNullOrEmpty(device.Tip) == false)
{
tipItem = gameObject.GetOrAddComponent<TipItem>();
tipItem.Set(device.Tip);
}
UIRoot.Instance.transform.Find("ZMouse").GetComponent<ZPointer>().OnObjectEntered.AddListener(OnObjEnter);
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnObjectEntered.AddListener(OnObjEnter);
UIRoot.Instance.transform.Find("ZMouse").GetComponent<ZPointer>().OnObjectExited.AddListener(OnObjExit);
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnObjectExited.AddListener(OnObjExit);
UIRoot.Instance.transform.Find("ZMouse").GetComponent<ZPointer>().OnClick.AddListener(OnClick);
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnClick.AddListener(OnClick);
}
#if VR
private void OnClick(ZPointer arg0, int arg1, GameObject arg2)
{
Debug.LogError($"µ±Ç°ÎïÌ壺{gameObject.name} Ä¿±êÎïÌå:{arg2.name}");
if (gameObject == arg2)
{
Debug.LogError("OnClick:" + arg2.name);
var effect = gameObject.GetComponent<HighlightEffect>();
if (effect != null)
{
effect.highlighted = false;
}
}
}
private void OnObjExit(ZPointer arg0, GameObject arg1)
{
if (gameObject == arg1)
{
Debug.LogError("OnObjExit:" + arg1.name);
var effect = gameObject.GetComponent<HighlightEffect>();
if (effect)
{
effect.highlighted = false;
}
}
}
private void OnObjEnter(ZPointer arg0, GameObject arg1)
{
if (gameObject == arg1)
{
Debug.LogError("OnObjEnter:" + arg1.name);
var effect = gameObject.GetComponent<HighlightEffect>();
if (effect)
{
effect.highlighted = true;
}
}
}
#endif
private void OnStepChanged(StepStatusOnChange change)
{
var effect = gameObject.GetComponent<HighlightEffect>();
if (effect != null)
{
effect.highlighted = false;
}
}
public void Close()
{
device = null;
tipItem = null;
StringEventSystem.Global.UnRegister<string[]>(Global.HighLightTrigger, OnHighLightTriggerEvent);
TypeEventSystem.Global.UnRegister<StepStatusOnChange>(OnStepChanged);
}
private void OnHighLightTriggerEvent(string[] obj)
{
if (obj.Length > 0)
{
bool isActive = true;
bool.TryParse(obj[0], out isActive);
if (obj.Length == 1 || (obj.Length > 1 && obj[1] == device.Name))
{
var high = gameObject.GetComponent<HighlightTrigger>();
if (high != null)
{
gameObject.GetComponent<HighlightTrigger>().enabled = isActive;
}
else
{
Debug.LogError(device.Name + "ÉíÉÏûÓиßÁÁ×é¼þ");
}
}
}
}
private void OnMouseUpAsButton()
{
var effect = gameObject.GetComponent<HighlightEffect>();
if (effect != null)
{
effect.highlighted = false;
}
}
}