Exemple #1
0
        public T RequestAssetAtPath <T>(string path) where T : UnityEngine.Object
        {
            Assert.IsNotNull(m_SuperAsset, "Must be a SuperAsset type if we are requesting dependencies");

            // Is the asset in our cache?
            var key = new KeyValuePair <string, Type>(path.ToLower(), typeof(T));

            UnityEngine.Object cachedObject;

            if (m_CachedDatabase.TryGetValue(key, out cachedObject))
            {
                return(cachedObject as T);
            }

            // The path is either relative to our asset path or is absolute
            using (new ChDir(this.assetPath))
            {
                path = Path.GetFullPath(path);
                if (AssetPath.TryAbsoluteToAsset(ref path))
                {
                    // Keep track that the the asset is a dependency
                    m_SuperAsset.AddDependency(path);

                    // In most cases our dependency is already known by the AssetDatabase
                    T asset = AssetDatabase.LoadAssetAtPath <T>(path);
                    if (asset != null)
                    {
                        // Add the asset to our cache for next time it is requested
                        m_CachedDatabase[key] = asset;
                        return(asset);
                    }
                }
            }

            return(null);
        }