bool active=EditorGUILayout.Toggle("active",_bodyObj.active);//bool类型
b2BodyType type=(b2BodyType)EditorGUILayout.EnumPopup("type",_bodyObj.type);//枚举类型 enum
RequireComponent的使用:
当你添加的一个用了RequireComponent组件的脚本,需要的组件将会自动被添加到game object(游戏物体)。这个可以有效的避免组装错误。举个例子一个脚本可能需要刚体总是被添加在相同的game object(游戏物体)上。用RequireComponent属性的话,这个过程将被自动完成,因此你可以永远不会犯组装错误。
[RequireComponent(typeof(Image))]
水平布局多个对象:
GUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Name:",GUILayout.MinWidth());
EditorGUILayout.LabelField("Type:",GUILayout.MinWidth());
EditorGUILayout.LabelField("Value:",GUILayout.MinWidth());
GUILayout.EndHorizontal();
public enum CustomPropertyType{
Bool=,
Int=,
Float=,
String=
}
public CustomPropertyType type;
public override void OnInspectorGUI() {
base.OnInspectorGUI();
GUILayout.BeginHorizontal();
EditorGUILayout.TextField("",GUILayout.MinWidth()); type=(CustomPropertyType)EditorGUILayout.EnumPopup(type,GUILayout.MinWidth());
EditorGUILayout.TextField("",GUILayout.MinWidth());
GUILayout.EndHorizontal(); GUILayout.BeginHorizontal();
EditorGUILayout.Space();
if(GUILayout.Button("✚",GUILayout.Width())){//✚
Debug.Log("click add");
}
if(GUILayout.Button("─",GUILayout.Width())){//━
Debug.Log("click delete");
}
GUILayout.EndHorizontal(); }