public override void Draw(InspectorField field, GUIStyle style) { RangeValueAttribute range = field.GetAttribute <RangeValueAttribute>(); if (range == null) { return; } EditorGUILayout.BeginHorizontal(); RangeFloat[] ranges = field.GetValues <RangeFloat>(); float[] mins = new float[ranges.Length]; float[] maxs = new float[ranges.Length]; float min = ranges[0].min; float max = ranges[0].max; bool different = false; for (int i = 0; i < ranges.Length; i++) { mins[i] = ranges[i].min; maxs[i] = ranges[i].max; if (ranges[i].min != min || ranges[0].max != max) { different = true; } } if (FloatEditor.DrawFloat("", mins, out min, GUILayout.Width(64))) { for (int i = 0; i < field.Instances.Length; i++) { field.SetValue(field.Instances[i], new RangeFloat(min, ranges[i].max)); } } EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = different; EditorGUILayout.MinMaxSlider(ref min, ref max, range.Min, range.Max); if (EditorGUI.EndChangeCheck() && min < max) { for (int i = 0; i < field.Instances.Length; i++) { field.SetValue(field.Instances[i], new RangeFloat(min, max)); } } if (FloatEditor.DrawFloat("", maxs, out max, GUILayout.Width(64))) { for (int i = 0; i < field.Instances.Length; i++) { field.SetValue(field.Instances[i], new RangeFloat(ranges[i].min, max)); } } EditorGUILayout.EndHorizontal(); }
public override void Draw(InspectorField field, GUIStyle style) { float labelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = VECTOR_FIELD_WIDTH; Bounds[] values = field.GetValues <Bounds>(); float[] centerX = new float[values.Length]; float[] centerY = new float[values.Length]; float[] centerZ = new float[values.Length]; float[] extendX = new float[values.Length]; float[] extendY = new float[values.Length]; float[] extendZ = new float[values.Length]; for (int i = 0; i < values.Length; i++) { centerX[i] = values[i].center.x; centerY[i] = values[i].center.y; centerZ[i] = values[i].center.z; extendX[i] = values[i].extents.x; extendY[i] = values[i].extents.y; extendZ[i] = values[i].extents.z; } GUILayout.BeginHorizontal(); float result; EditorGUILayout.LabelField("Center: ", GUILayout.Width(48)); if (FloatEditor.DrawFloat("X", centerX, style, out result)) { Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Center X"); for (int i = 0; i < field.Instances.Length; i++) { Vector3 center = values[i].center; center.x = result; values[i].center = center; field.SetValue(field.Instances[i], values[i]); } } if (FloatEditor.DrawFloat("Y", centerY, style, out result)) { Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Center Y"); for (int i = 0; i < field.Instances.Length; i++) { Vector3 center = values[i].center; center.y = result; values[i].center = center; field.SetValue(field.Instances[i], values[i]); } } if (FloatEditor.DrawFloat("Z", centerZ, style, out result)) { Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Center Z"); for (int i = 0; i < field.Instances.Length; i++) { Vector3 center = values[i].center; center.z = result; values[i].center = center; field.SetValue(field.Instances[i], values[i]); } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Extend: ", GUILayout.Width(48)); if (FloatEditor.DrawFloat("X", extendX, style, out result)) { Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Extend X"); for (int i = 0; i < field.Instances.Length; i++) { Vector3 extents = values[i].extents; extents.x = result; values[i].extents = extents; field.SetValue(field.Instances[i], values[i]); } } if (FloatEditor.DrawFloat("Y", extendY, style, out result)) { Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Extend Y"); for (int i = 0; i < field.Instances.Length; i++) { Vector3 extents = values[i].extents; extents.y = result; values[i].extents = extents; field.SetValue(field.Instances[i], values[i]); } } if (FloatEditor.DrawFloat("Z", extendZ, style, out result)) { Undo.RecordObjects(field.SerializedInstances, "Edit " + field.Name + " Extend Z"); for (int i = 0; i < field.Instances.Length; i++) { Vector3 extents = values[i].extents; extents.z = result; values[i].extents = extents; field.SetValue(field.Instances[i], values[i]); } } GUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUIUtility.labelWidth = labelWidth; }
public override void Draw(InspectorField field, GUIStyle style) { Type type = field.BaseType; float labelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = VECTOR_FIELD_WIDTH; if (type == typeof(Rect)) { Rect[] values = field.GetValues<Rect>(); float[] x = new float[values.Length]; float[] y = new float[values.Length]; float[] height = new float[values.Length]; float[] width = new float[values.Length]; for (int i = 0; i < values.Length; i++) { x[i] = values[i].x; y[i] = values[i].y; height[i] = values[i].height; width[i] = values[i].width; } GUILayout.BeginHorizontal(); float result; if (FloatEditor.DrawFloat("X", x, style, out result)) { field.RecordObjects("Edit " + field.Name + " X"); for (int i = 0; i < field.Instances.Length; i++) { values[i].x = result; field.SetValue(field.Instances[i], values[i]); } } if (FloatEditor.DrawFloat("Y", y, style, out result)) { field.RecordObjects("Edit " + field.Name + " Y"); for (int i = 0; i < field.Instances.Length; i++) { values[i].y = result; field.SetValue(field.Instances[i], values[i]); } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (FloatEditor.DrawFloat("W", width, style, out result)) { field.RecordObjects("Edit " + field.Name + " Width"); for (int i = 0; i < field.Instances.Length; i++) { values[i].width = result; field.SetValue(field.Instances[i], values[i]); } } if (FloatEditor.DrawFloat("H", height, style, out result)) { field.RecordObjects("Edit " + field.Name + " Height"); for (int i = 0; i < field.Instances.Length; i++) { values[i].height = result; field.SetValue(field.Instances[i], values[i]); } } GUILayout.EndHorizontal(); } else if (type == typeof(RectOffset)) { RectOffset[] values = field.GetValues<RectOffset>(); int[] left = new int[values.Length]; int[] right = new int[values.Length]; int[] top = new int[values.Length]; int[] bottom = new int[values.Length]; for (int i = 0; i < values.Length; i++) { left[i] = values[i].left; right[i] = values[i].right; top[i] = values[i].top; bottom[i] = values[i].bottom; } GUILayout.BeginHorizontal(); int result; if (IntegerEditor.DrawInt("L", left, style, out result)) { field.RecordObjects("Edit " + field.Name + " Left"); for (int i = 0; i < field.Instances.Length; i++) { values[i].left = result; field.SetValue(field.Instances[i], values[i]); } } if (IntegerEditor.DrawInt("R", right, style, out result)) { field.RecordObjects("Edit " + field.Name + " Right"); for (int i = 0; i < field.Instances.Length; i++) { values[i].right = result; field.SetValue(field.Instances[i], values[i]); } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (IntegerEditor.DrawInt("T", top, style, out result)) { field.RecordObjects("Edit " + field.Name + " Top"); for (int i = 0; i < field.Instances.Length; i++) { values[i].top = result; field.SetValue(field.Instances[i], values[i]); } } if (IntegerEditor.DrawInt("B", bottom, style, out result)) { field.RecordObjects("Edit " + field.Name + " Bottom"); for (int i = 0; i < field.Instances.Length; i++) { values[i].bottom = result; field.SetValue(field.Instances[i], values[i]); } } GUILayout.EndHorizontal(); } EditorGUILayout.Space(); EditorGUIUtility.labelWidth = labelWidth; }
public override void Draw(InspectorField field, GUIStyle style) { float width = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = VECTOR_FIELD_WIDTH; Quaternion[] values = field.GetValues <Quaternion>(); if (AdvancedInspectorControl.Level <= InspectorLevel.Advanced) { float[] x = new float[values.Length]; float[] y = new float[values.Length]; float[] z = new float[values.Length]; for (int i = 0; i < values.Length; i++) { Vector3 euler = values[i].eulerAngles; x[i] = euler.x; y[i] = euler.y; z[i] = euler.z; } GUILayout.BeginHorizontal(); float result; if (FloatEditor.DrawFloat("X", x, style, out result)) { field.RecordObjects("Edit " + field.Name + " X"); for (int i = 0; i < field.Instances.Length; i++) { Vector3 v = field.GetValue <Quaternion>(field.Instances[i]).eulerAngles; v.x = result; field.SetValue(field.Instances[i], Quaternion.Euler(v)); } } if (FloatEditor.DrawFloat("Y", y, style, out result)) { field.RecordObjects("Edit " + field.Name + " Y"); for (int i = 0; i < field.Instances.Length; i++) { Vector3 v = field.GetValue <Quaternion>(field.Instances[i]).eulerAngles; v.y = result; field.SetValue(field.Instances[i], Quaternion.Euler(v)); } } if (FloatEditor.DrawFloat("Z", z, style, out result)) { field.RecordObjects("Edit " + field.Name + " Z"); for (int i = 0; i < field.Instances.Length; i++) { Vector3 v = field.GetValue <Quaternion>(field.Instances[i]).eulerAngles; v.z = result; field.SetValue(field.Instances[i], Quaternion.Euler(v)); } } GUILayout.EndHorizontal(); } else { float[] x = new float[values.Length]; float[] y = new float[values.Length]; float[] z = new float[values.Length]; float[] w = new float[values.Length]; for (int i = 0; i < values.Length; i++) { x[i] = values[i].x; y[i] = values[i].y; z[i] = values[i].z; w[i] = values[i].w; } GUILayout.BeginHorizontal(); float result; if (FloatEditor.DrawFloat("X", x, style, out result)) { field.RecordObjects("Edit " + field.Name + " X"); for (int i = 0; i < field.Instances.Length; i++) { Quaternion v = field.GetValue <Quaternion>(field.Instances[i]); v.x = result; field.SetValue(field.Instances[i], v); } } if (FloatEditor.DrawFloat("Y", y, style, out result)) { field.RecordObjects("Edit " + field.Name + " Y"); for (int i = 0; i < field.Instances.Length; i++) { Quaternion v = field.GetValue <Quaternion>(field.Instances[i]); v.y = result; field.SetValue(field.Instances[i], v); } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (FloatEditor.DrawFloat("Z", z, style, out result)) { field.RecordObjects("Edit " + field.Name + " Z"); for (int i = 0; i < field.Instances.Length; i++) { Quaternion v = field.GetValue <Quaternion>(field.Instances[i]); v.z = result; field.SetValue(field.Instances[i], v); } } if (FloatEditor.DrawFloat("W", w, style, out result)) { field.RecordObjects("Edit " + field.Name + " W"); for (int i = 0; i < field.Instances.Length; i++) { Quaternion v = field.GetValue <Quaternion>(field.Instances[i]); v.w = result; field.SetValue(field.Instances[i], v); } } GUILayout.EndHorizontal(); } EditorGUIUtility.labelWidth = width; }
public override void Draw(InspectorField field, GUIStyle style) { Type type = field.BaseType; float width = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = VECTOR_FIELD_WIDTH; GUILayout.BeginHorizontal(); if (type == typeof(Vector2)) { Vector2[] values = field.GetValues <Vector2>(); float[] x = new float[values.Length]; float[] y = new float[values.Length]; for (int i = 0; i < values.Length; i++) { x[i] = values[i].x; y[i] = values[i].y; } float result; if (FloatEditor.DrawFloat("X", x, style, out result)) { field.RecordObjects("Edit " + field.Name + " X"); for (int i = 0; i < field.Instances.Length; i++) { values[i].x = result; field.SetValue(field.Instances[i], values[i]); } } if (FloatEditor.DrawFloat("Y", y, style, out result)) { field.RecordObjects("Edit " + field.Name + " Y"); for (int i = 0; i < field.Instances.Length; i++) { values[i].y = result; field.SetValue(field.Instances[i], values[i]); } } } else if (type == typeof(Vector3)) { Vector3[] values = field.GetValues <Vector3>(); float[] x = new float[values.Length]; float[] y = new float[values.Length]; float[] z = new float[values.Length]; for (int i = 0; i < values.Length; i++) { x[i] = values[i].x; y[i] = values[i].y; z[i] = values[i].z; } float result; if (FloatEditor.DrawFloat("X", x, style, out result)) { field.RecordObjects("Edit " + field.Name + " X"); for (int i = 0; i < field.Instances.Length; i++) { values[i].x = result; field.SetValue(field.Instances[i], values[i]); } } if (FloatEditor.DrawFloat("Y", y, style, out result)) { field.RecordObjects("Edit " + field.Name + " Y"); for (int i = 0; i < field.Instances.Length; i++) { values[i].y = result; field.SetValue(field.Instances[i], values[i]); } } if (FloatEditor.DrawFloat("Z", z, style, out result)) { field.RecordObjects("Edit " + field.Name + " Z"); for (int i = 0; i < field.Instances.Length; i++) { values[i].z = result; field.SetValue(field.Instances[i], values[i]); } } } else if (type == typeof(Vector4)) { Vector4[] values = field.GetValues <Vector4>(); float[] x = new float[values.Length]; float[] y = new float[values.Length]; float[] z = new float[values.Length]; float[] w = new float[values.Length]; for (int i = 0; i < values.Length; i++) { x[i] = values[i].x; y[i] = values[i].y; z[i] = values[i].z; w[i] = values[i].w; } float result; if (FloatEditor.DrawFloat("X", x, style, out result)) { field.RecordObjects("Edit " + field.Name + " X"); for (int i = 0; i < field.Instances.Length; i++) { values[i].x = result; field.SetValue(field.Instances[i], values[i]); } } if (FloatEditor.DrawFloat("Y", y, style, out result)) { field.RecordObjects("Edit " + field.Name + " Y"); for (int i = 0; i < field.Instances.Length; i++) { values[i].y = result; field.SetValue(field.Instances[i], values[i]); } } if (FloatEditor.DrawFloat("Z", z, style, out result)) { field.RecordObjects("Edit " + field.Name + " Z"); for (int i = 0; i < field.Instances.Length; i++) { values[i].z = result; field.SetValue(field.Instances[i], values[i]); } } if (FloatEditor.DrawFloat("W", w, style, out result)) { field.RecordObjects("Edit " + field.Name + " W"); for (int i = 0; i < field.Instances.Length; i++) { values[i].w = result; field.SetValue(field.Instances[i], values[i]); } } } GUILayout.EndHorizontal(); EditorGUIUtility.labelWidth = width; }