コード例 #1
0
        internal AssetRef GetOrCreateRef(Object asset)
        {
            if (asset == null)
            {
                #if ASSET_REF_DEBUG
                Debug.LogWarning("AssetRefManager.GetOrCreateRef asset is null");
                #endif
                return(null);
            }
            int      key = GetRefId(asset);
            AssetRef assetRef;
            if (assetRefs.TryGetValue(key, out assetRef))
            {
                return(assetRef);
            }
            else
            {
                assetRef = new AssetRef(this);
                assetRefs.Add(key, assetRef);
#if ASSET_REF_DEBUG
                assetRef.OnCreateAtEditor(asset);
#endif
                return(assetRef);
            }
        }
コード例 #2
0
 private static void OnUnRef(AssetRefHelper helper, AssetRef assetRef)
 {
     if (assetRefDict.TryGetValue(assetRef, out var set))
     {
         set.Remove(helper.gameObject);
     }
 }
コード例 #3
0
 public static GameObject[] FindGameObjects(AssetRef assetRef)
 {
     if (assetRefDict.TryGetValue(assetRef, out var set))
     {
         return(set.ToArray());
     }
     return(null);
 }
コード例 #4
0
        public bool RemoveRef(AssetRef assetRef)
        {
            bool ret = refList.Remove(assetRef);

            if (ret && assetRef.valid)
            {
                assetRef.UnRef();
            }
            return(ret);
        }
コード例 #5
0
        public void RefAsset(AssetRef assetRef)
        {
            if (refList == null)
            {
                refList = new AssetRefList();
            }
            refList.AddRef(assetRef);
#if UNITY_EDITOR
            OnRef(this, assetRef);
#endif
        }
コード例 #6
0
 private static void OnRef(AssetRefHelper helper, AssetRef assetRef)
 {
     if (assetRefDict.TryGetValue(assetRef, out var set))
     {
         set.Add(helper.gameObject);
     }
     else
     {
         set = new HashSet <GameObject>();
         set.Add(helper.gameObject);
         assetRefDict[assetRef] = set;
     }
 }
コード例 #7
0
        //关联资源引用到GameObject
        public void AddAssetRefToGameObject(GameObject gameObject, AssetRef assetRef)
        {
            if (gameObject == null)
            {
                return;
            }
            var helper = gameObject.GetComponent <AssetRefHelper>();

            if (helper == null)
            {
                helper = gameObject.AddComponent <AssetRefHelper>();
            }
            helper.RefAsset(assetRef);
        }
コード例 #8
0
        public void UnRef(AssetRef assetRef)
        {
            if (assetRef == null)
            {
                return;
            }
            if (refList != null)
            {
                return;
            }
            refList.RemoveRef(assetRef);
#if UNITY_EDITOR
            OnUnRef(this, assetRef);
#endif
        }
コード例 #9
0
 public void AddRef(AssetRef assetRef)
 {
     if (assetRef == null)
     {
         return;
     }
     if (!assetRef.valid)
     {
         return;
     }
     if (!refList.Contains(assetRef))
     {
         assetRef.Ref();
         refList.Add(assetRef);
     }
 }
コード例 #10
0
 internal AssetHandle(UnityEngine.Object asset, AssetRef assetRef)
 {
     this.asset    = asset;
     this.assetRef = assetRef;
 }
コード例 #11
0
 public bool Contains(AssetRef assetRef)
 {
     return(refList.Contains(assetRef));
 }