using AX.MessageSystem; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; //Author:ZCG //CreatTime:12/2/2017 /// ///地面文本控制 /// public class TextControl : MonoBehaviour { TextMesh text; //private Vector3 initScale; public float Scale { get;private set; } public Color Color { get; private set; } public string InputField { get; private set; } public float initScale; public Color initColor; public string initInputField; void Awake() { Color = Color.white; Scale = 1; text = transform.Find("InstanceText").GetComponent(); InputField = text.text; MessageDispatcher.AddListener("ReplayEvent", ExecuteEvent); } private void ExecuteEvent(IMessage obj) { var eventData = (EventData)obj.Data; if (eventData.eventType == RecordEventType.ToolTask && eventData.cloneObjType == CloneObjType.InstanceText) { var arg = JsonUtility.FromJson(eventData.json); if (arg.objectName == gameObject.name) { SetScale(arg.Scale); SetText(arg.InputField); SetColor(arg.Color); } } } void OnDestroy() { MessageDispatcher.RemoveListener("ReplayEvent", ExecuteEvent); } private DateTime t1, t2; private void OnMouseDown() { //双击 if (!EventSystem.current.IsPointerOverGameObject()) { t2 = DateTime.Now; if (t2 - t1 < new TimeSpan(0, 0, 0, 0, 500)) { if (SelectedObjs.selectedObj == gameObject) { initColor = Color; initInputField = InputField; initScale = Scale; UIPlanInstanceText.Instance.LoadObjData(gameObject); } } t1 = t2; } } /// /// 设置大小 /// public void SetScale(float value) { transform.localScale = new Vector3(value, value, 1); Scale = value; //AddRecordEventChange(transform); } /// /// 设置文本 /// public void SetText(string str) { text.text = str; InputField = str; // AddRecordEventChange(transform); } /// /// 设置颜色 /// public void SetColor(Color value) { text.color = value; Color = value; } private void LateUpdate() { transform.LookAt(Camera.main.transform); } /// /// 确认 /// public void Confirm() { AddRecordEventChange(transform); } /// /// 撤回 /// public void Revocation() { SetColor(initColor); SetText(initInputField); SetScale(initScale); } /// /// 添加记录(克隆) /// public void AddRecordEventChange(Transform obj) { if (ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal) { var eventData = new EventData(); eventData.time = RecordManager.Instance.RecordTimer; eventData.cloneObjType = CloneObjType.InstanceText; eventData.eventType = RecordEventType.ToolTask; var data = new RecordInstanceText(); SetBaseData(data, obj); SetInstanceText(data, obj); string json = JsonUtility.ToJson(data); eventData.json = json; RecordManager.Instance.jsonData.eventDataList.Add(eventData); } } private void SetBaseData(RecordObjectBase data, Transform obj) { var msg = obj.GetComponent(); data.gameObjType = msg.gameObjType; data.objectName = obj.gameObject.name; data.buildNum = msg.buildNum; data.floorNum = msg.floorNum; data.interlayerNum = msg.interlayerNum; data.myTransform.setMyPosition(obj.localPosition); data.myTransform.setMyRotation(obj.localRotation); data.myTransform.setMyScale(obj.localScale); data.isActive = obj.gameObject.activeSelf; } private void SetInstanceText(RecordInstanceText data, Transform child) { var textControl = child.GetComponent(); data.Color = Color; data.Scale = Scale; data.InputField = InputField; } }