所以问题是我的脚本中有一个公共变量,并且当更改此变量时,我想仅在 edit模式下并且仅当我处于时才调用特定函数Unity编辑器。当我想要一个小功能时, ExecuteInEditMode 将使整个脚本以编辑模式运行。现在,我使用带有以下代码的单独脚本组件:
using UnityEngine;
using UnityEditor;
[ExecuteInEditMode]
public class OtherScript: MonoBehaviour
{
private ThatBigScript that_script;
private float last_variable_value = 0.0f;
void Update()
{
if(Application.isEditor && !EditorApplication.isPlaying)
{
if(that_script == null)
{
that_script = GetComponent<ThatBigScript >();
}
if(that_script.variable_to_check != last_variable_value )
{
that_script.FunctionToCall(that_script.variable_to_check );
last_variable_value = that_script.variable_to_check ;
}
}
}
}
为一个小功能创建一个完整的单独组件需要做很多工作,所以有人可以帮我创建更漂亮,更短的东西吗?