using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; /* * 相机上必须有发射射线的组件 * UI上直接添加此脚本 * 3D物体必须有碰撞器 */ public class EditorEventHandler : MonoBehaviour, EventObserver { [SerializeField, Tooltip("当前素材是否可通过点击进行编辑")] private bool m_IsClickEditor = true; [SerializeField] private MaterialType m_Type; public MaterialType Type { get { return m_Type; } set { m_Type = value; } } public bool IsClickEditor { get { return m_IsClickEditor; } set { m_IsClickEditor = value; if (gameObject.GetComponent() != null) { gameObject.GetComponent().enabled = m_IsClickEditor; } } } private void Awake() { OnAwake(); EventManager.Instance.Register(this, EventID.EVENT_1); } public virtual void OnAwake() { if (gameObject.GetComponent() == null) { gameObject.AddComponent(); } gameObject.GetComponent().enabled = m_IsClickEditor; ClickEventTriggerListener.Get(gameObject).onPointerClick = new ClickEventTriggerListener.PointDelegate(OnClick); } public virtual void OnClick(PointerEventData eventData) { Debug.Log(gameObject.name); EventData1 data1 = new EventData1(EventID.EVENT_1, gameObject); data1.Send(); } public void HandleEvent(EventData data) { switch (data.ID) { case EventID.EVENT_1: EventData1 data1 = (EventData1)data; if (data1.SelectObj == gameObject) { //当前物体外轮廓发光 ChangeShow(true); } else { //当前物体外轮廓隐藏显示 ChangeShow(false); } break; case EventID.EVENT_2: break; default: break; } } public void ChangeShow(bool isShow) { //Debug.Log(gameObject); } private void OnDestroy() { //EventManager.Instance.Remove(this); } }