Страницы

Поиск по вопросам

воскресенье, 29 марта 2020 г.

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

#c_sharp #unity3d


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


Ответы

Ответ 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"); } }

Комментариев нет:

Отправить комментарий