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);
        }
예제 #3
0
 private void OnAssetCompleted(UAsset asset)
 {
     if (_state == SceneState.Loading && asset.isLoaded)
     {
         JobScheduler.DispatchCoroutine(_LoadAsync());
     }
 }
예제 #4
0
 private void OnAssetLoaded(UAsset asset)
 {
     _loaded++;
     if (_loaded == _assets.Count)
     {
         OnLoaded();
     }
 }
예제 #5
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);
        }
예제 #6
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);
        }
예제 #7
0
        public UAsset GetAsset(string assetPath)
        {
            WeakReference assetRef;
            UAsset        asset = null;

            if (_assets.TryGetValue(assetPath, out assetRef) && assetRef.IsAlive)
            {
                asset = assetRef.Target as UAsset;
                if (asset != null)
                {
                    return(asset);
                }
            }
            asset = new UBuiltinAsset(assetPath);
            _assets[assetPath] = new WeakReference(asset);
            return(asset);
        }
예제 #8
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);
        }
예제 #9
0
        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);
            asset = new UBuiltinAsset(assetPath, type, hints);
            _assets[assetPath] = new WeakReference(asset);
            return(asset);
        }
예제 #10
0
 public UScene(UAsset asset)
 {
     _asset            = asset;
     _asset.completed += OnAssetCompleted;
 }
예제 #11
0
 public UEditorScene(UAsset asset)
     : base(asset)
 {
 }