using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using Cysharp.Threading.Tasks; [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 async UniTask Get() { if (config == null) { config = await BuiltInLoader.LoadScriptableObjectAsync("WindowConfig"); foreach (var table in config.windows) { var children = config.parentChildrenTable[table.parent] = new List(); foreach (var info in table.orderTables) { children.Add(info.window); } config.childWindows.AddRange(children); } } return config; } public static void Release() { config = null; } public static async UniTask<(bool found, string parent)> FindParentWindow(string child) { var cfg = await Get(); foreach (var table in cfg.windows) { foreach (var orderTable in table.orderTables) { if (orderTable.window == child) { return (true, table.parent); } } } return (false, string.Empty); } public static async UniTask> GetChildWindows(string parent) { var cfg = await Get(); if (cfg.parentChildrenTable.ContainsKey(parent)) { return cfg.parentChildrenTable[parent]; } else { return null; } } public static async UniTask IsParentWindow(string name) { var cfg = await Get(); foreach (var window in cfg.windows) { if (window.parent == name) { return true; } } return false; } public static async UniTask IsChildWindow(string name) { var cfg = await Get(); return cfg.childWindows.Contains(name); } public static async UniTask GetWindowLevel(string name) { var cfg = await Get(); foreach (var window in cfg.windows) { if (window.parent == name) { return window.level; } } return WindowLevel.None; } public static async UniTask GetWindowPattern(string name) { var cfg = await Get(); foreach (var window in cfg.windows) { if (window.parent == name) { return window.pattern; } } return string.Empty; } public static async UniTask> GetWindowFunctionInfos(string parent) { var cfg = await Get(); foreach (var table in cfg.windows) { if (table.parent == parent) { return new List(table.orderTables); } } return null; } public static async UniTask GetTitleIconKey(string name) { var cfg = await Get(); foreach (var window in cfg.windows) { if (window.parent == name) { return window.titleIconKey; } } return string.Empty; } [Serializable] public struct WindowTable { public string parent; public string titleIconKey; public WindowLevel level; public string pattern; public OrderTable[] orderTables; } [Serializable] public struct OrderTable { public int order; public int functionId; public int redPointId; public string titleKey; public string window; } public enum WindowLevel { None, OneLevel, SecondLevel, ThirdLevel, } }