123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- 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<Collider>() != null)
- {
- gameObject.GetComponent<Collider>().enabled = m_IsClickEditor;
- }
- }
- }
- private void Awake()
- {
- OnAwake();
- EventManager.Instance.Register(this, EventID.EVENT_1);
- }
- public virtual void OnAwake()
- {
- if (gameObject.GetComponent<Collider>() == null)
- {
- gameObject.AddComponent<BoxCollider>();
- }
- gameObject.GetComponent<Collider>().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);
- }
- }
|