// Start is called before the first frame update
    void Start()
    {
        clear = GameObject.Find("clearobject").GetComponent <ClearScript>();

        print(waves[_currentwave].wave.Count);
        Nextwave();
    }
Exemple #2
0
        private void frmEvents_Load(object sender, EventArgs e)
        {
            var oFrmTestForm = new frmTestForm();

            engine = ClearScript.Create(EngineType.V8);
            engine.AddHostObject("form", this);
            engine.AddHostType("Form2", typeof(frmTestForm));
            engine.AddHostType("alert", typeof(AlertBox));
            engine.AddHostType("msgBox", typeof(MessageBox));

            engine.Execute(@"
                
                form.btnForm.Click.connect((s,e) => {
                 form.btnForm.Text = 'Clicked';
                 let form2 = new Form2();
                 form2.label1.Text = 'Opened from an event connected to ClearScript';
                 form2.Show();
            });
            ");

            engine.Execute(@"
                form.txtKeyPress.KeyPress.connect((s,e) => {
                 form.lblKeyPressResult.Text = 'Key pressed: '+e.KeyChar;
            });
            ");


            engine.Execute(@"
                form.btnAlert.Click.connect((s,e) => {
                 alert.Show('Hello from ClearScript');
            });
            ");


            if (!oFrmTestForm.IsDisposed)
            {
                engine.Execute(@"
                form.btnMsgBox.Click.connect((s,e) => {
                 msgBox.Show('Hello, I came from ClearScript :D');
            });
            ");
            }
            else
            {
                engine.AddHostObject("form2", oFrmTestForm);
            }
        }
        private void txtCommandLine_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)
            {
                code += this.txtCommandLine.Lines[this.txtCommandLine.Lines.Length - 2];
                if (code.Contains("exec"))
                {
                    code = code.Replace("exec", "");
                    engine.Execute(code);
                    code = "";
                }

                if (code.Contains("clear"))
                {
                    code = "";
                    this.txtCommandLine.Clear();
                    this.txtCommandLine.SelectionStart = this.txtCommandLine.Text.Length;
                }
                if (code.Contains("help"))
                {
                    this.txtCommandLine.Text          += "How to use: \n";
                    this.txtCommandLine.Text          += "Write your code like you would on a regular text editor, then type in exec on a new line to execute your commands \n";
                    this.txtCommandLine.Text          += "To clear the CLI, just type in clear: \n";
                    this.txtCommandLine.Text          += "To switch to another engine, just type in switch followed by the engine type: \n";
                    this.txtCommandLine.Text          += "example: switch vbscript to code using vbscipt, type switch v8 to go back to javascript \n";
                    this.txtCommandLine.Text          += "you can dynamically import Objects/Classes in this CLI, just type in import <your_object_name> <object_namespace> <object_type> \n";
                    this.txtCommandLine.Text          += "Using ClearScript is fun :D \n";
                    this.txtCommandLine.SelectionStart = this.txtCommandLine.Text.Length;
                    code = "";
                }

                if (code.Contains("switch"))
                {
                    if (code.Contains("vbscript") || code.Contains("vbs"))
                    {
                        try
                        {
                            engine = ClearScript.Create(EngineType.VBScript);
                            engine.AddHostObject("log", this);
                            this.txtCommandLine.Text += "Switched to VBScript \n";
                            code = "";
                            this.txtCommandLine.SelectionStart = this.txtCommandLine.Text.Length;
                        }
                        catch (ExecutionEngineException ex)
                        {
                            Output(ex.Message);
                            code = "";
                        }
                    }
                    else
                    if (code.Contains("v8"))
                    {
                        engine = ClearScript.Create(EngineType.V8);
                        engine.AddHostObject("log", this);
                        this.txtCommandLine.Text += "Switched to V8 \n";
                        code = "";
                        this.txtCommandLine.SelectionStart = this.txtCommandLine.Text.Length;
                    }
                    else
                    {
                        Output("Missing engine type, please type 'switch vbscript' or 'switch v8' to change engine types");
                        code = "";
                    }
                }

                if (code.Contains("import"))
                {
                    string command       = code.Substring(code.IndexOf("import"));
                    var    command_array = command.Split(' ');
                    if (command.Length < 4)
                    {
                        Output("Error, please type import <object_name> <object_namespace> <object_type>");
                        code = "";
                    }
                    else
                    {
                        try
                        {
                            Import(command_array[1], command_array[3], command_array[2]);
                            code = "";
                        }
                        catch
                        {
                            Output("Please verify that you typed the right command, or verify that the type of object you provided exists");
                        }
                    }
                }


                e.Handled = true;
            }
        }
 private void frmCommandLine_Load(object sender, EventArgs e)
 {
     this.txtCommandLine.Text += "\n";
     engine = ClearScript.Create(EngineType.V8);
     engine.AddHostObject("log", this);
 }
Exemple #5
0
 // Use this for initialization
 void Start()
 {
     myScript = gameObject.GetComponent <ClearScript>();
     start    = true;
 }