public override void DrawFields(FieldInfo fieldInfo) { if (fieldInfo.Name == "anim") { GUIContent lable = new GUIContent(fieldInfo.Name); float tmpHeight = GUIExtension.GetHeight(fieldInfo.FieldType, lable); UnityObjectAsset oldObj = (UnityObjectAsset)fieldInfo.GetValue(Target); ObjectDrawer objectDrawer = ObjectDrawer.CreateEditor(oldObj); objectDrawer.OnGUI(EditorGUILayout.GetControlRect(true, tmpHeight), lable); if (GUILayout.Button("设置为动画时长")) { AnimationClip clip = (AnimationClip)oldObj.GetObj(); if (clip != null) { ClipModel clipModel = Target as ClipModel; clipModel.SetEnd(clipModel.StartTime + clip.length); } } } else { base.DrawFields(fieldInfo); } }
public void OnPropertyGUI(bool isShowDesc = false) { Type actionType = m_ActionData.GetType(); EditorGUILayout.LabelField(actionType.Name); var attrs = actionType.GetCustomAttributes(typeof(MemberDesc), false); if (attrs != null && attrs.Length > 0) { EditorGUILayout.LabelField((attrs[0] as MemberDesc).Desc, EditorStyles.wordWrappedLabel); } m_DataDrawer.OnGUI(isShowDesc); }
public void OnGUI(Rect rect) { if (m_BaseData == null) { EditorGUI.HelpBox(rect, "Data is Null", MessageType.Error); return; } GUILayout.BeginArea(rect); { scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(rect.width)); { m_DataDrawer.OnGUI(IsShowDesc()); } EditorGUILayout.EndScrollView(); } GUILayout.EndArea(); }
/// <summary> /// 绘制字段 /// </summary> /// <param name="rect">区域</param> /// <param name="type">类型</param> /// <param name="value">值</param> /// <param name="label">名</param> /// <returns></returns> public static object DrawField(Rect rect, Type type, object value, GUIContent label) { if (value == null) { if (!typeof(UnityObject).IsAssignableFrom(type)) { value = CreateInstance(type); } } if (!IsSupport(type)) { return(null); } if (type.IsEnum) { return(EditorGUI.EnumPopup(rect, label, (Enum)value)); } if (type.Equals(typeof(bool))) { return(EditorGUI.Toggle(rect, label, value == null ? false : (bool)value)); } if (type.Equals(typeof(short)) || type.Equals(typeof(ushort)) || type.Equals(typeof(int)) || type.Equals(typeof(uint))) { return(EditorGUI.IntField(rect, label, value == null ? 0 : (int)value)); } if (type.Equals(typeof(long)) || type.Equals(typeof(ulong))) { return(EditorGUI.LongField(rect, label, value == null ? 0 : (long)value)); } if (type.Equals(typeof(float))) { return(EditorGUI.FloatField(rect, label, value == null ? 0 : (float)value)); } if (type.Equals(typeof(double))) { return(EditorGUI.DoubleField(rect, label, value == null ? 0 : (double)value)); } if (type.Equals(typeof(string))) { return(EditorGUI.TextField(rect, label, value == null ? "" : (string)value)); } if (type.Equals(typeof(Vector2))) { return(EditorGUI.Vector2Field(rect, label, value == null ? Vector2.zero : (Vector2)value)); } if (type.Equals(typeof(Vector2Int))) { return(EditorGUI.Vector2IntField(rect, label, value == null ? Vector2Int.zero : (Vector2Int)value)); } if (type.Equals(typeof(Vector3))) { return(EditorGUI.Vector3Field(rect, label, value == null ? Vector3.zero : (Vector3)value)); } if (type.Equals(typeof(Vector3Int))) { return(EditorGUI.Vector3IntField(rect, label, value == null ? Vector3Int.zero : (Vector3Int)value)); } if (type.Equals(typeof(Vector4))) { return(EditorGUI.Vector4Field(rect, label, value == null ? Vector4.zero : (Vector4)value)); } if (type.Equals(typeof(Quaternion))) { Quaternion quaternion = value == null ? Quaternion.identity : (Quaternion)value; Vector4 vector = new Vector4(quaternion.x, quaternion.y, quaternion.z, quaternion.w); vector = EditorGUI.Vector4Field(rect, label, vector); quaternion.Set(vector.x, vector.y, vector.z, vector.w); return(quaternion); } if (type.Equals(typeof(Color))) { return(EditorGUI.ColorField(rect, label, value == null ? Color.black : (Color)value)); } if (type.Equals(typeof(Rect))) { return(EditorGUI.RectField(rect, label, value == null ? Rect.zero : (Rect)value)); } if (type.Equals(typeof(AnimationCurve))) { return(EditorGUI.CurveField(rect, label, value == null ? AnimationCurve.EaseInOut(0f, 0f, 1f, 1f) : (AnimationCurve)value)); } if (type.Equals(typeof(LayerMask))) { return((LayerMask)EditorGUI.LayerField(rect, label, (LayerMask)(value == null ? (-1) : value))); } if (typeof(UnityObject).IsAssignableFrom(type)) { return(EditorGUI.ObjectField(rect, label, (UnityObject)value, type, true)); } if (ObjectDrawer.CheckHasCustomDrawer(type)) { ObjectDrawer objectDrawer = ObjectDrawer.CreateEditor(value); return(objectDrawer.OnGUI(rect, label)); } return(null); }