using AX.MessageSystem; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class ToolAttributePanel : MonoBehaviour { public Button confirm; public Button cancel; public Button tasks; public GameObject taskListPanel; public InputField taskInput; public Text typeName; public GameObject selectobj; public RectTransform content; public GameObject taskItem; public ToolAttribute toolAttribute; public Button CloseButton; private static ToolAttributePanel instance; public static ToolAttributePanel Instance { get { if (instance == null) { Transform canvas = GameObject.Find("Canvas").transform; GameObject panel = Instantiate(Resources.Load("Prefab/Tool/ToolAttributePanel") as GameObject, canvas); instance = panel.transform.Find("ToolAttributePanel").GetComponent(); instance.Init(); } return instance; } } // Use this for initialization void Init () { CloseButton.onClick.AddListener(Cancel); confirm.onClick.AddListener(Confirm); cancel.onClick.AddListener(Cancel); tasks.onClick.AddListener(TaskList); //MessageDispatcher.AddListener("RADIO_SELECTED_COMMAND", RadioSelect); } private void Start() { MessageDispatcher.AddListener("SelectChange", selectchange); } private void OnDestroy() { //MessageDispatcher.RemoveListener("RADIO_SELECTED_COMMAND", RadioSelect); MessageDispatcher.RemoveListener("SelectChange", selectchange); } private void selectchange(IMessage obj) { transform.parent.gameObject.SetActive(false); } private void RadioSelect(IMessage obj) { if (SelectedObjs.selectedObj.GetComponent().gameObjID != selectobj.GetComponent().gameObjID ) { gameObject.SetActive(false); } } private void Confirm() { if ( string.IsNullOrEmpty(taskInput.text)) return; MessageDispatcher.SendMessage("TaskChange", (object)taskInput.text); transform.parent.gameObject.SetActive(false); } private void Cancel() { transform.parent.gameObject.SetActive(false); } private void TaskList() { taskListPanel.SetActive(!taskListPanel.activeSelf); } public void SetAttribute(GameObject obj, string typeName) { transform.parent.gameObject.SetActive(true); gameObject.SetActive(true); selectobj = obj; this.typeName.text = typeName; toolAttribute = obj.GetComponent(); SetTaskList(toolAttribute); taskInput.text = toolAttribute.task; } /// /// 水幕水带属性设置 /// /// /// public void SetAttribute(GameObject obj,long id, string typeName) { GameObject parentObj = EntitiesManager.Instance.GetEntityByID(id); transform.parent.gameObject.SetActive(true); gameObject.SetActive(true); selectobj = parentObj; this.typeName.text = typeName; toolAttribute = obj.GetComponent(); SetTaskList(toolAttribute); taskInput.text = toolAttribute.task; } private void SetTaskList(ToolAttribute attribute) { taskListPanel.SetActive(false); foreach (Transform item in content) { Destroy(item.gameObject); } if (attribute.Tasklist.Length > 0) { for (int i = 0; i < attribute.Tasklist.Length; i++) { var item = Instantiate(taskItem, content); item.GetComponent().group = content.GetComponent(); item.transform.Find("TaskName").GetComponent().text = attribute.Tasklist[i]; } } } }