1

I want to know how to execute a method when I create a new script, or rename an existing one ?

I know Unity do some processes when scripts are created. For example, when you create a script, the script is added to the list of components in the window Component > Scripts > NamespaceOfYourScript > NameOfYOurScript. I want to do something like that, but for my own custom window. I'm pretty sure that the process is accessible, but I don't know its name, how to access it and use it.

I have already searched on the documentation, unity answers, stack overflow, but I don't find yet what I was looking for (without knowing what is the exact process keyword you are looking for, it's not helpful to the search).

I want to get a script a bit like this kind :

 using UnityEngine;
 using UnityEditor;

 public class MyScript : SomeScriptProcess ()
 {
     void OnScriptSaved (System.Type TheScriptThatWasJustSaved)
     {
         //I execute my stuff here
     }
 }

Any help would be great. :)

1 Answers1

0

You can access the Assets folder. From there, iterate all folders and look for .cs files.

Method to get all files within folder and subfolders that will return a list

Store them in a list and use it to display the name in buttons.You can also make that search system Unity has.

When button is clicked, use AddComponent with reflection:

https://forum.unity3d.com/threads/add-a-custom-component-by-searching-for-its-name.323361/

Everts
  • 10,408
  • 2
  • 34
  • 45