Exemplo n.º 1
0
    //-------------------------------------------------------------------------------------------------

    //Coroutine compilation is similar to methodless code compilation, but with some nuances.
    void CompileCoroutine()
    {
        CSScriptEngine engine = new CSScriptEngine();

        engine.AddUsings("using UnityEngine;");

        //CompileCoroutine returns IEnumerable object, so you need to use GetEnumerator on it in order to
        //be able to pass it to StartCoroutine
        IEnumerator coroutine = engine.CompileCoroutine(@"yield return new WaitForSeconds(1f);Debug.Log(""Hey!"");").GetEnumerator();

        StartCoroutine(coroutine);
    }
 public void OnCompileButton(CompilationEvent cmpEv)
 {
     if (!Remote)
     {
         if (_currentlyCompilingCode)
         {
             _lastCompiledScript = _engine.CompileCode(cmpEv.Code);
         }
         else if (_currentlyCompilingCoroutine)
         {
             _lastCompiledCoroutine = _engine.CompileCoroutine(cmpEv.Code);
         }
     }
     else
     {
         if (_currentlyCompilingCode)
         {
             _engineRemote.CompileCode(cmpEv.Code);
         }
     }
 }
Exemplo n.º 3
0
    void CompileCoroutineTest()
    {
        _engine.Reset();

        //Setup
        string code =
            @"
                GameObject gob = new GameObject(""DynamicallyCreatedGO"");
                yield return null;
            ";

        _engine.AddUsings("using UnityEngine;");

        //Action
        StartCoroutine(_engine.CompileCoroutine(code).GetEnumerator());

        //Assert
        GameObject go = GameObject.Find("DynamicallyCreatedGO");

        Assert.IsTrue(go != null);

        //TearDown
        Destroy(go);
    }