Пример #1
0
 private static void OnUnRef(AssetRefHelper helper, AssetRef assetRef)
 {
     if (assetRefDict.TryGetValue(assetRef, out var set))
     {
         set.Remove(helper.gameObject);
     }
 }
Пример #2
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);
            }
        }
Пример #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
 public bool Contains(AssetRef assetRef)
 {
     return(refList.Contains(assetRef));
 }
Пример #11
0
 internal AssetHandle(UnityEngine.Object asset, AssetRef assetRef)
 {
     this.asset    = asset;
     this.assetRef = assetRef;
 }