示例#1
0
    void CompileTypeTest()
    {
        _engine.Reset();

        //Setup
        string typeCode =
            @"
                public class DynamicType
                {
                    public void CreateGameObject(){GameObject gob = new GameObject(""DynamicallyCreatedGO"");}
                }
            ";

        _engine.AddUsings("using UnityEngine;");

        //Action
        _engine.CompileType("TestType", typeCode);
        _engine.CompileCode(@"DynamicType dt = new DynamicType();dt.CreateGameObject();").Execute();

        //Assert
        Type       dynamicType = _engine.CompileCurrentTypesIntoAssembly().GetType("DynamicType");
        GameObject go          = GameObject.Find("DynamicallyCreatedGO");

        Assert.IsTrue(go != null && dynamicType != null);

        //TearDown
        Destroy(go);
    }