162 lines
5.0 KiB
C#
162 lines
5.0 KiB
C#
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);
|
||
}
|
||
#if VR
|
||
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);
|
||
|
||
gameObject.GetOrAddComponent<DeviceDraggable>();
|
||
#endif
|
||
}
|
||
|
||
|
||
#if VR
|
||
|
||
private void OnClick(ZPointer arg0, int arg1, GameObject arg2)
|
||
{
|
||
if (gameObject == arg2)
|
||
{
|
||
var effect = gameObject.GetComponent<HighlightEffect>();
|
||
if (effect != null)
|
||
{
|
||
effect.highlighted = false;
|
||
}
|
||
}
|
||
}
|
||
private void OnObjExit(ZPointer arg0, GameObject arg1)
|
||
{
|
||
if (gameObject == arg1)
|
||
{
|
||
var trigger = gameObject.GetComponent<HighlightTrigger>();
|
||
if (trigger == null || trigger.enabled == false)
|
||
{
|
||
return;
|
||
}
|
||
var effect = gameObject.GetComponent<HighlightEffect>();
|
||
if (effect)
|
||
{
|
||
effect.highlighted = false;
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
private void OnObjEnter(ZPointer arg0, GameObject arg1)
|
||
{
|
||
if (gameObject == arg1)
|
||
{
|
||
var trigger = gameObject.GetComponent<HighlightTrigger>();
|
||
if (trigger == null || trigger.enabled == false)
|
||
{
|
||
return;
|
||
}
|
||
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;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
}
|