Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Possibilities for Editor plugins re: code IDE integration

Discussion in 'Scripting' started by justaguygames, Feb 17, 2021.

  1. justaguygames

    justaguygames

    Joined:
    Mar 4, 2015
    Posts:
    21
    Just a general question about possibilities. I'm thinking of writing an editor plugin and I want to be able to integrate the code IDE or at least change .cs files on the fly.

    When you click on a script in the editor, it loads the IDE. I'm wondering is there any possibility to edit a cs file live using Editor code? So say I click a button in the editor and the file in the ide updates.

    Or say I press another button and it inserts a new function into the code file. The thing is I'd want it to happen while the ide (say Visual studio) is open. So basically accessing the file from the editor code while it's open in visual studio.

    Thanks
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    You can make editor scripts write or change code. You can see an example in my Datasacks class in this file, which does a codegen step:

    https://github.com/kurtdekker/datas...cks/Assets/Datasack/Core/DatasackInspector.cs

    Just be sure to do a
    AssetDatabase.Refresh();
    to trigger a recompile.

    The usual file-sharing rules apply. If you changed it in VS and did not SAVE the file, then changing it in the editor is going to leave you in a halfway-two-versions state, just as if you edited it with Notepad while it was open in VS.
     
  3. justaguygames

    justaguygames

    Joined:
    Mar 4, 2015
    Posts:
    21
    Thanks a lot for the reply and example! So if VS studio is open and I change it through an editor script (and save the changes), then VS will reflect the change? Or a pop-up will come up in VS saying the file has changed and ask if I want to open the updated version?
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    I would not be so bold as to predict how Microsoft software might behave. I invite you to try it yourself.