网站新闻标题标题怎样进行优化,免备案域名是危险网站,php做的网站源代码在哪里,织梦的手机端网站模板下载地址有这个需求的原因是#xff0c;在编辑器的 Inspector 逻辑中#xff0c;写了许多生成逻辑。
现在不想挨个在 Inspector 上都点一遍按钮#xff0c;所以就需要能获取到它们的编辑器对象。
发现可以借助官方的 UnityEditor.Editor.CreateEditor 方法达到目的#xff0c;如下…有这个需求的原因是在编辑器的 Inspector 逻辑中写了许多生成逻辑。
现在不想挨个在 Inspector 上都点一遍按钮所以就需要能获取到它们的编辑器对象。
发现可以借助官方的 UnityEditor.Editor.CreateEditor 方法达到目的如下
public static TEditor GetEditorObjByRuntimeObjTEditor(UnityEngine.Object runtimeObj) where TEditor : UnityEditor.Editor
{var editorType typeof(TEditor);var editorObj UnityEditor.Editor.CreateEditor(runtimeObj, editorType) as TEditor;return editorObj;
}
如果我们想扩展 Unity 的原生组件也可以借助这个方法来实现。
[CustomEditor(typeof(Transform))]
public class TransformExt : Editor
{private Editor m_editor;void OnEnable(){var assembly Assembly.GetAssembly(typeof(Editor));var type assembly.GetType(UnityEditor.TransformInspector, true);m_editor Editor.CreateEditor(target, type);}public override void OnInspectorGUI(){// base.OnInspectorGUI();// 调用系统绘制方法m_editor.OnInspectorGUI();GUILayout.Space(5);if (GUILayout.Button(拓展按钮)){}}
}
效果如图