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); } }
private static void OnUnRef(AssetRefHelper helper, AssetRef assetRef) { if (assetRefDict.TryGetValue(assetRef, out var set)) { set.Remove(helper.gameObject); } }
public static GameObject[] FindGameObjects(AssetRef assetRef) { if (assetRefDict.TryGetValue(assetRef, out var set)) { return(set.ToArray()); } return(null); }
public bool RemoveRef(AssetRef assetRef) { bool ret = refList.Remove(assetRef); if (ret && assetRef.valid) { assetRef.UnRef(); } return(ret); }
public void RefAsset(AssetRef assetRef) { if (refList == null) { refList = new AssetRefList(); } refList.AddRef(assetRef); #if UNITY_EDITOR OnRef(this, assetRef); #endif }
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; } }
//关联资源引用到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); }
public void UnRef(AssetRef assetRef) { if (assetRef == null) { return; } if (refList != null) { return; } refList.RemoveRef(assetRef); #if UNITY_EDITOR OnUnRef(this, assetRef); #endif }
public void AddRef(AssetRef assetRef) { if (assetRef == null) { return; } if (!assetRef.valid) { return; } if (!refList.Contains(assetRef)) { assetRef.Ref(); refList.Add(assetRef); } }
internal AssetHandle(UnityEngine.Object asset, AssetRef assetRef) { this.asset = asset; this.assetRef = assetRef; }
public bool Contains(AssetRef assetRef) { return(refList.Contains(assetRef)); }