方便GUI编辑器开发的自制小脚本EditorGUILayout 和 BaseEditorGUIExtension
脚本代码
BaseEditorGUIExtension
public class EditorGUILayout : MonoBehaviour { }
BaseEditorGUIExtension
public class BaseEditorGUIExtension<T> : EditorWindow where T : Component
{
protected EditorGUILayout EditorGUILayoutObj;
protected static T layout;
private void Awake()
{
EditorGUILayoutObj = FindAnyObjectByType<EditorGUILayout>();
if (EditorGUILayoutObj == null)
{
GameObject cao = new GameObject("EditorGUILayout");
EditorGUILayoutObj = cao.AddComponent<EditorGUILayout>();
}
layout = FindAnyObjectByType<T>();
if (layout != null)
DestroyImmediate(layout.gameObject);
GameObject obj = new GameObject(typeof(T).ToString());
obj.transform.parent = EditorGUILayoutObj.transform;
layout = obj.AddComponent<T>();
}
}
重点
演示视频
脚本使用
实现