赞
踩
GUILayout.flexibleSpace
例如GUILayout.TextField
,它默认是没有宽度的,这时候我们就可以通过以下设定来设置
这些设置会重写style里面的宽高设定
GUILayout.Width
用来设置控件宽度
GUILayout.Height
用来设置空间高度
GUILayout.MinWidth
和GUILayout.MaxHeight
设定该控件的最大宽度和最小宽度,当拖拽窗口进行缩放的时候,该控件会缩小到最小宽度后不再变化。GUILayout.MinHeight和GUILayout.MaxHeight
也是同样的道理
GUILayout.ExpandWidth
是否允许控件进行水平方向的扩展,我测试了后发现,自动布局的所有控件默认是进行水平扩展的,因此会平分整个水平宽度
GUILayout.BeginHorizontal();
createFileName = GUILayout.TextField(createFileName);
GUILayout.Button("新建"); //所有宽度平分
GUILayout.Button("重命名");
GUILayout.Button("复制");
GUILayout.Button("删除");
GUILayout.EndHorizontal();
-
GUILayout.BeginHorizontal();
createFileName = GUILayout.TextField(createFileName,GUILayout.ExpandWidth(true));//会占据所有剩余空间
GUILayout.Button("新建",GUILayout.ExpandWidth(false));//按照style固有宽度渲染
GUILayout.Button("重命名", GUILayout.ExpandWidth(false));
GUILayout.Button("复制", GUILayout.ExpandWidth(false));
GUILayout.Button("删除", GUILayout.ExpandWidth(false));
GUILayout.EndHorizontal();
UnityEditor.Callbacks.OnOpenAsset(0)
[UnityEditor.Callbacks.OnOpenAsset(0)]
static bool OpenAsset(int id, int line)
{
var obj = EditorUtility.InstanceIDToObject(id);
if (obj.GetType() == typeof(UnitSettingObject))
{
OpenWindow();
return true;
}
return false;
}
GUI.Toggle(pos, value, label, "button")
最后的GUIStyle设置为button就可以变成toggle形式的button了EditorGUI.BeginChangeCheck()
和EditorGUI.EndChangeCheck()
可以用来检测control控件是否修改EditorGUI.DelayedDoubleField()
和EditorGUI.DoubleField()
的区别在于前者只有当鼠标移出输入框的时候才会返回值EditorGUILayout.Foldout()
是一个带标签的折叠箭头EditorGUILayout.BeginFoldoutHeaderGroup()
与EditorGUILayout.EndFoldoutHeaderGroup
相比于Foldout()
,有一个HeaderTitle,而且是一个折叠块EditorUtility.OpenFolderPanel ("excel路径", LoadCenter.RootDir, "C:\\");
用于选定一个文件路径obj = EditorGUILayout.ObjectField (label, obj, typeof (T), allowSceneObjects) as T;
用来选择资源public struct Vertical : IDisposable { public Rect Rect { get; private set; } FlexibleTypes flexible; public static Vertical New (FlexibleTypes flexible, GUIStyle style, params GUILayoutOption[] options) { var rect = EditorGUILayout.BeginVertical (style, options); if (flexible.FlexibleBegin ()) { GUILayout.FlexibleSpace (); } return new Vertical () { flexible = flexible, Rect = rect }; } public void Dispose () { if (flexible.FlexibleEnd ()) { GUILayout.FlexibleSpace (); } EditorGUILayout.EndVertical (); } }
using (GUIScope.Horizontal.New (FlexibleTypes.Begin))
{
}
EditorGUI.PropertyField()
,传入SerializeProperty
即可stages = serializedObject.FindProperty ("stages");
可以查找到对应属性Undo, prefab保存
这些。serializeObject.update();
//draw UI
serializedObject.ApplyModifiedProperties();
public static bool PropertyField (Rect position, SerializedProperty property, [DefaultValue ("false")] bool includeChildren);
includeChildren
设置为true会绘制该属性的内部字段PropertyDrawer
后重写OnGUI
在内部是无法使用Layout自动布局的。会导致报错ReOrderableList
,但其实并不好用GetItemHeight()
private void OnDrawGizmos ()
{
foreach (var pos in allCube)
{
Gizmos.DrawCube (pos, Vector3.one);
}
}
public class PosEditCom : MonoBehaviour
{
}
public class PosEditComGizmoDrawer
{
[DrawGizmo (GizmoType.Pickable|GizmoType.Selected|GizmoType.NonSelected)]
static void DrawGizmoForMyScript (PosEditCom scr, GizmoType gizmoType)
{
Gizmos.DrawCube (scr.transform.position, Vector3.one);
}
}
GenericMenu
menu.ShowAsContext()
就可以显示出来menu.AddSeperator()
添加分隔符menu.AddItem()
添加右键菜单的选项if (Event.current.type == EventType.MouseDown && Event.current.button == 1)
{
menu.ShowMenu ();
Event.current.Use ();
}
GameObject
一样的MenuItem("Assets/")
EditorApplication.projectWindowItemOnGUI+=OnProjectGUI
EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyGUI;
[MenuItem ("Assets/TestMenu01/TestMenu04")] static void TestMenu04 () { Debug.Log ("点击了TestMenu04"); } [In itializeOnLoadMethod] static void StartInitializeOnLoadMethod () { EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyGUI; } static void OnHierarchyGUI (int instanceID, Rect selectionRect) { if (Event.current != null && selectionRect.Contains (Event.current.mousePosition) && Event.current.button == 1 && Event.current.type <= EventType.MouseUp) { GameObject selectedGameObject = EditorUtility.InstanceIDToObject (instanceID) as GameObject; //这里可以判断selectedGameObject的条件 if (selectedGameObject) { Vector2 mousePosition = Event.current.mousePosition; EditorUtility.DisplayPopupMenu (new Rect (mousePosition.x, mousePosition.y, 0, 0), "Window/Test", null); Event.current.Use (); } } }
[CreateAssetMenu (menuName = "xuhaitao/personInfo")]
public class shishi : ScriptableObject
{
public string namee;
public int age;
public Image img;
}
OnOpenAssetAttribute
是一个特性 [OnOpenAssetAttribute(1)]
public static bool step1(int instanceID, int line)
{
string name = EditorUtility.InstanceIDToObject(instanceID).name;
Debug.Log("Open Asset step: 1 (" + name + ")");
return false; // we did not handle the open
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。