using AX.MessageSystem; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; //Author:ZCG //CreatTime:12/15/2017 /// /// ÉèÖÃÇøÓò /// public class SetArea : MonoBehaviour { public float High { get; private set; } public string Name { get; private set; } public Color Color { get; private set; } private float initHigh; private string initName; private Color initColor; private Vector3 pos; private MeshRenderer render; private TextMesh text; private DateTime t1; private DateTime t2; private void Awake() { text = transform.Find("info").Find("Name").GetComponent(); render = GetComponent(); High = 0; Name = text.text; Color = render.material.color; } private void Start() { MessageDispatcher.AddListener("ReplayEvent", ReplayAreaChange); } private void OnDestroy() { MessageDispatcher.RemoveListener("ReplayEvent", ReplayAreaChange); } private void AddRecordArea() { if (ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal) { var eventData = new EventData(); eventData.time = RecordManager.Instance.RecordTimer; eventData.cloneObjType = CloneObjType.SetArea; eventData.eventType = RecordEventType.SetAreaAttribute; var data = new RecordSetArea(); SetBaseData(data); SetSetAreaData(data); string json = JsonUtility.ToJson(data); eventData.json = json; RecordManager.Instance.jsonData.eventDataList.Add(eventData); } } private void ReplayAreaChange(IMessage obj) { var eventData = (EventData)obj.Data; if (eventData.cloneObjType == CloneObjType.SetArea && eventData.eventType == RecordEventType.SetAreaAttribute) { var jsonData = JsonUtility.FromJson(eventData.json); if (jsonData.objectName == gameObject.name) { SetColor(jsonData.color); SetHigh(jsonData.height); SetName(jsonData.areName); } } } private void SetBaseData(RecordSetArea data) { var msg = gameObject.GetComponent(); data.gameObjType = msg.gameObjType; data.objectName = gameObject.gameObject.name; data.buildNum = msg.buildNum; data.floorNum = msg.floorNum; data.interlayerNum = msg.interlayerNum; data.myTransform.setMyPosition(transform.localPosition); data.myTransform.setMyRotation(transform.localRotation); data.myTransform.setMyScale(transform.localScale); data.isActive = gameObject.activeSelf; if (gameObject.GetComponent()) { data.IsSelect = gameObject.GetComponent().selected; } } private void SetSetAreaData(RecordSetArea data) { data.areName = Name; data.color = Color; data.height = High; } public void SetHigh(float value) { pos = Vector3.zero; transform.localPosition = new Vector3(pos.x, pos.y + value, pos.z); High = value; //AddRecordArea(); } public void ReplayFrameData(RecordSetArea data) { SetName(data.areName); SetColor(data.color); SetHigh(data.height); } public void SetName(string value) { text.text = value; Name = value; //AddRecordArea(); } public void SetColor(Color value) { render.material.color = value; Color = value; //AddRecordArea(); } public void Confirm() { AddRecordArea(); } public void Revocation() { SetHigh(initHigh); SetName(initName); SetColor(initColor); } private void OnMouseDown() { //Ë«»÷ if (!EventSystem.current.IsPointerOverGameObject()) { t2 = DateTime.Now; if (t2 - t1 < new TimeSpan(0, 0, 0, 0, 500)) { if(SelectedObjs.selectedObj == gameObject) { initHigh = High; initName = Name; initColor = Color; UIPlanSetArea.Instance.LoadObjData(gameObject); } } t1 = t2; } } }