private void CreateAsset(string uname, string path, Transform parent) { Transform prefab = GetPrefab <Transform>(path); if (prefab == null) { return; } Transform target = Instantiate(prefab); PoolObjectInfo info = new PoolObjectInfo { path = path, name = uname, gameObject = target.gameObject, transform = target, component = target.GetComponent <ZUIBehaviour>() }; if (info.component == null) { info.component = target.GetComponent <ZBehaviourBase>(); } assetList.Add(info); target.SetParent(parent, false); target.gameObject.SetActive(false); }
private T GetSleepAsset <T>() where T : MonoBehaviour { for (int i = 0; i < assetList.Count; i++) { PoolObjectInfo info = assetList[i]; if (info.component != null && !info.gameObject.activeInHierarchy && info.name == typeof(T).Name && info.transform.parent == sleepParent) { if (typeof(T) == info.component.GetType() || info.component.GetType().IsSubclassOf(typeof(T))) { return(info.component as T); } } } return(null); }
private T GetSleepAssetByName <T>(string uname) where T : MonoBehaviour { for (int i = 0; i < assetList.Count; i++) { PoolObjectInfo info = assetList[i]; if (info.component != null && !info.gameObject.activeSelf && uname == info.name && info.transform.parent == sleepParent) { //Debug.LogError("GetSleepAssetByName...." + uname + ";info = " + info.name + "; active = " + info.gameObject.activeSelf); if (typeof(T) == info.component.GetType() || info.component.GetType().IsSubclassOf(typeof(T))) { return(info.component as T); } } } return(null); }
private T GetSleepAsset <T>(string path) where T : Component { for (int i = 0; i < assetList.Count; i++) { PoolObjectInfo info = assetList[i]; GameObject go = info.gameObject; if (info.component != null && !go.activeSelf && path == info.path && info.transform.parent == sleepParent) { if (typeof(T) == info.component.GetType() || info.component.GetType().IsSubclassOf(typeof(T))) { return(info.component as T); } } } return(null); }
public void Recover() { int leng = assetList.Count; for (int i = 0; i < leng; i++) { PoolObjectInfo info = assetList[i]; if (info.gameObject != null && info.gameObject.activeInHierarchy) { info.transform.parent = sleepParent; info.gameObject.SetActive(false); } else if (info.gameObject == null) { } } RecoverEffect(); }
private T CreateAsset <T>(T prefab, string uname, string path) where T : Component { if (prefab == null) { //ZLog.Warning("can not create asset that path = " + path + "!!!"); return(null); } T clone = Instantiate <T>(prefab); PoolObjectInfo info = new PoolObjectInfo { path = path, name = uname, gameObject = clone.gameObject, transform = clone.transform, component = clone }; assetList.Add(info); return(clone); }