//获取资源的副本(同步)
        public PrefabAsset ClonePrefab(string assetName, string requester)
        {
            //检查资源
            if (string.IsNullOrEmpty(requester) ||
                !AssetBundle ||
                !AssetBundle.Contains(assetName))
            {
                return(null);
            }

            PrefabAssetNode assetInfoNode = null;

            //没有clone过
            if (!prefabAssetNodeDic.TryGetValue(assetName, out assetInfoNode))
            {
                assetInfoNode = PrefabAssetNode.Create(this, assetName);

                if (assetInfoNode != null)
                {
                    prefabAssetNodeDic.Add(assetName, assetInfoNode);
                }
                else
                {
                    Debug.LogError(string.Format("Clone prefab failed : {0}"));
                }
            }

            if (assetInfoNode != null)
            {
                return(assetInfoNode.Clone(requester));
            }

            return(null);
        }
Esempio n. 2
0
 public void OnRecycle()
 {
     requester = string.Empty;
     assetNode = null;
     if (clone != null)
     {
         GameObject.Destroy(clone);
         clone = null;
     }
 }
Esempio n. 3
0
        //创建一个新的
        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);
        }
        public void SetCloneCapacity(string assetName, int capacity)
        {
            if (capacity < 0)
            {
                return;
            }

            //检查资源
            if (!AssetBundle ||
                !AssetBundle.Contains(assetName))
            {
                return;
            }

            PrefabAssetNode assetInfoNode = null;

            //没有clone过
            if (!prefabAssetNodeDic.TryGetValue(assetName, out assetInfoNode))
            {
                assetInfoNode = PrefabAssetNode.Create(this, assetName);

                if (assetInfoNode != null)
                {
                    prefabAssetNodeDic.Add(assetName, assetInfoNode);
                }
                else
                {
                    Debug.LogError(string.Format("Clone prefab failed : {0}", assetName));
                }
            }

            if (assetInfoNode != null)
            {
                assetInfoNode.PoolCapacity = capacity;
            }
        }
Esempio n. 5
0
        public static PrefabAssetNode Create(AssetBundleInfoNode infoNode, string assetName)
        {
            if (infoNode == null)
            {
                Debug.LogError("Create AssetInfoNode failed. Empty infoNode...");
                return(null);
            }

            GameObject original = infoNode.GetAsset <GameObject>(assetName, string.Format("PrefabAssetNode_{0}", assetName));

            if (original == null)
            {
                Debug.LogError("Create AssetInfoNode failed. Can not get gameobject asset ==> " + assetName);
                return(null);
            }

            PrefabAssetNode node = nodePool.Get();

            node.infoNode     = infoNode;
            node.assetName    = assetName;
            node.originPrefab = original;

            return(node);
        }