|
@@ -94,6 +94,7 @@ public class ManaReso : Regist
|
|
|
|
|
|
public static Dictionary<string, Object> ObjDic = new Dictionary<string, Object>();
|
|
|
public static Dictionary<string, Transform> TraDic = new Dictionary<string, Transform>();
|
|
|
+ public static Dictionary<GameObject, ObjType> ObjPoolDic = new Dictionary<GameObject, ObjType>();
|
|
|
|
|
|
public static Dictionary<ObjType, List<Transform>> ObjectPool = new Dictionary<ObjType, List<Transform>>();
|
|
|
|
|
@@ -187,55 +188,21 @@ public class ManaReso : Regist
|
|
|
|
|
|
public static void Save<T>(T t, bool aware = false) where T : Component
|
|
|
{
|
|
|
- Transform tra = t.transform;
|
|
|
-
|
|
|
- ObjRoot objRoot = tra.GetComponent<ObjRoot>();
|
|
|
-
|
|
|
- if (objRoot == null)
|
|
|
- {
|
|
|
- throw new Exception();
|
|
|
- }
|
|
|
-
|
|
|
- List<Transform> 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();
|
|
|
- }
|
|
|
+ Save(t.gameObject);
|
|
|
}
|
|
|
|
|
|
public static void Save(GameObject go, bool aware = false)
|
|
|
{
|
|
|
- ObjRoot objRoot = go.GetComponent<ObjRoot>();
|
|
|
+ ObjType objType;
|
|
|
|
|
|
- if (objRoot == null)
|
|
|
+ if (!ObjPoolDic.TryGetValue(go, out objType))
|
|
|
{
|
|
|
throw new Exception();
|
|
|
}
|
|
|
|
|
|
List<Transform> traList;
|
|
|
|
|
|
- if (ObjectPool.TryGetValue(objRoot.ObjType, out traList))
|
|
|
+ if (ObjectPool.TryGetValue(objType, out traList))
|
|
|
{
|
|
|
if (traList.Contains(go.transform))
|
|
|
{
|
|
@@ -262,6 +229,24 @@ public class ManaReso : Regist
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public static bool Contains<T>(T t) where T : Component
|
|
|
+ {
|
|
|
+ return Contains(t.gameObject);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static bool Contains(GameObject go)
|
|
|
+ {
|
|
|
+ foreach (var kv in ObjectPool)
|
|
|
+ {
|
|
|
+ if (kv.Value.Contains(go.transform))
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
public static Transform Get(ObjType objType)
|
|
|
{
|
|
|
List<Transform> traList;
|
|
@@ -431,7 +416,7 @@ public class ManaReso : Regist
|
|
|
return Load<Sprite>(goName, Folder.UI);
|
|
|
}
|
|
|
|
|
|
- public static Transform Get<T>(string goName, Folder folder, bool compile, Transform par, bool worldSpace, ObjType objType = ObjType.Null) where T : ObjRoot
|
|
|
+ public static Transform Get(string goName, Folder folder, bool compile, Transform par, bool worldSpace, ObjType objType = ObjType.Null, Type type = null)
|
|
|
{
|
|
|
Transform tra = Get(objType);
|
|
|
|
|
@@ -449,7 +434,12 @@ public class ManaReso : Regist
|
|
|
|
|
|
if (objType != ObjType.Null)
|
|
|
{
|
|
|
- go.AddComponent<T>().ObjType = objType;
|
|
|
+ ObjPoolDic.Add(go, objType);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (type != null)
|
|
|
+ {
|
|
|
+ go.AddComponent(type);
|
|
|
}
|
|
|
|
|
|
return go.transform;
|
|
@@ -478,7 +468,7 @@ public class ManaReso : Regist
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static Transform Get<T>(string goName, Folder folder, bool compile, Transform par, Vector3 pos, ObjType objType = ObjType.Null) where T : ObjRoot
|
|
|
+ public static Transform Get(string goName, Folder folder, bool compile, Transform par, Vector3 pos, ObjType objType = ObjType.Null, Type type = null)
|
|
|
{
|
|
|
Transform tra = Get(objType);
|
|
|
|
|
@@ -496,7 +486,12 @@ public class ManaReso : Regist
|
|
|
|
|
|
if (objType != ObjType.Null)
|
|
|
{
|
|
|
- go.AddComponent<T>().ObjType = objType;
|
|
|
+ ObjPoolDic.Add(go, objType);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (type != null)
|
|
|
+ {
|
|
|
+ go.AddComponent(type);
|
|
|
}
|
|
|
|
|
|
return go.transform;
|
|
@@ -527,11 +522,11 @@ public class ManaReso : Regist
|
|
|
|
|
|
if (objType == ObjType.DropGold)
|
|
|
{
|
|
|
- tra = Get<DropGold>(objType.ToString(), Folder.UI, false, null, pos, objType);
|
|
|
+ tra = Get(objType.ToString(), Folder.UI, false, null, pos, objType, typeof(DropGold));
|
|
|
}
|
|
|
else if(objType == ObjType.DropDiamond)
|
|
|
{
|
|
|
- tra = Get<DropDiamond>(objType.ToString(), Folder.UI, false, null, pos, objType);
|
|
|
+ tra = Get(objType.ToString(), Folder.UI, false, null, pos, objType, typeof(DropDiamond));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -549,7 +544,7 @@ public class ManaReso : Regist
|
|
|
|
|
|
public static Flower GetFlower(FlowerInfo flowerInfo, Slot slot, bool collider)
|
|
|
{
|
|
|
- Transform tra = Get<Flower>("Flower", Folder.Scene, false, slot.transform, false, ObjType.Flower);
|
|
|
+ Transform tra = Get("Flower", Folder.Scene, false, slot.transform, false, ObjType.Flower, typeof(Flower));
|
|
|
|
|
|
tra.localScale = new Vector3(1, 1, 1);
|
|
|
|
|
@@ -569,7 +564,7 @@ public class ManaReso : Regist
|
|
|
|
|
|
public static Flower GetFlower(FlowerInfo flowerInfo, Transform par)
|
|
|
{
|
|
|
- Transform tra = Get<Flower>("Flower", Folder.Scene, false, par, false, ObjType.Flower);
|
|
|
+ Transform tra = Get("Flower", Folder.Scene, false, par, false, ObjType.Flower, typeof(Flower));
|
|
|
|
|
|
tra.localScale = new Vector3(1, 1, 1);
|
|
|
|
|
@@ -600,7 +595,7 @@ public class ManaReso : Regist
|
|
|
pos = posTra.position;
|
|
|
}
|
|
|
|
|
|
- Transform tra = Get<HudText>("HudText", Folder.UI, false, parTra, pos, ObjType.HudText);
|
|
|
+ Transform tra = Get("HudText", Folder.UI, false, parTra, pos, ObjType.HudText, typeof(HudText));
|
|
|
|
|
|
HudText hudText = tra.GetComponent<HudText>();
|
|
|
|
|
@@ -621,7 +616,7 @@ public class ManaReso : Regist
|
|
|
|
|
|
pos.z -= Random.Range(0.001f, 0.1f);
|
|
|
|
|
|
- tra = Get<ObjRoot>(obj.ToString(), Folder.Scene, false, par, pos, obj);
|
|
|
+ tra = Get(obj.ToString(), Folder.Scene, false, par, pos, obj);
|
|
|
|
|
|
Elf elf = tra.GetChild(0).GetComponent<Elf>();
|
|
|
|
|
@@ -658,19 +653,19 @@ public class ManaReso : Regist
|
|
|
|
|
|
if (skillRoot.SkillTab == SkillTab.Elf)
|
|
|
{
|
|
|
- tra = Get<ObjRoot>("SkillItem", Folder.UI, false, Get("Fd_Grid"), false, ObjType.SkillItem);
|
|
|
+ tra = Get("SkillItem", Folder.UI, false, Get("Fd_Grid"), false, ObjType.SkillItem);
|
|
|
}
|
|
|
else if (skillRoot.SkillTab == SkillTab.Store)
|
|
|
{
|
|
|
- tra = Get<ObjRoot>("SkillItem", Folder.UI, false, Get("Fc_Grid"), false, ObjType.SkillItem);
|
|
|
+ tra = Get("SkillItem", Folder.UI, false, Get("Fc_Grid"), false, ObjType.SkillItem);
|
|
|
}
|
|
|
else if (skillRoot.SkillTab == SkillTab.Magic)
|
|
|
{
|
|
|
- tra = Get<ObjRoot>("SkillItem", Folder.UI, false, Get("Fb_Grid"), false, ObjType.SkillItem);
|
|
|
+ tra = Get("SkillItem", Folder.UI, false, Get("Fb_Grid"), false, ObjType.SkillItem);
|
|
|
}
|
|
|
else if (skillRoot.SkillTab == SkillTab.Garden)
|
|
|
{
|
|
|
- tra = Get<ObjRoot>("SkillItem", Folder.UI, false, Get("Fa_Grid"), false, ObjType.SkillItem);
|
|
|
+ tra = Get("SkillItem", Folder.UI, false, Get("Fa_Grid"), false, ObjType.SkillItem);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -684,7 +679,7 @@ public class ManaReso : Regist
|
|
|
|
|
|
public static Transform GetAchieveItem()
|
|
|
{
|
|
|
- Transform tra = Get<ObjRoot>("AchieveItem", Folder.UI, false, ManaReso.Get("M_Grid"), false, ObjType.AchieveItem);
|
|
|
+ Transform tra = Get("AchieveItem", Folder.UI, false, ManaReso.Get("M_Grid"), false, ObjType.AchieveItem);
|
|
|
|
|
|
return tra;
|
|
|
}
|
|
@@ -692,7 +687,7 @@ public class ManaReso : Regist
|
|
|
|
|
|
public static ParticleSystem GetFirework(Vector3 pos)
|
|
|
{
|
|
|
- Transform tra = Get<Effect>("Firework", Folder.Effect, false, null, pos, ObjType.Firework);
|
|
|
+ Transform tra = Get("Firework", Folder.Effect, false, null, pos, ObjType.Firework, typeof(Effect));
|
|
|
|
|
|
ParticleSystem particle = tra.GetComponent<ParticleSystem>();
|
|
|
|
|
@@ -703,7 +698,7 @@ public class ManaReso : Regist
|
|
|
|
|
|
public static ParticleSystem GetLightwall()
|
|
|
{
|
|
|
- Transform tra = Get<Effect>("LightwallUI", Folder.Effect, false, Get("Canvas"), false, ObjType.LightwallUI);
|
|
|
+ Transform tra = Get("LightwallUI", Folder.Effect, false, Get("Canvas"), false, ObjType.LightwallUI, typeof(Effect));
|
|
|
|
|
|
ParticleSystem particle = tra.GetComponent<ParticleSystem>();
|
|
|
|
|
@@ -759,7 +754,7 @@ public class ManaReso : Regist
|
|
|
InstantiateList.Add(kv);
|
|
|
}
|
|
|
|
|
|
- public static void AsyncLoad<T>(string goName, int amt, Folder folder, ObjType objType, bool ui = false, bool canvas = false, UnityAction callback = null) where T : ObjRoot
|
|
|
+ public static void AsyncLoad(string goName, int amt, Folder folder, ObjType objType, bool ui = false, bool canvas = false, UnityAction callback = null, Type type = null)
|
|
|
{
|
|
|
KV<AsyncRequest, UnityAction> kv = new KV<AsyncRequest, UnityAction>();
|
|
|
|
|
@@ -815,7 +810,12 @@ public class ManaReso : Regist
|
|
|
go = (GameObject)Instantiate(bundleRequest.asset);
|
|
|
}
|
|
|
|
|
|
- go.AddComponent<T>().ObjType = objType;
|
|
|
+ ObjPoolDic.Add(go, objType);
|
|
|
+
|
|
|
+ if (type != null)
|
|
|
+ {
|
|
|
+ go.AddComponent(type);
|
|
|
+ }
|
|
|
|
|
|
go.name = go.name.Replace("(Clone)", "");
|
|
|
|
|
@@ -846,13 +846,13 @@ public class ManaReso : Regist
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- public static void AddAsyncLoad<T>(string goName, int amt, Folder folder, ObjType objType, bool ui = false, bool canvas = false, UnityAction callback = null) where T : ObjRoot
|
|
|
+ public static void AddAsyncLoad(string goName, int amt, Folder folder, ObjType objType, bool ui = false, bool canvas = false, UnityAction callback = null, Type type = null)
|
|
|
{
|
|
|
AsyncList.Add
|
|
|
(
|
|
|
() =>
|
|
|
{
|
|
|
- AsyncLoad<T>(goName, amt, folder, objType, ui, canvas, callback);
|
|
|
+ AsyncLoad(goName, amt, folder, objType, ui, canvas, callback, type);
|
|
|
}
|
|
|
);
|
|
|
}
|
|
@@ -891,7 +891,7 @@ public class ManaReso : Regist
|
|
|
|
|
|
go.AddScript<Player>().BuildPink();
|
|
|
|
|
|
- go.AddComponent<ObjRoot>().ObjType = objType;
|
|
|
+ ObjPoolDic.Add(go, objType);
|
|
|
}
|
|
|
else if (player == "PlayerBlond")
|
|
|
{
|
|
@@ -901,7 +901,7 @@ public class ManaReso : Regist
|
|
|
|
|
|
go.AddScript<Player>().BuildBlond();
|
|
|
|
|
|
- go.AddComponent<ObjRoot>().ObjType = objType;
|
|
|
+ ObjPoolDic.Add(go, objType);
|
|
|
}
|
|
|
else if(player == "PlayerBrown")
|
|
|
{
|
|
@@ -911,7 +911,7 @@ public class ManaReso : Regist
|
|
|
|
|
|
go.AddScript<Player>().BuildBrown();
|
|
|
|
|
|
- go.AddComponent<ObjRoot>().ObjType = objType;
|
|
|
+ ObjPoolDic.Add(go, objType);
|
|
|
}
|
|
|
else
|
|
|
{
|