Beispiel #1
0
        protected override void InitAPI()
        {
            var cmdGetScript = new Service.Scripting.Commands.GetMainScriptCommand();

            Publish(cmdGetScript);
            var api = new API(this);

            Kernel.Instance.Inject(api);
            cmdGetScript.result.Globals["FileSystem"] = api;
        }
 protected void ActivateDefaultScripting(string name)
 {
     try {
         var cmdGetScript = new Service.Scripting.Commands.GetMainScriptCommand();
         Publish(cmdGetScript);
         cmdGetScript.result.Globals[name] = this;
     }
     catch (Exception e) {
         UnityEngine.Debug.LogError("Error activating default scripting for Service.Scripting with lua-name:" + name);
         UnityEngine.Debug.LogException(e);
     }
 }
Beispiel #3
0
        protected override void InitAPI()
        {
            var cmdGetScript = new Service.Scripting.Commands.GetMainScriptCommand();

            Publish(cmdGetScript);
            var api = new API(this);

            Kernel.Instance.Inject(api);
            cmdGetScript.result.Globals["testValue"] = 95;

            ActivateDefaultScripting("DevUIService");
        }
Beispiel #4
0
        protected override void InitAPI()
        {
            // use all methods of the service
            ActivateDefaultScripting("MemoryBrowserService");


            var cmdGetScript = new Service.Scripting.Commands.GetMainScriptCommand();

            Publish(cmdGetScript);
            var api = new API(this);

            Kernel.Instance.Inject(api);
            cmdGetScript.result.Globals["MTest"]       = new TestEnvironment();
            cmdGetScript.result.Globals["TestListInt"] = new List <int>()
            {
                1, 2, 3, 4, 5, 6, 7
            };
            cmdGetScript.result.Globals["TestDictStringInt"] = new Dictionary <string, int>()
            {
                { "tom", 1 }, { "FORTUNA", 95 }, { "GHF", 11111 }
            };
            cmdGetScript.result.Globals["TestDictStringObject"] = new Dictionary <string, TestEnvironment.Employee>()
            {
                { "tom", new TestEnvironment.Employee() }, { "tom2", new TestEnvironment.Employee() }, { "tom3", new TestEnvironment.Employee() }
            };

            cmdGetScript.result.Globals["TestEmp"] = new List <TestEnvironment.Employee>()
            {
                new TestEnvironment.Employee()
                {
                    name = "tom"
                }, new TestEnvironment.Employee()
                {
                    name = "Stephan"
                }, new TestEnvironment.Employee()
                {
                    name = "Daniel"
                }, new TestEnvironment.Employee()
                {
                    name = "Matthias"
                }, new TestEnvironment.Employee()
                {
                    name = "Wolfgang"
                }
            };
        }
        protected override void AfterBind()
        {
            scriptingPath = filesystem.GetPath(FSDomain.ScriptingOutput);

            consoleInput.onEndEdit.AddListener(OnEndEdit);
            closeButton.onClick.AddListener(CloseConsole);

            this.OnEvent <Service.DevUIService.Events.WriteToScriptingConsole>().Subscribe(e => {
                AddToText(e.text);
            }).AddTo(this);

            this.OnEvent <Service.DevUIService.Events.ScriptingConsoleOpened>().Subscribe(e => {
                consoleInput.ActivateInputField();
            }).AddTo(this);

            Observable.EveryUpdate().Subscribe(_ => {
                if (Input.GetKeyDown(KeyCode.LeftControl))
                {
                    consoleInput.readOnly = true;
                }

                if (Input.GetKeyUp(KeyCode.LeftControl))
                {
                    consoleInput.readOnly = false;
                }

                //Auto completion switch
                if (Input.GetKey(KeyCode.UpArrow))
                {
                    if (historyID < 0)
                    {
                        //if keyHeldTimer == 0 we do one step, else if button is held more than 0.5 seconds we do continuous scroll
                        if (keyHeldTimer == 0 || keyHeldTimer > 0.5f)
                        {
                            autoCompleteWindow.SwitchElement(-1);
                        }
                    }
                }
                else if (Input.GetKey(KeyCode.DownArrow))
                {
                    if (historyID < 0)
                    {
                        //if keyHeldTimer == 0 we do one step, else if button is held more than 0.5 seconds we do continuous scroll
                        if (keyHeldTimer == 0 || keyHeldTimer > 0.5f)
                        {
                            autoCompleteWindow.SwitchElement(1);
                        }
                    }
                }
                else if (Input.GetKeyDown(KeyCode.Tab) && consoleInput.isFocused)
                {
                    autoCompleteWindow.ApplyCurrentProposal();
                }

                if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.UpArrow))
                {
                    keyHeldTimer += Time.deltaTime;
                }

                if (Input.GetKeyUp(KeyCode.DownArrow) || Input.GetKeyUp(KeyCode.UpArrow))
                {
                    keyHeldTimer = 0;
                }

                //History switch
                if (Input.GetKeyDown(KeyCode.UpArrow) && !autoCompleteWindow.HasContent)
                {
                    if (consoleInput.text == "" || historyID >= 0)
                    {
                        if (history.Count == 0)
                        {
                            return;
                        }

                        historyID = Mathf.Clamp(++historyID, -1, history.Count - 1);

                        consoleInput.text = history[historyID];
                    }
                }

                if (Input.GetKeyDown(KeyCode.DownArrow) && !autoCompleteWindow.HasContent)
                {
                    if (historyID >= 0)
                    {
                        if (history.Count == 0)
                        {
                            return;
                        }

                        historyID = Mathf.Clamp(--historyID, -1, history.Count - 1);

                        if (historyID < 0)
                        {
                            consoleInput.text = "";
                        }
                        else
                        {
                            consoleInput.text = history[historyID];
                        }
                    }
                }

                //Exclude buttons from value changed
                if (Input.anyKeyDown && !(Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.UpArrow)) || Input.GetKeyDown(KeyCode.Tab))
                {
                    OnValueChanged();
                }

                if (Input.GetKeyDown(KeyCode.Space) && Input.GetKey(KeyCode.LeftControl))
                {
                    GetAutocompleteProposal();
                }
            }).AddTo(this);

            var cmdGetMainScript = new Service.Scripting.Commands.GetMainScriptCommand();

            Publish(cmdGetMainScript);
            cmdGetMainScript.result.Options.DebugPrint = (inputString) => {
                AddToText(inputString);
            };
        }