0

Я использую атрибут ExecuteInEditMode, функцию которую мне нужно т.е.

$if UNITY_EDITOR
public void SetAllItem()
{
Debug.Log("Test");
}
$endif

и вызываю в апдейте

private void Update()
{
$if UNITY_EDITOR
SetAllItem();
$endif
}

да я понимаю что она как-то по другом должна вызываться (контекстное меню не подходит) но я не знаю как и вызываю так, но как можно сделать так что бы функция вызывалась только если игра не запущена, т.е. что бы только в моде редактирования.

2 ответа 2

3

Пример кода если игра была запущена из эдитора:

Returns true if the game is being run from the Unity editor; false if run from any deployment target.

Возвращает true, если запущен редактор Unity; false в остальных случаях

using UnityEngine;

class Example : MonoBehaviour
{
    void Start()
    {
        if (Application.isEditor)
        {
            print("We are running this from inside of the editor!");
        }
    }
}

https://docs.unity3d.com/ScriptReference/Application-isEditor.html


Если игра запущена в принципе:

using UnityEngine;

class Example : MonoBehaviour
{
    void Start()
    {
        if (Application.isPlaying)
        {
            print("In player or playmode");
        }
    }
}

https://docs.unity3d.com/ScriptReference/Application-isPlaying.html


Так же возможно будет полезным атрибут [ExecuteInEditMode]

[ExecuteInEditMode]
public class PrintAwake : MonoBehaviour
{
    void Awake()
    {
        Debug.Log("Editor causes this Awake");
    }

    void Update()
    {
        Debug.Log("Editor causes this Update");
    }
}

https://docs.unity3d.com/ScriptReference/ExecuteInEditMode.html

1

isEditor и isPlaying, вероятно, то, что вам надо.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.