通常我会在自定义编辑器中使用以下方法来在检查器中显示组件的脚本字段
private void DrawScriptField()
{
// Disable editing
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.ObjectField("Script", MonoScript.FromMonoBehaviour((MyClass) target), typeof(MyClass), false);
EditorGUI.EndDisabledGroup();
}
我的问题是MonoScript
显然只包含FromMonoBehaviour
和FromScriptableObject
两种方法,但没有方法可以从StateMachineBehaviour
获取脚本。
如何在自定义编辑器中为StateMachineBehaviour
脚本创建类似的脚本字段?
哦,没关系。我过度认为StateMachineBehaviour
实际上是从ScriptableObject
继承的,所以我可以简单地使用MonoScript.FromScriptableObject
。