//直接clone Prefab public GameObject ClonePrefab(AssetBundleInfoNode assetBundleInfoNode, string asset, string requester) { PrefabAsset assetNode = assetBundleInfoNode.ClonePrefab(asset, requester); if (assetNode == null) { return(null); } this.requester = requester; if (prefabRequests == null) { prefabRequests = new Dictionary <string, List <PrefabAsset> >(System.StringComparer.CurrentCultureIgnoreCase); } List <PrefabAsset> list = null; if (!prefabRequests.TryGetValue(assetBundleInfoNode.bundleName, out list)) { list = new List <PrefabAsset>(); prefabRequests.Add(assetBundleInfoNode.bundleName, list); } list.Add(assetNode); return(assetNode.clone); }
//创建一个新的 public static PrefabAsset Get(PrefabAssetNode assetNode) { if (assetNode == null || assetNode.originPrefab == null) { return(null); } PrefabAsset clone = pool.Get(); clone.assetNode = assetNode; clone.requester = null; clone.clone = GameObject.Instantiate <GameObject>(assetNode.originPrefab, assetNode.ParentNode); clone.Reset(); return(clone); }
//只是克隆一个新的对象放到池中 private PrefabAsset Clone() { if (ParentNode == null) { Debug.LogError(string.Format("{0} clone failed. None parent node.", assetName)); return(null); } PrefabAsset newClone = PrefabAsset.Get(this); if (newClone == null) { Debug.LogError(string.Format("{0} clone failed. None model", assetName)); return(null); } prefabPool.Add(newClone); return(newClone); }
public PrefabAsset Clone(string requester) { if (string.IsNullOrEmpty(requester)) { Debug.LogError(string.Format("{0} clone failed. None reqeuster.", assetName)); return(null); } if (ParentNode == null) { Debug.LogError(string.Format("{0} clone failed. None parent node.", assetName)); return(null); } if (prefabPool == null) { prefabPool = new List <PrefabAsset>(); } if (prefabPool.Count > 0) { for (int i = 0; i < prefabPool.Count; ++i) { if (!prefabPool[i].IsActive) { prefabPool[i].Requester = requester; return(prefabPool[i]); } } } //当前池中没有符合需求的 PrefabAsset newClone = Clone(); newClone.Requester = requester; return(newClone); }