天津23维预案
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.

166 lines
6.2 KiB

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