1

I am looking to build a Unity based app which can update itself when we feed it some c# code, like Unity does using editor scripts. An example below will update Unity front end:

#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
public class MyWindow : EditorWindow
{
    string myString = "Hello World";

    // Add menu named "My Window" to the Window menu
    [MenuItem("Window/My Window")]
    static void Init()
    {
        // Get existing open window or if none, make a new one:
        MyWindow window = (MyWindow)EditorWindow.GetWindow(typeof(MyWindow));
        window.Show();
    }

    void OnGUI()
    {
        GUILayout.Label("Base Settings", EditorStyles.boldLabel);
        myString = EditorGUILayout.TextField("Text Field", myString);
    }
}
#endif

It looks like Unity compiles editor script, converts into dll, then loads the dll and updates itself using reflection. But it's just a guess, which can be horribly wrong. Anyone has information from authentic source?

  • 1
    Look into [`dotnet watch`](https://www.youtube.com/watch?v=nYudqdL55us), might be what you're looking for – blenderfreaky Jun 22 '19 at 17:19
  • Are you talking about how `EditorGUILayout.TextField()` updates the value of `myString` when you type into the gui object? That's just how Input Fields *work.* I don't know what "the app updates itself when you feed it C# code" has to do with this. Auto update systems are always a separate executable. – Draco18s no longer trusts SE Jun 22 '19 at 23:29
  • 1
    No, I am looking to build editor scripting system for my app. Question is not related to text field or input field. Above script is just an example of Unity editor script. – Harsh Priyadarshi Jun 23 '19 at 04:54
  • 1
    You might want to look into the [CodeDom API](https://www.codeproject.com/Tips/715891/Compiling-Csharp-Code-at-Runtime) or the newer [Roslyn API](http://www.tugberkugurlu.com/archive/compiling-c-sharp-code-into-memory-and-executing-it-with-roslyn) (see the [comparison](https://stackoverflow.com/questions/7852926/microsoft-roslyn-vs-codedom)) – Ghost4Man Jun 23 '19 at 08:13

0 Answers0