在状态机行为的自定义 Unity 检查器中显示脚本字段



通常我会在自定义编辑器中使用以下方法来在检查器中显示组件的脚本字段

private void DrawScriptField()
{
// Disable editing
EditorGUI.BeginDisabledGroup(true); 
EditorGUILayout.ObjectField("Script", MonoScript.FromMonoBehaviour((MyClass) target), typeof(MyClass), false);
EditorGUI.EndDisabledGroup();
}

我的问题是MonoScript显然只包含FromMonoBehaviourFromScriptableObject两种方法,但没有方法可以从StateMachineBehaviour获取脚本。

如何在自定义编辑器中为StateMachineBehaviour脚本创建类似的脚本字段?

哦,没关系。我过度认为StateMachineBehaviour实际上是从ScriptableObject继承的,所以我可以简单地使用MonoScript.FromScriptableObject

最新更新