public UAsset GetAsset(string assetPath, Type type, EAssetHints hints)
        {
            WeakReference assetRef;
            UAsset        asset = null;

            if (_assets.TryGetValue(assetPath, out assetRef) && assetRef.IsAlive)
            {
                asset = assetRef.Target as UAsset;
                if (asset != null)
                {
                    ResourceManager.GetAnalyzer()?.OnAssetAccess(assetPath);
                    return(asset);
                }
            }
            ResourceManager.GetAnalyzer()?.OnAssetOpen(assetPath);
            if (Directory.Exists(assetPath))
            {
                asset = new UAssetDatabaseFileListAsset(assetPath);
            }
            else if (IsFileExists(assetPath))
            {
                asset = new UAssetDatabaseAsset(assetPath, type, hints, Random.Range(_asyncSimMin, _asyncSimMax));
            }
            else
            {
                asset = new UFailureAsset(assetPath, type);
            }
            _assets[assetPath] = new WeakReference(asset);
            return(asset);
        }
        public UAsset GetAsset(string assetPath, Type type)
        {
            WeakReference assetRef;
            UAsset        asset = null;

            if (_assets.TryGetValue(assetPath, out assetRef) && assetRef.IsAlive)
            {
                asset = assetRef.Target as UAsset;
                if (asset != null)
                {
                    ResourceManager.GetAnalyzer().OnAssetAccess(assetPath);
                    return(asset);
                }
            }
            ResourceManager.GetAnalyzer().OnAssetOpen(assetPath);
            if (File.Exists(assetPath))
            {
                asset = new UAssetDatabaseAsset(assetPath, type);
            }
            else
            {
                asset = new UFailureAsset(assetPath);
            }
            _assets[assetPath] = new WeakReference(asset);
            return(asset);
        }
Esempio n. 3
0
        private UAsset GetAsset(string assetPath, bool concrete, Type type)
        {
            UAsset        asset = null;
            WeakReference assetRef;
            var           transformedAssetPath = TransformAssetPath(assetPath);

            if (_assets.TryGetValue(transformedAssetPath, out assetRef) && assetRef.IsAlive)
            {
                asset = assetRef.Target as UAsset;
                if (asset != null)
                {
                    ResourceManager.GetAnalyzer().OnAssetAccess(assetPath);
                    return(asset);
                }
            }
            string bundleName;

            if (_assetPath2Bundle.TryGetValue(transformedAssetPath, out bundleName))
            {
                var bundle = this.GetBundle(bundleName);
                if (bundle != null)
                {
                    bundle.AddRef();
                    var assetBundleUBundle = bundle as UAssetBundleBundle;
                    if (assetBundleUBundle != null)
                    {
                        ResourceManager.GetAnalyzer().OnAssetOpen(assetPath);
                        if (concrete)
                        {
                            asset = new UAssetBundleConcreteAsset(assetBundleUBundle, assetPath, type);
                        }
                        else
                        {
                            asset = new UAssetBundleAsset(assetBundleUBundle, assetPath);
                        }
                        _assets[TransformAssetPath(assetPath)] = new WeakReference(asset);
                    }
                    else
                    {
                        var zipArchiveBundle = bundle as UZipArchiveBundle;
                        if (zipArchiveBundle != null)
                        {
                            ResourceManager.GetAnalyzer().OnAssetOpen(assetPath);
                            asset = new UZipArchiveBundleAsset(zipArchiveBundle, assetPath);
                            _assets[TransformAssetPath(assetPath)] = new WeakReference(asset);
                        }
                    }
                    bundle.RemoveRef();
                    return(asset);
                }
                // 不是 Unity 资源包, 不能实例化 AssetBundleUAsset
            }
            var invalid = new UFailureAsset(assetPath);

            _assets[TransformAssetPath(assetPath)] = new WeakReference(invalid);
            return(invalid);
        }
Esempio n. 4
0
        //TODO: hints
        private UAsset GetAsset(string assetPath, bool concrete, Type type, EAssetHints hints)
        {
            if (_closed)
            {
                return(null);
            }

            UAsset        asset = null;
            WeakReference assetRef;
            var           transformedAssetPath = TransformAssetPath(assetPath);

            if (_assets.TryGetValue(transformedAssetPath, out assetRef) && assetRef.IsAlive)
            {
                asset = assetRef.Target as UAsset;
                if (asset != null)
                {
                    ResourceManager.GetAnalyzer()?.OnAssetAccess(assetPath);
                    return(asset);
                }
            }

            string bundleName;

            if (TryGetBundleNameByAssetPath(transformedAssetPath, out bundleName))
            {
                var bundle = this.GetBundle(bundleName, hints);
                if (bundle != null)
                {
                    try
                    {
                        bundle.AddRef();
                        ResourceManager.GetAnalyzer()?.OnAssetOpen(assetPath);
                        asset = bundle.CreateAsset(assetPath, type, concrete, hints);
                        if (asset != null)
                        {
                            _assets[TransformAssetPath(assetPath)] = new WeakReference(asset);
                            return(asset);
                        }
                    }
                    finally
                    {
                        bundle.RemoveRef();
                    }
                }

                // 不是 Unity 资源包, 不能实例化 AssetBundleUAsset
            }

            var invalid = new UFailureAsset(assetPath, type);

            _assets[TransformAssetPath(assetPath)] = new WeakReference(invalid);
            return(invalid);
        }
Esempio n. 5
0
        private UAsset GetAsset(string assetPath, bool concrete)
        {
            UAsset        asset = null;
            WeakReference assetRef;

            if (_assets.TryGetValue(assetPath, out assetRef) && assetRef.IsAlive)
            {
                asset = assetRef.Target as UAsset;
                if (asset != null)
                {
                    return(asset);
                }
            }
            string bundleName;

            if (_assetPath2Bundle.TryGetValue(assetPath, out bundleName))
            {
                var bundle = this.GetBundle(bundleName);
                if (bundle != null)
                {
                    bundle.AddRef();
                    var assetBundleUBundle = bundle as UAssetBundleBundle;
                    if (assetBundleUBundle != null)
                    {
                        if (concrete)
                        {
                            asset = new UAssetBundleConcreteAsset(assetBundleUBundle, assetPath);
                        }
                        else
                        {
                            asset = new UAssetBundleAsset(assetBundleUBundle, assetPath);
                        }
                        _assets[assetPath] = new WeakReference(asset);
                    }
                    bundle.RemoveRef();
                    return(asset);
                }
                // 不是 Unity 资源包, 不能实例化 AssetBundleUAsset
            }
            var invalid = new UFailureAsset(assetPath);

            _assets[assetPath] = new WeakReference(invalid);
            return(invalid);
        }