Exemple #1
0
    public bool LoadScript(Ship ship, StarSystem starSystem, string filename)
    {
        if (domain != null)
        {
            domain.Dispose();
        }

        domain = ScriptDomain.CreateDomain("ShipDomain", true);

        //domain.RoslynCompilerService.ReferenceAssemblies.Add(typeof(UnityEngine.Object).Assembly);
        //domain.RoslynCompilerService.ReferenceAssemblies.Add(typeof(Ship).Assembly);
        //domain.RoslynCompilerService.ReferenceAssemblies.Add(typeof(StarSystem).Assembly);
        //domain.RoslynCompilerService.ReferenceAssemblies.Add(typeof(LandableObject).Assembly);

        type = domain.CompileAndLoadMainFile(filename);

        if (proxy != null && !proxy.IsDisposed)
        {
            Debug.Log(proxy.IsDisposed);
            proxy.Dispose();
        }

        Debug.Log(gameObject.name);
        Debug.Log(type.Name);

        proxy = type.CreateInstance(gameObject);
        Debug.Log(gameObject.name);

        if (type != null)
        {
            proxy.Fields["ship"]       = ship;
            proxy.Fields["starSystem"] = starSystem;
            return(true);
        }
        else
        {
            return(false);
        }
    }