目的 在一个纯净的游戏环境下 , 查看释放技能后, 是否有节点一直增长。 判断两层子节点
using Flux; using Sirenix.OdinInspector; using Sirenix.OdinInspector.Editor; using System.Collections; using System.Collections.Generic; using System.Text; using UnityEditor; using UnityEngine; #if UNITY_EDITOR && !BOSS_EDITOR namespace FluxEditor { /// <summary> /// 目的:制作技能后,自我监测节点的增加情况,确保没有节点一直增长。 /// 进GameInfo 1 1 30 然后设置BossAction为一个比较纯净的Move ///释放技能后,查看技能结束后运行节点增长信息 /// </summary> public class FCheckNodeChildCount : OdinEditorWindow { public static FCheckNodeChildCount _instance = null; [MenuItem("Tools/CheckNodeChildCount")] public static void Open() { System.Type T = System.Type.GetType("UnityEditor.GameView,UnityEditor"); var gameWindow = EditorWindow.GetWindow(T); _instance = GetWindow<FCheckNodeChildCount>(); _instance.Show(); _instance.titleContent = new GUIContent("FCheckNodeChildCount"); _instance.position = new Rect(gameWindow.position.x + 50, gameWindow.position.y - 50, 600, 400); _instance.parentObj = GameObject.Find("ControllerObject(Clone)"); if (_instance.parentObj == null) { EditorUtility.DisplayDialog("", "1当前没有指定总节点ControllerObject(Clone) ?", "ok"); return; } _instance.parentNode = _instance.parentObj.transform; } [PropertyOrder(0)] private GameObject parentObj; [SceneObjectsOnly] public Transform parentNode; [Button("$ButtonName"), PropertyOrder(1)] public void CompareNodeInfo() { newTransList.Clear(); lostTransList.Clear(); addStr.Clear(); lostStr.Clear(); if (parentNode == null) { _instance.parentObj = GameObject.Find("ControllerObject(Clone)"); if (_instance.parentObj != null) { _instance.parentNode = _instance.parentObj.transform; } EditorUtility.DisplayDialog("", "2当前没有指定总节点?", "ok"); return; } //只获取二级子节点就可以 int firstChildCount = parentNode.childCount; if (isFirstClick) { for (int i = 0; i < firstChildCount; ++i) { var firstChid = parentNode.GetChild(i); firstTransList.Add(new TransHadInfo(firstChid, false)); int secondCount = firstChid.childCount; for (int j = 0; j < secondCount; ++j) { var secondChid = firstChid.GetChild(j); secondTransList.Add(new TransHadInfo(secondChid, false)); } } isFirstClick = false; } else { //重新读取所有节点,然后获取新节点: for (int i = 0; i < firstChildCount; ++i) { var firstChid = parentNode.GetChild(i); int findIndex = firstTransList.FindIndex(o => o.trans == firstChid); if (findIndex != -1) { firstTransList[findIndex].isHad = true; } else { newTransList.Add(firstChid); firstTransList.Add(new TransHadInfo(firstChid, true)); } //第二层 int secondCount = firstChid.childCount; for (int j = 0; j < secondCount; ++j) { var secondChid = firstChid.GetChild(j); int secondChidIndex = secondTransList.FindIndex(o => o.trans == secondChid); if (secondChidIndex != -1) { secondTransList[secondChidIndex].isHad = true; } else { newTransList.Add(secondChid); secondTransList.Add(new TransHadInfo(secondChid, true)); } } } //获取失去的节点: int curCount = firstTransList.Count; for (int i = curCount - 1; i >= 0; --i) { if (firstTransList[i].isHad) { firstTransList[i].isHad = false; } else { firstTransList.RemoveAt(i); lostTransList.Add(firstTransList[i]); } } curCount = secondTransList.Count; for (int i = curCount - 1; i >= 0; --i) { if (secondTransList[i].isHad) { secondTransList[i].isHad = false; } else { lostTransList.Add(secondTransList[i]); } } } if(newTransList.Count == 0 && lostTransList.Count == 0) { EditorUtility.DisplayDialog("","没有更改","ok"); } //得出结论: if (newTransList.Count > 0) { addStr.Append("新增个数:" + newTransList.Count + " "); } foreach (var item in newTransList) { addStr.Append("Name:" + item.name + " 父节点:" + item.parent.name + " "); } if (lostTransList.Count > 0) { lostStr.Append("减少总个数:" + lostTransList.Count + " "); } foreach (var item in lostTransList) { lostStr.Append("Name:" + item.curName + " 父节点:" + item.parentName + " "); } addInfos = addStr.ToString(); lostInfos = lostStr.ToString(); } [LabelText("新增:"), ShowIf("IsShowAddInfo")] [PropertyOrder(2), TextArea(10, 100)] public string addInfos = ""; [PropertyOrder(3), TextArea(10, 100)] [LabelText("减少:"), ShowIf("IsShowLostInfo")] public string lostInfos = ""; private StringBuilder addStr = new StringBuilder(); private StringBuilder lostStr = new StringBuilder(); [Button("清理并重新开始")] public void ClearInfo() { isFirstClick = true; firstTransList.Clear(); secondTransList.Clear(); addInfos = ""; lostInfos = ""; } private string ButtonName { get { if (isFirstClick) { return "第一次获取当前信息"; } else { return "和之前节点对比"; } } } private List<TransHadInfo> firstTransList = new List<TransHadInfo>(50); private List<TransHadInfo> secondTransList = new List<TransHadInfo>(500); private List<Transform> newTransList = new List<Transform>(); private List<TransHadInfo> lostTransList = new List<TransHadInfo>(); private bool isFirstClick = true; private bool IsShowAddInfo() { return newTransList.Count > 0; } private bool IsShowLostInfo() { return lostTransList.Count > 0; } private float timeCount = 1; protected override void OnGUI() { base.OnGUI(); if (parentNode == null) { timeCount -= Time.deltaTime; if (timeCount < 0) { _instance.parentObj = GameObject.Find("ControllerObject(Clone)"); if (_instance.parentObj != null) { _instance.parentNode = _instance.parentObj.transform; } } timeCount = 1; } } private class TransHadInfo { public TransHadInfo(Transform t, bool isH) { trans = t; isHad = isH; curName = trans.name; parentName = trans.parent.name; } public string curName; public string parentName; public Transform trans; public bool isHad = false; } } } #endif
using Flux;using Sirenix.OdinInspector;using Sirenix.OdinInspector.Editor;using System.Collections;using System.Collections.Generic;using System.Text;using UnityEditor;using UnityEngine;
#if UNITY_EDITOR && !BOSS_EDITORnamespace FluxEditor{ /// <summary> /// 目的:制作技能后,自我监测节点的增加情况,确保没有节点一直增长。 /// 进GameInfo 1 1 30 然后设置BossAction为一个比较纯净的Move ///释放技能后,查看技能结束后运行节点增长信息 /// </summary> public class FCheckNodeChildCount : OdinEditorWindow { public static FCheckNodeChildCount _instance = null;
[MenuItem("Tools/CheckNodeChildCount")] public static void Open() { System.Type T = System.Type.GetType("UnityEditor.GameView,UnityEditor"); var gameWindow = EditorWindow.GetWindow(T);
_instance = GetWindow<FCheckNodeChildCount>(); _instance.Show(); _instance.titleContent = new GUIContent("FCheckNodeChildCount"); _instance.position = new Rect(gameWindow.position.x + 50, gameWindow.position.y - 50, 600, 400);
_instance.parentObj = GameObject.Find("ControllerObject(Clone)");
if (_instance.parentObj == null) { EditorUtility.DisplayDialog("", "1当前没有指定总节点ControllerObject(Clone) ?", "ok"); return; } _instance.parentNode = _instance.parentObj.transform; } [PropertyOrder(0)] private GameObject parentObj; [SceneObjectsOnly] public Transform parentNode; [Button("$ButtonName"), PropertyOrder(1)] public void CompareNodeInfo() { newTransList.Clear(); lostTransList.Clear(); addStr.Clear(); lostStr.Clear(); if (parentNode == null) { _instance.parentObj = GameObject.Find("ControllerObject(Clone)");
if (_instance.parentObj != null) { _instance.parentNode = _instance.parentObj.transform; } EditorUtility.DisplayDialog("", "2当前没有指定总节点?", "ok"); return; } //只获取二级子节点就可以 int firstChildCount = parentNode.childCount; if (isFirstClick) { for (int i = 0; i < firstChildCount; ++i) { var firstChid = parentNode.GetChild(i); firstTransList.Add(new TransHadInfo(firstChid, false)); int secondCount = firstChid.childCount; for (int j = 0; j < secondCount; ++j) { var secondChid = firstChid.GetChild(j); secondTransList.Add(new TransHadInfo(secondChid, false)); } } isFirstClick = false; } else { //重新读取所有节点,然后获取新节点: for (int i = 0; i < firstChildCount; ++i) { var firstChid = parentNode.GetChild(i); int findIndex = firstTransList.FindIndex(o => o.trans == firstChid); if (findIndex != -1) { firstTransList[findIndex].isHad = true; } else { newTransList.Add(firstChid); firstTransList.Add(new TransHadInfo(firstChid, true)); } //第二层 int secondCount = firstChid.childCount; for (int j = 0; j < secondCount; ++j) { var secondChid = firstChid.GetChild(j); int secondChidIndex = secondTransList.FindIndex(o => o.trans == secondChid); if (secondChidIndex != -1) { secondTransList[secondChidIndex].isHad = true; } else { newTransList.Add(secondChid); secondTransList.Add(new TransHadInfo(secondChid, true)); } } }
//获取失去的节点: int curCount = firstTransList.Count; for (int i = curCount - 1; i >= 0; --i) { if (firstTransList[i].isHad) { firstTransList[i].isHad = false; } else { firstTransList.RemoveAt(i); lostTransList.Add(firstTransList[i]); } }
curCount = secondTransList.Count; for (int i = curCount - 1; i >= 0; --i) { if (secondTransList[i].isHad) { secondTransList[i].isHad = false; } else { lostTransList.Add(secondTransList[i]); } } }
if(newTransList.Count == 0 && lostTransList.Count == 0) { EditorUtility.DisplayDialog("","没有更改","ok"); }
//得出结论: if (newTransList.Count > 0) { addStr.Append("新增个数:" + newTransList.Count + "
"); } foreach (var item in newTransList) { addStr.Append("Name:" + item.name + " 父节点:" + item.parent.name + "
"); } if (lostTransList.Count > 0) { lostStr.Append("减少总个数:" + lostTransList.Count + "
"); } foreach (var item in lostTransList) { lostStr.Append("Name:" + item.curName + " 父节点:" + item.parentName + "
"); } addInfos = addStr.ToString(); lostInfos = lostStr.ToString(); } [LabelText("新增:"), ShowIf("IsShowAddInfo")] [PropertyOrder(2), TextArea(10, 100)] public string addInfos = ""; [PropertyOrder(3), TextArea(10, 100)] [LabelText("减少:"), ShowIf("IsShowLostInfo")] public string lostInfos = ""; private StringBuilder addStr = new StringBuilder(); private StringBuilder lostStr = new StringBuilder(); [Button("清理并重新开始")] public void ClearInfo() { isFirstClick = true; firstTransList.Clear(); secondTransList.Clear(); addInfos = ""; lostInfos = ""; }
private string ButtonName { get { if (isFirstClick) { return "第一次获取当前信息"; } else { return "和之前节点对比"; } } }
private List<TransHadInfo> firstTransList = new List<TransHadInfo>(50); private List<TransHadInfo> secondTransList = new List<TransHadInfo>(500); private List<Transform> newTransList = new List<Transform>(); private List<TransHadInfo> lostTransList = new List<TransHadInfo>(); private bool isFirstClick = true;
private bool IsShowAddInfo() { return newTransList.Count > 0; }
private bool IsShowLostInfo() { return lostTransList.Count > 0; }
private float timeCount = 1; protected override void OnGUI() { base.OnGUI();
if (parentNode == null) { timeCount -= Time.deltaTime; if (timeCount < 0) { _instance.parentObj = GameObject.Find("ControllerObject(Clone)");
if (_instance.parentObj != null) { _instance.parentNode = _instance.parentObj.transform; } } timeCount = 1; } }
private class TransHadInfo { public TransHadInfo(Transform t, bool isH) { trans = t; isHad = isH; curName = trans.name; parentName = trans.parent.name; }
public string curName; public string parentName; public Transform trans; public bool isHad = false; } }}#endif