Выполнение скрипта в редакторе

114
13 января 2020, 21:30

В UI есть скрипты Image, Text и так далее, они выполняются даже когда не нажата кнопка Play. Как это сделать для своего скрипта?

Answer 1

ExecuteInEditMode

Makes all instances of a script execute in Edit Mode.

By default, MonoBehaviours are only executed in Play Mode. By adding this attribute, any instance of the MonoBehaviour will have its callback functions executed while the Editor is in Edit Mode too.

...

The functions are not called constantly like they are in Play Mode.

  • Update is only called when something in the Scene changed.
  • OnGUI is called when the Game View receives a non-editor-only Event that it does not use (e.g., EventType.ScrollWheel) and does not forward to the Editor's keyboard shortcut system (e.g., EventType.KeyDown, EventType.KeyUp). Events forwarded to the Game View are enqueued and are not guaranteed to be processed immediately.
  • OnRenderObject and the other rendering callback functions are called on every repaint of the Scene View or Game View.

Пример кода:

[ExecuteInEditMode]
public class PrintAwake : MonoBehaviour
{
    void Awake()
    {
        Debug.Log("Editor causes this Awake");
    }
    void Update()
    {
        Debug.Log("Editor causes this Update");
    }
}
READ ALSO
Можно ли перемещать файлы в streamingassets из кода?

Можно ли перемещать файлы в streamingassets из кода?

Появилась необходимость динамически создавать материалыМне посоветовали делать через streamingassets

131
Как добавить form в вкладку tabControl? Windows Form

Как добавить form в вкладку tabControl? Windows Form

Я нашел в интернете такой код но он добавляет по индексу но мне нужно с добавлением и переводом на новую вкладку для пользователя

127
Заставить Input.MousePosition проходить через ноль

Заставить Input.MousePosition проходить через ноль

Имеется код, который таскает UI объект за мышкой по клеточкам,каждая клеточка 25 юнити метров

108
DataGridViewAutoFilter и BindingList

DataGridViewAutoFilter и BindingList

Вот так заполняю грид:

100