示例#1
0
 public static void Attach()
 {
     if (go != null)
     {
         return;
     }
     // And wire the dispatcher to monob proxy
     go       = new GameObject("Scripts");
     instance = go.AddComponent <MBProxy>();
     DontDestroyOnLoad(go);
     SceneManager.sceneLoaded += (scene, mode) =>
     {
         Debug.Log($"[SCENE] change to {scene.name} {scene.buildIndex}");
         Script.On.OnLevelWasLoaded(scene, mode);
         foreach (var ip in ipa)
         {
             try
             {
                 Debug.Log($"Notifying {ip.GetType().Name}");
                 ip.OnLevelWasLoaded(scene.buildIndex);
             }
             catch (Exception ex)
             {
                 print(ex);
             };
             hasScene = true;
         }
     };
 }
示例#2
0
    public static bool reload()
    {
        var oldeva = Evaluator;

        Evaluator = MonoScript.New(new Reporter(), typeof(Script), (oldeva == null && Patchwork.settings.cacheScripts)?Dir.cache:null);
        Output    = Evaluator.tw;
        Error     = Evaluator.tw;
        Assembly sass = null;

        try
        {
            sass = ScriptEntry.CompileScripts();
        } catch (Exception ex)
        {
            print(ex);
        }
        if (sass == null)
        {
            print("Script reload failed; trying to retain old script base.");
            Evaluator.Dispose();
            Evaluator = oldeva;
            return(false);
        }
        oldeva?.Dispose();
        var newbase = sass.GetType("ScriptEnv");

        if (newbase != null)
        {
            Evaluator.InteractiveBaseClass = newbase;
        }
        if (!firstRun)
        {
            firstRun = true;
            MBProxy.Attach();
            ScriptEntry.RunDLLs();
        }
        print("Scripts reloaded");
        return(true);
    }
示例#3
0
 public void Awake()
 {
     instance = this;
     Script.On.Awake();
 }