using AX.MessageSystem; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; public class PowerAttribute : MonoBehaviour { private string affiliation; private string task; private int number; private string typename; public PowerInfo PowerInfo; private DateTime t1, t2; public string[] Tasklist; public string Affiliation { get { return this.affiliation; } set { this.affiliation = value; PowerInfo.Squadron.text = this.affiliation + "-" + this.number; } } public string Task { get { return this.task; } set { this.task = value; PowerInfo.RenWu.text = this.task; } } public int Number { get { return this.number; } set { this.number = value; PowerInfo.Squadron.text = this.affiliation + "-" + this.number; } } public string TypeName { get { return typename; } set { typename = value; } } // Use this for initialization protected void Awake() { PowerInfo = transform.Find("info").GetComponent(); PowerInfo.gameObject.SetActive(GlobalVariable.InfoActive); this.number = int.Parse(PowerInfo.Squadron.text.Split('-')[1]); this.affiliation = PowerInfo.Squadron.text.Split('-')[0]; this.task = PowerInfo.RenWu.text; MessageDispatcher.AddListener("ShowHideInfo", InfoActive); MessageDispatcher.AddListener("RADIO_SELECTED_COMMAND", RadioSelect); MessageDispatcher.AddListener("ReplayEvent", ReplayAgent); } private void ReplayAgent(IMessage obj) { var eventData = (EventData)obj.Data; if (eventData.eventType == RecordEventType.PowerAttribute) { var data = JsonUtility.FromJson(eventData.json); if (data.GameId == GetComponent().GameObjID) { this.Task = data.Task; this.Affiliation = data.Affiliation; this.Number = data.Number; this.TypeName = data.TypeName; } } } private void RadioSelect(IMessage obj) { var id = (long)obj.Sender; if (id == GetComponent().GameObjID) PowerInfo.Squadron.color = Color.green; else PowerInfo.Squadron.color = Color.white; } private void OnDestroy() { MessageDispatcher.RemoveListener("ShowHideInfo", InfoActive); MessageDispatcher.RemoveListener("RADIO_SELECTED_COMMAND", RadioSelect); MessageDispatcher.RemoveListener("ReplayEvent", ReplayAgent); } private void InfoActive(IMessage obj) { PowerInfo.gameObject.SetActive(GlobalVariable.InfoActive); } private void OnMouseDown() { if (RecordEvent.IsReplay()) return; if (!EventSystem.current.IsPointerOverGameObject()) { t2 = DateTime.Now; if (t2 - t1 < new TimeSpan(0, 0, 0, 0, 500)) { MessageDispatcher.SendMessage("CANCEL_CLONEBTN_SELECTED_COMMAND"); PowerAttributePanel.GetInstance.SetAttribute(this.gameObject); } t1 = t2; } } }