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();
            }
        }
Esempio n. 2
0
        public async Task InitializeServiceAsync()
        {
            scriptLoader = new ScriptLoader(config.Loader, providersManager, localizationManager);

            if (!string.IsNullOrEmpty(config.GlobalDefinesScript))
            {
                scriptLoader.GlobalDefinesScript = await scriptLoader.LoadAsync(config.GlobalDefinesScript);
            }

            if (CommunityModdingEnabled)
            {
                externalScriptLoader = new ScriptLoader(config.ExternalLoader, providersManager, localizationManager);
                externalScriptLoader.GlobalDefinesScript = scriptLoader.GlobalDefinesScript;
            }

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

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

                StartGameScriptName = scriptPaths.FirstOrDefault()?.Replace(scriptLoader.PathPrefix + "/", string.Empty);
            }
            else
            {
                StartGameScriptName = config.StartGameScript;
            }
        }
Esempio n. 3
0
        public virtual async UniTask InitializeServiceAsync()
        {
            foreach (var binding in Configuration.Bindings)
            {
                var sampler = new InputSampler(Configuration, binding, null);
                samplersMap[binding.Name] = sampler;
            }

            gameObject = Engine.CreateObject(nameof(InputManager));

            if (Configuration.SpawnEventSystem)
            {
                if (ObjectUtils.IsValid(Configuration.CustomEventSystem))
                {
                    Engine.Instantiate(Configuration.CustomEventSystem).transform.SetParent(gameObject.transform, false);
                }
                else
                {
                    gameObject.AddComponent <EventSystem>();
                }
            }

            if (Configuration.SpawnInputModule)
            {
                if (ObjectUtils.IsValid(Configuration.CustomInputModule))
                {
                    Engine.Instantiate(Configuration.CustomInputModule).transform.SetParent(gameObject.transform, false);
                }
                else
                {
                    #if ENABLE_INPUT_SYSTEM && INPUT_SYSTEM_AVAILABLE
                    var inputModule = gameObject.AddComponent <UnityEngine.InputSystem.UI.InputSystemUIInputModule>();
                    #else
                    var inputModule = gameObject.AddComponent <StandaloneInputModule>();
                    #endif
                    await AsyncUtils.WaitEndOfFrame;
                    inputModule.enabled = false; // Otherwise it stops processing UI events when using new input system.
                    inputModule.enabled = true;
                }
            }

            SampleInputAsync(sampleCTS.Token).Forget();
        }
Esempio n. 4
0
        public virtual async UniTask SpawnAsync(string path, CancellationToken cancellationToken = default, params string[] parameters)
        {
            if (IsObjectSpawned(path))
            {
                Debug.LogWarning($"Object `{path}` is already spawned and can't be spawned again before it's destroyed.");
                return;
            }

            var resourcePath   = SpawnConfiguration.ProcessInputPath(path, out _);
            var prefabResource = await loader.LoadAndHoldAsync(resourcePath, this);

            if (cancellationToken.CancelASAP)
            {
                return;
            }
            if (!prefabResource.Valid)
            {
                Debug.LogWarning($"Failed to spawn `{resourcePath}`: resource is not valid.");
                return;
            }

            var obj = Engine.Instantiate(prefabResource.Object, path);

            var spawnedObj = new SpawnedObject {
                Object = obj, State = new SpawnedObjectState(path, parameters)
            };

            spawnedObjects.Add(spawnedObj);

            var parameterized = obj.GetComponent <Commands.Spawn.IParameterized>();

            parameterized?.SetSpawnParameters(parameters);

            var awaitable = obj.GetComponent <Commands.Spawn.IAwaitable>();

            if (awaitable != null)
            {
                await awaitable.AwaitSpawnAsync(cancellationToken);
            }
        }
Esempio n. 5
0
        public Task InitializeServiceAsync()
        {
            foreach (var binding in config.Bindings)
            {
                var sampler = new InputSampler(binding, null, config.TouchContinueCooldown);
                samplersMap[binding.Name] = sampler;
            }

            gameObject = Engine.CreateObject("InputManager");

            if (config.SpawnEventSystem)
            {
                if (ObjectUtils.IsValid(config.CustomEventSystem))
                {
                    Engine.Instantiate(config.CustomEventSystem).transform.SetParent(gameObject.transform, false);
                }
                else
                {
                    gameObject.AddComponent <EventSystem>();
                }
            }


            if (config.SpawnInputModule)
            {
                if (ObjectUtils.IsValid(config.CustomInputModule))
                {
                    Engine.Instantiate(config.CustomInputModule).transform.SetParent(gameObject.transform, false);
                }
                else
                {
                    gameObject.AddComponent <StandaloneInputModule>();
                }
            }

            engineBehaviour.OnBehaviourUpdate += SampleInput;

            return(Task.CompletedTask);
        }