Exemplo n.º 1
0
        /// <summary>
        /// 加载子资源对象
        /// </summary>
        public static SubAssetsOperationHandle LoadSubAssetsAsync(AssetInfo assetInfo)
        {
            if (assetInfo.IsInvalid)
            {
                YooLogger.Warning(assetInfo.Error);
                CompletedProvider completedProvider = new CompletedProvider(assetInfo);
                return(completedProvider.CreateHandle <SubAssetsOperationHandle>());
            }

            ProviderBase provider = TryGetProvider(assetInfo.ProviderGUID);

            if (provider == null)
            {
                if (_simulationOnEditor)
                {
                    provider = new DatabaseSubAssetsProvider(assetInfo);
                }
                else
                {
                    provider = new BundledSubAssetsProvider(assetInfo);
                }
                provider.InitSpawnDebugInfo();
                _providers.Add(provider);
            }
            return(provider.CreateHandle <SubAssetsOperationHandle>());
        }
Exemplo n.º 2
0
        /// <summary>
        /// 加载场景
        /// </summary>
        public static SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode, bool activateOnLoad, int priority)
        {
            if (assetInfo.IsInvalid)
            {
                YooLogger.Warning(assetInfo.Error);
                CompletedProvider completedProvider = new CompletedProvider(assetInfo);
                return(completedProvider.CreateHandle <SceneOperationHandle>());
            }

            // 注意:场景句柄永远保持唯一
            string providerGUID = assetInfo.ProviderGUID;

            if (_sceneHandles.ContainsKey(providerGUID))
            {
                return(_sceneHandles[providerGUID]);
            }

            // 如果加载的是主场景,则卸载所有缓存的场景
            if (sceneMode == LoadSceneMode.Single)
            {
                UnloadAllScene();
            }

            ProviderBase provider = TryGetProvider(providerGUID);

            if (provider == null)
            {
                if (_simulationOnEditor)
                {
                    provider = new DatabaseSceneProvider(assetInfo, sceneMode, activateOnLoad, priority);
                }
                else
                {
                    provider = new BundledSceneProvider(assetInfo, sceneMode, activateOnLoad, priority);
                }
                provider.InitSpawnDebugInfo();
                _providers.Add(provider);
            }

            var handle = provider.CreateHandle <SceneOperationHandle>();

            _sceneHandles.Add(providerGUID, handle);
            return(handle);
        }