海淀天下城电子沙盘单机版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
4.0 KiB

4 years ago
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<ToolAttributePanel>();
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<CloneGameObjInfo>().gameObjID != selectobj.GetComponent<CloneGameObjInfo>().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<ToolAttribute>();
SetTaskList(toolAttribute);
taskInput.text = toolAttribute.task;
}
/// <summary>
/// 水幕水带属性设置
/// </summary>
/// <param name="obj"></param>
/// <param name="id"></param>
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<ToolAttribute>();
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<Toggle>().group = content.GetComponent<ToggleGroup>();
item.transform.Find("TaskName").GetComponent<Text>().text = attribute.Tasklist[i];
}
}
}
}