123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class MaterialBtnItem : MonoBehaviour, EventObserver
- {
- private Toggle m_Toggle;
- private Image m_Image;
- private Text m_Text;
- private GameObject m_MaterialObj;
- private ObjectValue m_ObjectValue;
- private MaterialObjValue m_MatValue;
- private bool m_IsSelect;
- private bool m_IsCollider;
- public GameObject MaterialObj
- {
- get { return m_MaterialObj; }
- set { m_MaterialObj = value; }
- }
- public ObjectValue ObjValue
- {
- get { return m_ObjectValue; }
- set { m_ObjectValue = value; }
- }
- public MaterialObjValue MatValue
- {
- get { return m_MatValue; }
- set { m_MatValue = value; }
- }
- public bool IsCollider
- {
- get { return m_IsCollider; }
- set { m_IsCollider = value; }
- }
- public bool IsSelect
- {
- get { return m_IsSelect; }
- set { m_IsSelect = value; }
- }
- private void Awake()
- {
- IsSelect = false;
- EventManager.Instance.Register(this, EventID.EVENT_1);
- m_Toggle = GetComponent<Toggle>();
- m_Image = transform.Find("Image").GetComponent<Image>();
- m_Text = transform.Find("Text").GetComponent<Text>(); ;
- m_Toggle.onValueChanged.AddListener(OnValueChanged);
- }
- private void LateUpdate()
- {
- if (IsCollider && MaterialObj != null)
- {
- MaterialObj.transform.localScale = new Vector3(MaterialObj.transform.localScale.x, 1, MaterialObj.transform.localScale.z);
- }
- }
- private void OnValueChanged(bool b)
- {
- if (b)
- {
- EventData1 data1 = new EventData1(EventID.EVENT_1, MaterialObj);
- if (!IsSelect)
- {
- data1.Send();
- }
- SelectObj(true);
- }
- }
- public void HandleEvent(EventData data)
- {
- switch (data.ID)
- {
- case EventID.EVENT_1:
- EventData1 data1 = (EventData1)data;
- if (!m_Toggle.isOn && data1.SelectObj == MaterialObj)
- {
- m_Toggle.isOn = true;
- IsSelect = true;
- }
- else
- {
- IsSelect = false;
- }
- break;
- case EventID.EVENT_2:
- break;
- default:
- break;
- }
- }
- public void SetData(MaterialObjValue value, ObjectValue objValue)
- {
- IsCollider = false;
- m_MatValue = value;
- m_ObjectValue = objValue;
- MaterialObj = objValue.Object;
- m_Text.text = string.IsNullOrWhiteSpace(value.name) ? MaterialObj.name : value.name;
- //MaterialObj.transform.localPosition = m_ObjectValue.nowPos;
- //MaterialObj.transform.localEulerAngles = m_ObjectValue.nowRot;
- //MaterialObj.transform.localScale = m_ObjectValue.nowScale;
- //m_Image.sprite =
- }
- public void SetData(ObjectValue objValue)
- {
- IsCollider = true;
- m_ObjectValue = objValue;
- MaterialObj = objValue.Object;
- m_Text.text = "BoxCollider";
- MaterialObj.transform.localPosition = m_ObjectValue.nowPos;
- MaterialObj.transform.localEulerAngles = m_ObjectValue.nowRot;
- MaterialObj.transform.localScale = m_ObjectValue.nowScale;
- }
- public void InitMatObj()
- {
- if (m_ObjectValue != null)
- {
- m_ObjectValue.InitObjTransform();
- }
- if (IsCollider)
- {
- GameManager.Instance.SaveCurrentColliderValue(m_ObjectValue);
- }
- }
- public void SaveMatObj()
- {
- if (m_ObjectValue != null)
- {
- m_ObjectValue.SaveObjTransfoem();
- }
- if (IsCollider)
- {
- GameManager.Instance.SaveCurrentColliderValue(m_ObjectValue);
- }
- }
- public void ClearData()
- {
- m_Text.text = null;
- m_Image.sprite = null;
- MaterialObj = null;
- m_ObjectValue = null;
- IsCollider = false;
- IsSelect = false;
- }
- /// <summary>
- /// 选中物体状态改变
- /// </summary>
- /// <param name="isShow"></param>
- public void SelectObj(bool isShow)
- {
- Debug.Log(MaterialObj);
- if (MaterialObj != null)
- {
- Debug.Log(MaterialObj.GetComponent<EditorEventHandler>());
- MaterialObj.GetComponent<EditorEventHandler>().ChangeShow(isShow);
- }
- }
- private void OnDestroy()
- {
- //EventManager.Instance.Remove(this);
- }
- }
|