Ejemplo n.º 1
0
        /// <summary>
        /// Causes the mouse crawler to stop moving and reset to its initial position.
        /// </summary>
        public void StopCrawler()
        {
            if (activeCrawlerScript != null)
            {
                // Get the maze crawler instance
                MazeCrawler mazeCrawler = activeCrawlerScript.GetInstanceAs <MazeCrawler>(false);

                // Call the restart method
                mazeCrawler.Restart();

                // Destroy script
                activeCrawlerScript.Dispose();
                activeCrawlerScript = null;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Causes the mouse crawler to reset its initial position and start crawling again.
        /// </summary>
        public void RestartCrawler()
        {
            if (activeCrawlerScript != null)
            {
                ScriptType type = activeCrawlerScript.ScriptType;

                // Get the maze crawler instance
                MazeCrawler mazeCrawler = activeCrawlerScript.GetInstanceAs <MazeCrawler>(false);

                // Call the restart method
                mazeCrawler.Restart();

                // Remove and re-add script to reset it
                activeCrawlerScript.Dispose();
                activeCrawlerScript = type.CreateInstance(mazeMouse);

                activeCrawlerScript.Fields["breadcrumbPrefab"] = breadcrumbPrefab;
                activeCrawlerScript.Fields["moveSpeed"]        = mouseSpeed;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Main run method.
        /// This causes any modified code to be recompiled and executed on the mouse crawler.
        /// </summary>
        public void RunCrawler()
        {
            // Get the C# code from the input field
            string cSharpSource = runCrawlerInput.text;

            // Dont recompile the same code
            if (activeCSharpSource != cSharpSource || activeCrawlerScript == null)
            {
                // Remove any other scripts
                StopCrawler();

                try
                {
                    // Compile code
                    ScriptType type = domain.CompileAndLoadMainSource(cSharpSource, ScriptSecurityMode.UseSettings, assemblyReferences);

                    // Check for null
                    if (type == null)
                    {
                        if (domain.RoslynCompilerService.LastCompileResult.Success == false)
                        {
                            throw new Exception("Maze crawler code contained errors. Please fix and try again");
                        }
                        else if (domain.SecurityResult.IsSecurityVerified == false)
                        {
                            throw new Exception("Maze crawler code failed code security verification");
                        }
                        else
                        {
                            throw new Exception("Maze crawler code does not define a class. You must include one class definition of any name that inherits from 'RoslynCSharp.Example.MazeCrawler'");
                        }
                    }

                    // Check for base class
                    if (type.IsSubTypeOf <MazeCrawler>() == false)
                    {
                        throw new Exception("Maze crawler code must define a single type that inherits from 'RoslynCSharp.Example.MazeCrawler'");
                    }



                    // Create an instance
                    activeCrawlerScript = type.CreateInstance(mazeMouse);
                    activeCSharpSource  = cSharpSource;

                    // Set speed value
                    activeCrawlerScript.Fields["breadcrumbPrefab"] = breadcrumbPrefab;
                    activeCrawlerScript.Fields["moveSpeed"]        = mouseSpeed;
                }
                catch (Exception e)
                {
                    // Show the code editor window
                    codeEditorWindow.SetActive(true);
                    throw e;
                }
            }
            else
            {
                // Get the maze crawler instance
                MazeCrawler mazeCrawler = activeCrawlerScript.GetInstanceAs <MazeCrawler>(false);

                // Call the restart method
                mazeCrawler.Restart();
            }
        }