using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using AX.MessageSystem; public class TreeViewItemButtonClick : MonoBehaviour { /// /// 点击删除元素按钮 /// public void TreeViewButtonDeleteClick() { transform.Find("TreeViewToggle").GetComponent().isOn = true; string tip = "确认删除图层 ?"; var list = new List();//得到该图层及其子图层的所有ID AddIDToList(GetComponent(), list); TempDataManager.Instance.LayerObjs.Clear(); MessageDispatcher.SendMessage("CheckIfHasObjs", list); if (TempDataManager.Instance.LayerObjs.Count > 0) { tip = "图层或其子图层包含素材,\n确认删除?"; } var TipWindow = Instantiate(Resources.Load("UIPrefab/TipWindow")); TipWindow.GetComponent().SetWindow( tip, new UnityEngine.Events.UnityAction(DeleteOKFunc), null); //GameObject tipwindow = Instantiate(Resources.Load("Prefabs/UI/TipWindow")); //tipwindow.GetComponent().SetWindow("确认删除?", DeleteOKFunc, null); } private void DeleteOKFunc() { var id = GetComponent().ID; //var childCount = GetComponent().GetChildrenNumber(); //for(int i = 0; i ().GetChildrenByIndex(i); // GetComponent().Controler.RemoveItem(child.ID);//删除选中项的孩子 //} //GetComponent().Controler.RemoveItem(id);//删除选中项 var list = new List(); AddIDToList(GetComponent(), list); for(int i = list.Count - 1; i >= 0; i--) { GetComponent().Controler.RemoveItem(list[i].ID); GetComponent().Controler._treeViewItems.Remove(list[i].gameObject); list[i].GetParent().RemoveChildren(list[i]); Destroy(list[i].gameObject); //list[i].gameObject.SetActive(false); } // GetComponent().Controler.GenerateTreeView(); GetComponent().Controler.RefreshTreeView(); GetComponent().Controler.HasEditFlag = true; var idList = new List(); foreach(var item in list) { idList.Add(item.ID); } NodeSet.Instance.DeleteXml(idList); idList = null; NodeSet.Instance.JiaZaiBtn.gameObject.SetActive(false); } private void AddIDToList(TreeViewItem__ item, List needDeleteList) { needDeleteList.Add(item); var childCount = item.GetChildrenNumber(); if (childCount > 0) { for(int i = 0; i < childCount; i++) { var child = item.GetChildrenByIndex(i); AddIDToList(child, needDeleteList); } } } /// /// 点击添加元素按钮 /// public void TreeViewButtonAddClick() { transform.Find("TreeViewToggle").GetComponent().isOn = true; GameObject inputwindow = Instantiate(Resources.Load("Prefabs/UI/InputWindow")); inputwindow.GetComponent().SetWindow("信息编辑", AddOKFunc, null); inputwindow.name = "TheInputWindow"; GetComponent().ShowChildren(); Debug.Log("新建层级"); } /// /// 切换是否可见模式 /// public void ChangeViewModeClick() { var flag = transform.Find("ViewButton/yes").gameObject.activeSelf; //flag为true当前是可见状态,要切换为不可见状态 SetView(!flag); TreeViewControl__.Instance.SetViewOfData(GetComponent().ID, !flag); } /// /// 编辑节点 /// public void TreeViewButtonEditClick() { MessageDispatcher.SendMessage("OPEN", (object)"NodeIntroShowWin", "CUBE"); NodeSet.Instance.GetMessageNode(this.gameObject); } public void SetView(bool flag) { transform.Find("ViewButton/yes").gameObject.SetActive(flag); transform.Find("ViewButton/no").gameObject.SetActive(!flag); } private void AddOKFunc() { var window = GameObject.Find("TheInputWindow"); var inputStr = window.transform.Find("InputField").GetComponent().text; if(inputStr == "") { MessageDispatcher.SendMessage("Operatinghints", (object)"请输入名称"); return; } if (TreeViewControl__.Instance.GetHierarchy_Name(GetComponent().GetHierarchy() + 1, inputStr)) { MessageDispatcher.SendMessage("Operatinghints", (object)"已经有此名字"); return; } var id = GetComponent().ID; TreeViewData data = new TreeViewData(); data.Name = inputStr; //data.ID = GetComponent().Controler.GetNewID(); data.ID = NodeSet.Instance.GetNextID(); data.ParentID = id; data.Hierarchy = GetComponent().GetHierarchy() + 1; GetComponent().Controler.Data.Add(data); GetComponent().Controler.InstanATreeViewItem(data); //GetComponent().Controler.GenerateTreeView();//在该方法中,生成树形元素的时候判断有没有对应的xml文件,设置字体大小是否自适应最佳 GetComponent().Controler.RefreshTreeView(); GetComponent().Controler.HasEditFlag = true; Destroy(window.gameObject); NodeSet.Instance.ADDXml(inputStr, data); if (TreeViewControl__.Instance.CheckFileTreeItems()) { NodeSet.Instance.JiaZaiBtn.gameObject.SetActive(true); } else { NodeSet.Instance.JiaZaiBtn.gameObject.SetActive(false); } //MessageDispatcher.SendMessage("AddNode", data); } }