public void OnDeleteTypeButton(DeleteTypeEvent ev)
 {
     if (!Remote)
     {
         _engine.RemoveTypes(ev.TypeID);
     }
     else
     {
         _engineRemote.RemoveTypes(ev.TypeID);
     }
 }
Exemplo n.º 2
0
    //-------------------------------------------------------------------------------------------------

    //Remove compiled type from system, now this type is inaccessible to dynamic code
    void RemoveType()
    {
        CSScriptEngine engine = new CSScriptEngine();

        engine.AddUsings("using UnityEngine;");

        engine.AddOnCompilationFailedHandler(OnCompilationFailedAction);

        string typeCode = @"
                
                                public class SimpleType
                                {
                                    public void PrintHey()
                                    {
                                        Debug.Log(""Hey!"");
                                    }
                                }

                              ";

        engine.CompileType("SimpleType", typeCode);

        string anotherTypeCode = @"
                
                                public class AnotherSimpleType
                                {
                                    public void InvokeSimpleTypesPrintHey()
                                    {
                                        Debug.Log(""Greetings from AnotherSimpleType! Invoking SimpleTypes PrintHey method..."");
                                        SimpleType sm = new SimpleType(); sm.PrintHey();
                                    }
                                }

                              ";

        engine.CompileType("AnotherSimpleType", anotherTypeCode);

        engine.RemoveTypes("AnotherSimpleType");

        //This will cause a compilation error, beacause we removed AnotherSimpleType
        engine.CompileCode(@"
                                                 AnotherSimpleType sm = new AnotherSimpleType(); 
                                               ");

        engine.RemoveOnCompilationFailedHandler(OnCompilationFailedAction);
    }
Exemplo n.º 3
0
    void RemoveTypeTest()
    {
        _engine.Reset();

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

        _engine.AddUsings("using UnityEngine;");
        bool currentCompilationSucceeded;

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

        currentCompilationSucceeded = _lastCompilationSucceeded;

        Type dynamicType = _engine.CompileCurrentTypesIntoAssembly().GetType("DynamicType");

        //Assert
        Assert.IsTrue(dynamicType == null && !currentCompilationSucceeded);
    }