public async UniTask InitializeServiceAsync()
        {
            scriptLoader = Configuration.Loader.CreateFor <Script>(providerManager);
            if (CommunityModdingEnabled)
            {
                externalScriptLoader = Configuration.ExternalLoader.CreateFor <Script>(providerManager);
            }

            if (Application.isPlaying && Configuration.EnableNavigator)
            {
                var navigatorPrefab = Resources.Load <UI.ScriptNavigatorPanel>(navigatorPrefabResourcesPath);
                ScriptNavigator = Engine.Instantiate(navigatorPrefab, "ScriptNavigator");
                ScriptNavigator.SortingOrder = Configuration.NavigatorSortOrder;
                ScriptNavigator.SetVisibility(false);
            }

            if (string.IsNullOrEmpty(Configuration.StartGameScript))
            {
                var scriptPaths = await scriptLoader.LocateAsync(string.Empty);

                StartGameScriptName = scriptPaths.FirstOrDefault()?.Replace(scriptLoader.PathPrefix + "/", string.Empty);
            }
            else
            {
                StartGameScriptName = Configuration.StartGameScript;
            }

            if (Configuration.CountTotalCommands)
            {
                TotalCommandsCount = await CountTotalCommandsAsync();
            }
        }
        public async UniTask <IEnumerable <Script> > LoadAllScriptsAsync()
        {
            OnScriptLoadStarted?.Invoke();
            var scriptResources = await scriptLoader.LoadAllAsync();

            var scripts = scriptResources.Select(r => r.Object);

            await UniTask.WhenAll(scripts.Select(s => TryAddLocalizationScriptAsync(s)));

            if (ScriptNavigator)
            {
                ScriptNavigator.GenerateScriptButtons(scripts);
            }

            OnScriptLoadCompleted?.Invoke();
            return(scripts);
        }
示例#3
0
        public virtual async UniTask <IReadOnlyCollection <Script> > LoadAllScriptsAsync()
        {
            OnScriptLoadStarted?.Invoke();
            var scriptResources = await scriptLoader.LoadAllAsync();

            var scripts = scriptResources.Select(r => r.Object).ToArray();

            await UniTask.WhenAll(scripts.Select(TryAddLocalizationScriptAsync));

            if (ScriptNavigator)
            {
                ScriptNavigator.GenerateScriptButtons(scripts);
            }

            OnScriptLoadCompleted?.Invoke();
            return(scripts);
        }
        public void UnloadAllScripts()
        {
            scriptLoader.UnloadAll();
            foreach (var scriptName in localizationScripts.Keys)
            {
                localizationManager?.UnloadLocalizedResource(scriptLoader.BuildFullPath(scriptName));
            }
            localizationScripts.Clear();

            #if UNITY_GOOGLE_DRIVE_AVAILABLE
            // Delete cached scripts when using Google Drive resource provider.
            if (providerManager.ProviderInitialized(ResourceProviderConfiguration.GoogleDriveTypeName))
            {
                (providerManager.GetProvider(ResourceProviderConfiguration.GoogleDriveTypeName) as GoogleDriveResourceProvider).PurgeCachedResources(Configuration.Loader.PathPrefix);
            }
            #endif

            if (ScriptNavigator)
            {
                ScriptNavigator.DestroyScriptButtons();
            }
        }