private T[] GetAssets <T>() where T : Object { return((from pair in m_assets[(int)RestoredAssetsRoot.FindAssetType <T>()] where pair.Value.Asset is T select pair.Value.Asset as T).ToArray()); }
private T GetOrCreateAsset <T>(T current, string name, System.Action <T> onFirstRef, System.Func <T> factory) where T : Object { if (factory == null) { throw new System.ArgumentNullException("factory"); } var isNewInstance = current == null; if (current == null) { if (current == null) { current = factory(); } else { Debug.Assert(RestoredAssetsRoot.FindAssetType <T>() == RestoredAssetsRoot.ContainingType.Unknown); } m_assets[RestoredAssetsRoot.FindAssetTypeIndex <T>()].Add(current.GetHashCode(), new AssetDbData() { Asset = current, RefCount = 0 }); } var data = m_assets[RestoredAssetsRoot.FindAssetTypeIndex <T>()][current.GetHashCode()]; if (data.RefCount == 0) { onFirstRef(current); current.name = name; if (isNewInstance) { AssetDatabase.AddObjectToAsset(current, GetRoot(RestoredAssetsRoot.FindAssetType <T>())); ++m_statistics.NumAddedAssets; } } data.RefCount += 1; return(current); }
public int GetRefCount(Object obj) { if (obj == null) { return(-1); } var dict = m_assets[(int)RestoredAssetsRoot.FindAssetType(obj.GetType())]; if (dict == null) { return(-1); } AssetDbData data = null; if (dict.TryGetValue(obj.GetHashCode(), out data)) { return(data.RefCount); } return(-1); }