所以问题是我的脚本中有一个公共变量,当这个变量改变时,我想调用一个特定的函数,但只在编辑模式下,而且只有当我在Unity Editor 中时。当我需要一个小功能时,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 ;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
为一个小功能创建一个完整的独立组件需要很多工作,所以有人可以帮助我创建更漂亮和更短的东西吗?