コード例 #1
0
        /// <summary>
        /// 异步更新资源版本号
        /// </summary>
        public UpdateStaticVersionOperation UpdateStaticVersionAsync(int timeout)
        {
            var operation = new HostPlayModeUpdateStaticVersionOperation(this, timeout);

            OperationSystem.StartOperaiton(operation);
            return(operation);
        }
コード例 #2
0
        /// <summary>
        /// 异步更新资源包裹
        /// </summary>
        public UpdatePackageOperation UpdatePackageAsync(int resourceVersion, int timeout)
        {
            var operation = new HostPlayModeUpdatePackageOperation(this, resourceVersion, timeout);

            OperationSystem.StartOperaiton(operation);
            return(operation);
        }
コード例 #3
0
        private static RawFileOperation GetRawFileInternal(AssetInfo assetInfo, string copyPath)
        {
            if (assetInfo.IsInvalid)
            {
                YooLogger.Warning(assetInfo.Error);
                RawFileOperation operation = new CompletedRawFileOperation(assetInfo.Error, copyPath);
                OperationSystem.StartOperaiton(operation);
                return(operation);
            }

            BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);

            if (_playMode == EPlayMode.EditorSimulateMode)
            {
                RawFileOperation operation = new EditorPlayModeRawFileOperation(bundleInfo, copyPath);
                OperationSystem.StartOperaiton(operation);
                return(operation);
            }
            else if (_playMode == EPlayMode.OfflinePlayMode)
            {
                RawFileOperation operation = new OfflinePlayModeRawFileOperation(bundleInfo, copyPath);
                OperationSystem.StartOperaiton(operation);
                return(operation);
            }
            else if (_playMode == EPlayMode.HostPlayMode)
            {
                RawFileOperation operation = new HostPlayModeRawFileOperation(bundleInfo, copyPath);
                OperationSystem.StartOperaiton(operation);
                return(operation);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
コード例 #4
0
        /// <summary>
        /// 异步卸载子场景
        /// </summary>
        public UnloadSceneOperation UnloadAsync()
        {
            // 如果句柄无效
            if (IsValid == false)
            {
                string error     = $"{nameof(SceneOperationHandle)} is invalid.";
                var    operation = new UnloadSceneOperation(error);
                OperationSystem.StartOperaiton(operation);
                return(operation);
            }

            // 如果是主场景
            if (IsMainScene())
            {
                string error = $"Cannot unload main scene. Use {nameof(YooAssets.LoadSceneAsync)} method to change the main scene !";
                YooLogger.Error(error);
                var operation = new UnloadSceneOperation(error);
                OperationSystem.StartOperaiton(operation);
                return(operation);
            }

            // 卸载子场景
            Scene sceneObject = SceneObject;

            AssetSystem.UnloadSubScene(Provider);
            {
                var operation = new UnloadSceneOperation(sceneObject);
                OperationSystem.StartOperaiton(operation);
                return(operation);
            }
        }
コード例 #5
0
        private InstantiateOperation InstantiateAsyncInternal(Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation)
        {
            InstantiateOperation operation = new InstantiateOperation(this, position, rotation, parent, setPositionRotation);

            OperationSystem.StartOperaiton(operation);
            return(operation);
        }
コード例 #6
0
 /// <summary>
 /// 开始下载
 /// </summary>
 public void BeginDownload()
 {
     if (_steps == ESteps.None)
     {
         OperationSystem.StartOperaiton(this);
     }
 }
コード例 #7
0
        /// <summary>
        /// 异步初始化
        /// </summary>
        public InitializationOperation InitializeAsync(bool locationToLower, string simulatePatchManifestPath)
        {
            _locationToLower = locationToLower;
            var operation = new EditorSimulateModeInitializationOperation(this, simulatePatchManifestPath);

            OperationSystem.StartOperaiton(operation);
            return(operation);
        }
コード例 #8
0
        /// <summary>
        /// 异步初始化
        /// </summary>
        public InitializationOperation InitializeAsync(bool locationToLower)
        {
            _locationToLower = locationToLower;
            var operation = new OfflinePlayModeInitializationOperation(this);

            OperationSystem.StartOperaiton(operation);
            return(operation);
        }
コード例 #9
0
        internal static void InternalUpdate()
        {
            // 更新异步操作系统
            OperationSystem.Update();

            // 更新下载管理系统
            DownloadSystem.Update();

            // 更新资源系统
            AssetSystem.Update();
        }
コード例 #10
0
        /// <summary>
        /// 异步初始化
        /// </summary>
        public InitializationOperation InitializeAsync(bool locationToLower, bool clearCacheWhenDirty, string defaultHostServer, string fallbackHostServer)
        {
            _locationToLower     = locationToLower;
            _clearCacheWhenDirty = clearCacheWhenDirty;
            _defaultHostServer   = defaultHostServer;
            _fallbackHostServer  = fallbackHostServer;

            var operation = new HostPlayModeInitializationOperation(this);

            OperationSystem.StartOperaiton(operation);
            return(operation);
        }
コード例 #11
0
 /// <summary>
 /// 创建资源包裹下载器,用于下载更新指定资源版本所有的资源包文件
 /// </summary>
 /// <param name="resourceVersion">指定更新的资源版本</param>
 /// <param name="timeout">超时时间</param>
 public static UpdatePackageOperation UpdatePackageAsync(int resourceVersion, int timeout = 60)
 {
     DebugCheckInitialize();
     if (_playMode == EPlayMode.EditorSimulateMode)
     {
         var operation = new EditorPlayModeUpdatePackageOperation();
         OperationSystem.StartOperaiton(operation);
         return(operation);
     }
     else if (_playMode == EPlayMode.OfflinePlayMode)
     {
         var operation = new OfflinePlayModeUpdatePackageOperation();
         OperationSystem.StartOperaiton(operation);
         return(operation);
     }
     else if (_playMode == EPlayMode.HostPlayMode)
     {
         return(_hostPlayModeImpl.UpdatePackageAsync(resourceVersion, timeout));
     }
     else
     {
         throw new NotImplementedException();
     }
 }
コード例 #12
0
 /// <summary>
 /// 开启一个异步操作
 /// </summary>
 /// <param name="operation">异步操作对象</param>
 public static void StartOperaiton(GameAsyncOperation operation)
 {
     OperationSystem.StartOperaiton(operation);
 }
コード例 #13
0
        /// <summary>
        /// 异步初始化
        /// </summary>
        public static InitializationOperation InitializeAsync(InitializeParameters parameters)
        {
            if (parameters == null)
            {
                throw new Exception($"YooAsset create parameters is null.");
            }

            if (parameters.LocationServices == null)
            {
                throw new Exception($"{nameof(IBundleServices)} is null.");
            }
            else
            {
                _locationServices = parameters.LocationServices;
            }

#if !UNITY_EDITOR
            if (parameters is EditorSimulateModeParameters)
            {
                throw new Exception($"Editor simulate mode only support unity editor.");
            }
#endif

            // 创建驱动器
            if (_isInitialize == false)
            {
                _isInitialize = true;
                UnityEngine.GameObject driverGo = new UnityEngine.GameObject("[YooAsset]");
                driverGo.AddComponent <YooAssetDriver>();
                UnityEngine.Object.DontDestroyOnLoad(driverGo);
            }
            else
            {
                throw new Exception("YooAsset is initialized yet.");
            }

            // 检测参数范围
            if (parameters.AssetLoadingMaxNumber < 1)
            {
                parameters.AssetLoadingMaxNumber = 1;
                YooLogger.Warning($"{nameof(parameters.AssetLoadingMaxNumber)} minimum value is 1");
            }
            if (parameters.OperationSystemMaxTimeSlice < 30)
            {
                parameters.OperationSystemMaxTimeSlice = 30;
                YooLogger.Warning($"{nameof(parameters.OperationSystemMaxTimeSlice)} minimum value is 30 milliseconds");
            }

            // 鉴定运行模式
            if (parameters is EditorSimulateModeParameters)
            {
                _playMode = EPlayMode.EditorSimulateMode;
            }
            else if (parameters is OfflinePlayModeParameters)
            {
                _playMode = EPlayMode.OfflinePlayMode;
            }
            else if (parameters is HostPlayModeParameters)
            {
                _playMode = EPlayMode.HostPlayMode;
            }
            else
            {
                throw new NotImplementedException();
            }

            // 初始化异步操作系统
            OperationSystem.Initialize(parameters.OperationSystemMaxTimeSlice);

            // 初始化下载系统
            if (_playMode == EPlayMode.HostPlayMode)
            {
#if UNITY_WEBGL
                throw new Exception($"{EPlayMode.HostPlayMode} not supports WebGL platform !");
#else
                var hostPlayModeParameters = parameters as HostPlayModeParameters;
                DownloadSystem.Initialize(hostPlayModeParameters.BreakpointResumeFileSize);
#endif
            }

            // 初始化资源系统
            InitializationOperation initializeOperation;
            if (_playMode == EPlayMode.EditorSimulateMode)
            {
                _editorSimulateModeImpl = new EditorSimulateModeImpl();
                _bundleServices         = _editorSimulateModeImpl;
                AssetSystem.Initialize(true, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
                var editorSimulateModeParameters = parameters as EditorSimulateModeParameters;
                initializeOperation = _editorSimulateModeImpl.InitializeAsync(
                    editorSimulateModeParameters.LocationToLower,
                    editorSimulateModeParameters.SimulatePatchManifestPath);
            }
            else if (_playMode == EPlayMode.OfflinePlayMode)
            {
                _offlinePlayModeImpl = new OfflinePlayModeImpl();
                _bundleServices      = _offlinePlayModeImpl;
                AssetSystem.Initialize(false, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
                initializeOperation = _offlinePlayModeImpl.InitializeAsync(parameters.LocationToLower);
            }
            else if (_playMode == EPlayMode.HostPlayMode)
            {
                _hostPlayModeImpl = new HostPlayModeImpl();
                _bundleServices   = _hostPlayModeImpl;
                AssetSystem.Initialize(false, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
                var hostPlayModeParameters = parameters as HostPlayModeParameters;
                initializeOperation = _hostPlayModeImpl.InitializeAsync(
                    hostPlayModeParameters.LocationToLower,
                    hostPlayModeParameters.ClearCacheWhenDirty,
                    hostPlayModeParameters.DefaultHostServer,
                    hostPlayModeParameters.FallbackHostServer);
            }
            else
            {
                throw new NotImplementedException();
            }

            // 监听初始化结果
            initializeOperation.Completed += InitializeOperation_Completed;
            return(initializeOperation);
        }