static void FindNextSelectedTag(FTagNode node, List <string> strList) { if (node != null && node.bToggle) { if (node.childs == null || node.childs.Count == 0) { // TODO Found strList.Add(node.GetTagTotalName()); } else { bool bHas = false; for (int i = 0; i < node.childs.Count; i++) { bHas = (!bHas) ? node.childs[i].bToggle : bHas; } if (!bHas) { // TODO Found strList.Add(node.GetTagTotalName()); } else { for (int i = 0; i < node.childs.Count; i++) { FindNextSelectedTag(node.childs[i], strList); } } } } }
static void InitToggleTag(string[] strs) { if (strs == null || strs.Length == 0) { return; } int index = 1; FTagNode node = null; for (int i = 0; i < nodeList.Count; i++) { if (nodeList[i].name.Equals(strs[0])) { node = nodeList[i]; } } while (index < strs.Length && node != null) { for (int i = 0; i < node.childs.Count; i++) { if (node.childs[i].name.Equals(strs[index])) { node = node.childs[i]; break; } } ++index; } node.OnToggleChanged(true); }
public string GetTagTotalName() { List <string> tempList = new List <string>(); FTagNode node = this; while (node != null) { tempList.Add(node.name); node = node.parent; } string res = ""; for (int i = tempList.Count - 1; i >= 0; i--) { res += tempList[i] + (i == 0 ? "" : "."); } return(res); }
public void OnToggleChanged(bool inToggle) { bToggle = inToggle; if (inToggle) { FTagNode temp = parent; while (temp != null) { temp.bToggle = true; temp = temp.parent; } } else { OnToggleOff(); } Window_AbilityTagEditor.OnValueChanged?.Invoke(Window_AbilityTagEditor.GetSelectedTags()); }
void DrawTag(FTagNode node, int level) { EditorGUI.indentLevel = level; EditorGUILayout.BeginHorizontal(); node.bOpen = EditorGUILayout.Foldout(node.bOpen, node.name); bool preToggle = node.bToggle; node.bToggle = EditorGUILayout.ToggleLeft("", node.bToggle); if (preToggle != node.bToggle) { node.OnToggleChanged(node.bToggle); } EditorGUILayout.EndHorizontal(); if (node.bOpen) { for (int i = 0; i < node.childs.Count; i++) { DrawTag(node.childs[i], level + 1); } } }
static FTagNode CheckSame(string str, FTagNode node = null) { if (node != null) { foreach (FTagNode child in node.childs) { if (child != null && child.name.Equals(str)) { return(child); } } } else { for (int i = 0; i < nodeList.Count; i++) { if (nodeList[i].name.Equals(str)) { return(nodeList[i]); } } } return(null); }
static bool AddTag(string inStr) { if (string.IsNullOrEmpty(inStr)) { return(false); } string[] strs = inStr.Split('.'); int level = 0; FTagNode node = null; for (; level < strs.Length; level++) { FTagNode temp = CheckSame(strs[level], node); if (temp is null) { break; } else { node = temp; } } if (level == strs.Length) { return(false); } if (node == null) { if (strs.Length > 0) { FTagNode root = new FTagNode(strs[0], null); FTagNode tagNode = root; for (int i = 1; i < strs.Length; i++) { FTagNode child = new FTagNode(strs[i], tagNode); tagNode.childs.Add(child); tagNode = child; } nodeList.Add(root); return(true); } } else { if (strs.Length > level) { FTagNode root = new FTagNode(strs[level], node); FTagNode tagNode = root; for (int i = level + 1; i < strs.Length; i++) { FTagNode child = new FTagNode(strs[i], tagNode); tagNode.childs.Add(child); tagNode = child; } node.childs.Add(root); return(true); } } return(false); }
public FTagNode(string name, FTagNode parent) { this.name = name; this.parent = parent; childs = new List <FTagNode>(); }