2024-12-14 18:27:59 +08:00
|
|
|
using HighlightPlus;
|
|
|
|
|
using QFramework;
|
|
|
|
|
using QFramework.Example;
|
2024-12-31 17:06:00 +08:00
|
|
|
using System;
|
2024-12-14 18:27:59 +08:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class DeviceItem : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public XMLTool.Device device;
|
|
|
|
|
public void Init(XMLTool.Device device)
|
|
|
|
|
{
|
|
|
|
|
this.device = device;
|
|
|
|
|
if (string.IsNullOrEmpty(device.HighColor) == false)
|
|
|
|
|
{
|
|
|
|
|
var effect = gameObject.GetOrAddComponent<HighlightEffect>();
|
|
|
|
|
gameObject.GetOrAddComponent<HighlightTrigger>();
|
|
|
|
|
effect.outlineColor = Color.green;
|
2024-12-31 17:06:00 +08:00
|
|
|
StringEventSystem.Global.Register<string[]>(Global.HighLightTrigger, OnHighLightTriggerEvent).UnRegisterWhenGameObjectDestroyed(gameObject);
|
2024-12-14 18:27:59 +08:00
|
|
|
}
|
|
|
|
|
if (device.MeshCollider)
|
|
|
|
|
{
|
|
|
|
|
gameObject.GetOrAddComponent<MeshCollider>();
|
|
|
|
|
}
|
2024-12-24 13:52:04 +08:00
|
|
|
else if (string.IsNullOrEmpty(device.BoxColliderSize) == false)
|
2024-12-14 18:27:59 +08:00
|
|
|
{
|
|
|
|
|
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)
|
2024-12-18 09:00:26 +08:00
|
|
|
{
|
|
|
|
|
gameObject.AddComponent<TipItem>().Set(device.Tip);
|
|
|
|
|
}
|
|
|
|
|
else
|
2024-12-14 18:27:59 +08:00
|
|
|
{
|
|
|
|
|
gameObject.AddComponent<TipItem>().Set(device.Name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-31 17:06:00 +08:00
|
|
|
private void OnHighLightTriggerEvent(string[] obj)
|
|
|
|
|
{
|
|
|
|
|
if (obj.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
bool isActive = true;
|
|
|
|
|
bool.TryParse(obj[0], out isActive);
|
|
|
|
|
gameObject.GetComponent<HighlightTrigger>().enabled = isActive;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-24 13:52:04 +08:00
|
|
|
private void OnMouseUpAsButton()
|
|
|
|
|
{
|
|
|
|
|
var effect = gameObject.GetComponent<HighlightEffect>();
|
|
|
|
|
if (effect != null)
|
|
|
|
|
{
|
|
|
|
|
effect.highlighted = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-14 18:27:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|