using UnityEngine; using UnityEngine.UI; using UnityEngine.Events; using System; using System.Collections; using System.Linq.Expressions; using System.ComponentModel; using System.Collections.Generic; using System.Diagnostics; using Object = UnityEngine.Object; using Random = UnityEngine.Random; using Component = UnityEngine.Component; using Debug = UnityEngine.Debug; public enum Folder { UI, Effect, Audio, Scene, Config, } public enum ObjType { Null, Firework, LightwallUI, PlayerPink, PlayerBlond, PlayerBrown, Page, Flower, Garden, Tutorial, Canvas, GroupA, GroupB, GroupC, GroupD, EventSystem, MainCamera, HudText, SkillItem, SignItem, FlowerItem, AchieveItem, Music, DropGold, DropDiamond, BeeRed, BeeBlue, BeeWhite, BeePurple, BeeYellow, ButterflyRed, ButterflyBlue, ButterflyWhite, ButterflyPurple, ButterflyYellow, } public class AsyncRequest { public UnityAction Callback; public AssetBundleRequest Request; } public class ManaReso : Regist { #region 变量 public static bool AsyncLoadLock; public static bool AsyncInstantiateLock; public static Coroutine CoroAsync; public static Coroutine CoroInstantiate; public static ManaReso Instance; public static UnityAction OnAsyncLoadFinish; public static List AsyncList = new List(); public static List RequestList = new List(); public static List> InstantiateList = new List>(); public static Dictionary ObjDic = new Dictionary(); public static Dictionary TraDic = new Dictionary(); public static Dictionary> ObjectPool = new Dictionary>(); #endregion public override void RegistImmed() { if (RegistFlag) { return; } else { RegistFlag = true; } Instance = this; Transform objPool = new GameObject("ObjPool").transform; objPool.parent = transform; objPool.SetActive(false); TraDic.Add(objPool.name, objPool); CoroAsync = StartCoroutine(IAsyncLoad()); CoroInstantiate = StartCoroutine(IAsyncInstancitate()); } #region TraDic public static T Get(string goName) { Transform tra; if (TraDic.TryGetValue(goName, out tra)) { T t = tra.GetComponent(); if (t == null) { throw new Exception(goName); } return t; } else { throw new Exception(goName); } } public static T[] Gets(string goName) { Transform tra; if (TraDic.TryGetValue(goName, out tra)) { T[] ts = tra.GetComponentsInChildren(); if (ts == null) { throw new Exception(goName); } return ts; } else { throw new Exception(goName); } } public static Transform Get(string goName) { Transform tra; if (TraDic.TryGetValue(goName, out tra)) { return tra; } else { throw new Exception(goName); } } #endregion #region ObjPool public static void Save(T t, bool aware = false) where T : Component { Transform tra = t.transform; ObjRoot objRoot = tra.GetComponent(); if (objRoot == null) { throw new Exception(); } List traList; if (ObjectPool.TryGetValue(objRoot.ObjType, out traList)) { if (traList.Contains(tra)) { if (aware) { return; } else { throw new Exception(); } } tra.SetActive(false); traList.Add(tra); tra.transform.SetParent(Get("ObjPool")); } else { throw new Exception(); } } public static void Save(GameObject go, bool aware = false) { ObjRoot objRoot = go.GetComponent(); if (objRoot == null) { throw new Exception(); } List traList; if (ObjectPool.TryGetValue(objRoot.ObjType, out traList)) { if (traList.Contains(go.transform)) { if (aware) { return; } else { throw new Exception(); } } go.SetActive(false); traList.Add(go.transform); go.transform.SetParent(Get("ObjPool")); } else { throw new Exception(); } } public static Transform Get(ObjType objType) { List traList; if (ObjectPool.TryGetValue(objType, out traList)) { if (traList.Count > 0) { Transform tra = traList[0]; tra.SetActive(true); traList.RemoveAt(0); return tra.transform; } } return null; } #endregion #region ShortCut public static void SetText(string goName) { Text text = Get(goName); text.text = Language.GetStr("UI", goName); } public static void SetText(string goName, string str) { Text text = Get(goName); text.text = str; } public static void SetSprite(string goName, Sprite sprite) { Image image = Get(goName); image.sprite = sprite; } public static void SetActive(string goName, bool active) { Get(goName).SetActive(active); } public static void SetButtonEvent(string goName, UnityAction onClick) { Button button = Get