Exemple #1
0
        public bool ContainsAsset <T>(T asset)
            where T : ScriptableObject
        {
            if (asset == null)
            {
                return(false);
            }

            return(m_assets[RestoredAssetsRoot.FindAssetTypeIndex <T>()].ContainsKey(asset.GetHashCode()));
        }
Exemple #2
0
        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);
        }