using System.Collections; using System.Collections.Generic; using UnityEngine; using System; [CreateAssetMenu(menuName = "Config/WindowConfig")] public class WindowConfig : ScriptableObject { public WindowTable[] windows; [NonSerialized] public Dictionary> parentChildrenTable = new Dictionary>(); [NonSerialized] public List childWindows = new List(); static WindowConfig config; public static WindowConfig Get() { if (config == null) { config = BuiltInLoader.LoadScriptableObject("WindowConfig"); for (int i = 0; i < config.windows.Length; i++) { var table = config.windows[i]; var children = config.parentChildrenTable[table.parent] = new List(); for (int j = 0; j < table.orderTables.Length; j++) { children.Add(table.orderTables[j].window); } config.childWindows.AddRange(children); } } return config; } public static void Release() { config = null; } public bool FindChildWindow(string _parent, int _order, out string _child) { for (int i = 0; i < windows.Length; i++) { var table = windows[i]; if (table.parent == _parent) { for (int j = 0; j < table.orderTables.Length; j++) { if (table.orderTables[j].order == _order) { _child = table.orderTables[j].window; return true; } } } } _child = string.Empty; return false; } public bool FindParentWindow(string _child, out string _parent) { for (int i = 0; i < windows.Length; i++) { var table = windows[i]; for (int j = 0; j < table.orderTables.Length; j++) { var orderTable = table.orderTables[j]; if (orderTable.window == _child) { _parent = table.parent; return true; } } } _parent = string.Empty; return false; } public List FindChildWindows(string _parent) { if (parentChildrenTable.ContainsKey(_parent)) { return parentChildrenTable[_parent]; } else { return null; } } public bool IsChildWindow(string _name) { return childWindows.Contains(_name); } [Serializable] public struct WindowTable { public string parent; public OrderTable[] orderTables; } [Serializable] public struct OrderTable { public int order; public string window; } }