first commit
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.Mathematics.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(bool2x2)), CustomPropertyDrawer(typeof(bool2x3)), CustomPropertyDrawer(typeof(bool2x4))]
|
||||
[CustomPropertyDrawer(typeof(bool3x2)), CustomPropertyDrawer(typeof(bool3x3)), CustomPropertyDrawer(typeof(bool3x4))]
|
||||
[CustomPropertyDrawer(typeof(bool4x2)), CustomPropertyDrawer(typeof(bool4x3)), CustomPropertyDrawer(typeof(bool4x4))]
|
||||
[CustomPropertyDrawer(typeof(double2x2)), CustomPropertyDrawer(typeof(double2x3)), CustomPropertyDrawer(typeof(double2x4))]
|
||||
[CustomPropertyDrawer(typeof(double3x2)), CustomPropertyDrawer(typeof(double3x3)), CustomPropertyDrawer(typeof(double3x4))]
|
||||
[CustomPropertyDrawer(typeof(double4x2)), CustomPropertyDrawer(typeof(double4x3)), CustomPropertyDrawer(typeof(double4x4))]
|
||||
[CustomPropertyDrawer(typeof(float2x2)), CustomPropertyDrawer(typeof(float2x3)), CustomPropertyDrawer(typeof(float2x4))]
|
||||
[CustomPropertyDrawer(typeof(float3x2)), CustomPropertyDrawer(typeof(float3x3)), CustomPropertyDrawer(typeof(float3x4))]
|
||||
[CustomPropertyDrawer(typeof(float4x2)), CustomPropertyDrawer(typeof(float4x3)), CustomPropertyDrawer(typeof(float4x4))]
|
||||
[CustomPropertyDrawer(typeof(int2x2)), CustomPropertyDrawer(typeof(int2x3)), CustomPropertyDrawer(typeof(int2x4))]
|
||||
[CustomPropertyDrawer(typeof(int3x2)), CustomPropertyDrawer(typeof(int3x3)), CustomPropertyDrawer(typeof(int3x4))]
|
||||
[CustomPropertyDrawer(typeof(int4x2)), CustomPropertyDrawer(typeof(int4x3)), CustomPropertyDrawer(typeof(int4x4))]
|
||||
[CustomPropertyDrawer(typeof(uint2x2)), CustomPropertyDrawer(typeof(uint2x3)), CustomPropertyDrawer(typeof(uint2x4))]
|
||||
[CustomPropertyDrawer(typeof(uint3x2)), CustomPropertyDrawer(typeof(uint3x3)), CustomPropertyDrawer(typeof(uint3x4))]
|
||||
[CustomPropertyDrawer(typeof(uint4x2)), CustomPropertyDrawer(typeof(uint4x3)), CustomPropertyDrawer(typeof(uint4x4))]
|
||||
class MatrixDrawer : PropertyDrawer
|
||||
{
|
||||
#if !UNITY_2023_2_OR_NEWER
|
||||
public override bool CanCacheInspectorGUI(SerializedProperty property)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
if (!property.isExpanded)
|
||||
return EditorGUIUtility.singleLineHeight;
|
||||
var rows = 1 + property.type[property.type.Length - 3] - '0';
|
||||
return rows * EditorGUIUtility.singleLineHeight + (rows - 1) * EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
|
||||
static ReadOnlyCollection<string> k_ColPropertyPaths =
|
||||
new ReadOnlyCollection<string>(new[] { "c0", "c1", "c2", "c3" });
|
||||
static ReadOnlyCollection<string> k_RowPropertyPaths =
|
||||
new ReadOnlyCollection<string>(new[] { "x", "y", "z", "w" });
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
position.height = EditorGUIUtility.singleLineHeight;
|
||||
EditorGUI.PropertyField(position, property, label, false);
|
||||
|
||||
if (Event.current.type == EventType.ContextClick && position.Contains(Event.current.mousePosition))
|
||||
{
|
||||
DoUtilityMenu(property);
|
||||
Event.current.Use();
|
||||
}
|
||||
|
||||
if (!property.isExpanded)
|
||||
return;
|
||||
|
||||
var rows = property.type[property.type.Length - 3] - '0';
|
||||
var cols = property.type[property.type.Length - 1] - '0';
|
||||
|
||||
++EditorGUI.indentLevel;
|
||||
position = EditorGUI.IndentedRect(position);
|
||||
--EditorGUI.indentLevel;
|
||||
|
||||
var elementType = property.FindPropertyRelative("c0.x").propertyType;
|
||||
for (var row = 0; row < rows; ++row)
|
||||
{
|
||||
position.y += position.height + EditorGUIUtility.standardVerticalSpacing;
|
||||
var elementRect = new Rect(position)
|
||||
{
|
||||
width = elementType == SerializedPropertyType.Boolean
|
||||
? EditorGUIUtility.singleLineHeight
|
||||
: (position.width - (cols - 1) * EditorGUIUtility.standardVerticalSpacing) / cols
|
||||
};
|
||||
for (var col = 0; col < cols; ++col)
|
||||
{
|
||||
EditorGUI.PropertyField(
|
||||
elementRect,
|
||||
property.FindPropertyRelative($"{k_ColPropertyPaths[col]}.{k_RowPropertyPaths[row]}"),
|
||||
GUIContent.none
|
||||
);
|
||||
elementRect.x += elementRect.width + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary<SerializedPropertyType, Action<SerializedProperty, bool>> k_UtilityValueSetters =
|
||||
new Dictionary<SerializedPropertyType, Action<SerializedProperty, bool>>
|
||||
{
|
||||
{ SerializedPropertyType.Boolean, (property, b) => property.boolValue = b },
|
||||
{ SerializedPropertyType.Float, (property, b) => property.floatValue = b ? 1f : 0f },
|
||||
{ SerializedPropertyType.Integer, (property, b) => property.intValue = b ? 1 : 0 }
|
||||
};
|
||||
|
||||
void DoUtilityMenu(SerializedProperty property)
|
||||
{
|
||||
var rows = property.type[property.type.Length - 3] - '0';
|
||||
var cols = property.type[property.type.Length - 1] - '0';
|
||||
var elementType = property.FindPropertyRelative("c0.x").propertyType;
|
||||
var setValue = k_UtilityValueSetters[elementType];
|
||||
var menu = new GenericMenu();
|
||||
property = property.Copy();
|
||||
menu.AddItem(
|
||||
EditorGUIUtility.TrTextContent("Set to Zero"),
|
||||
false,
|
||||
() =>
|
||||
{
|
||||
property.serializedObject.Update();;
|
||||
for (var row = 0; row < rows; ++row)
|
||||
for (var col = 0; col < cols; ++col)
|
||||
setValue(
|
||||
property.FindPropertyRelative($"{k_ColPropertyPaths[col]}.{k_RowPropertyPaths[row]}"),
|
||||
false
|
||||
);
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
);
|
||||
if (rows == cols)
|
||||
{
|
||||
menu.AddItem(
|
||||
EditorGUIUtility.TrTextContent("Reset to Identity"),
|
||||
false,
|
||||
() =>
|
||||
{
|
||||
property.serializedObject.Update();
|
||||
for (var row = 0; row < rows; ++row)
|
||||
for (var col = 0; col < cols; ++col)
|
||||
setValue(
|
||||
property.FindPropertyRelative($"{k_ColPropertyPaths[col]}.{k_RowPropertyPaths[row]}"),
|
||||
row == col
|
||||
);
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
);
|
||||
}
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 407410bec194a4cfe929933685bb80a7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,202 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityObject = UnityEngine.Object;
|
||||
|
||||
namespace Unity.Mathematics.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(PostNormalizeAttribute))]
|
||||
class PostNormalizedVectorDrawer : PrimitiveVectorDrawer
|
||||
{
|
||||
static class Content
|
||||
{
|
||||
public static readonly string tooltip =
|
||||
L10n.Tr("Values you enter will be post-normalized. You will see the normalized result if you change selection and view the values again.");
|
||||
}
|
||||
|
||||
class VectorPropertyGUIData
|
||||
{
|
||||
const int k_MaxElements = 4;
|
||||
|
||||
public readonly bool Valid;
|
||||
|
||||
// parent property
|
||||
readonly SerializedProperty m_VectorProperty;
|
||||
// relative paths of element child properties
|
||||
readonly IReadOnlyList<string> m_ElementPaths;
|
||||
// the number of element child properties
|
||||
readonly int m_NumElements;
|
||||
// per child property; value is null if there are multiple different values
|
||||
readonly double?[] m_PreNormalizedValues;
|
||||
// per target; used to revert actual values for each object after displaying pre-normalized values
|
||||
readonly Dictionary<SerializedProperty, double4> m_PostNormalizedValues = new Dictionary<SerializedProperty, double4>();
|
||||
|
||||
public VectorPropertyGUIData(SerializedProperty property)
|
||||
{
|
||||
m_VectorProperty = property;
|
||||
var parentPath = m_VectorProperty.propertyPath;
|
||||
var i = 0;
|
||||
var elementPaths = new List<string>(k_MaxElements);
|
||||
var iterator = m_VectorProperty.Copy();
|
||||
while (iterator.Next(true) && iterator.propertyPath.StartsWith(parentPath))
|
||||
{
|
||||
if (i >= k_MaxElements || iterator.propertyType != SerializedPropertyType.Float)
|
||||
return;
|
||||
elementPaths.Add(iterator.propertyPath.Substring(parentPath.Length + 1));
|
||||
i++;
|
||||
}
|
||||
|
||||
Valid = true;
|
||||
m_NumElements = elementPaths.Count;
|
||||
m_ElementPaths = elementPaths;
|
||||
m_PreNormalizedValues = elementPaths.Select(p => (double?)null).ToArray();
|
||||
|
||||
UpdatePreNormalizedValues();
|
||||
UpdatePostNormalizedValues();
|
||||
}
|
||||
|
||||
void UpdatePostNormalizedValues()
|
||||
{
|
||||
m_PostNormalizedValues.Clear();
|
||||
foreach (var target in m_VectorProperty.serializedObject.targetObjects)
|
||||
{
|
||||
var postNormalizedValue = new double4();
|
||||
var parentProperty = new SerializedObject(target).FindProperty(m_VectorProperty.propertyPath);
|
||||
for (var i = 0; i < m_NumElements; ++i)
|
||||
postNormalizedValue[i] = parentProperty.FindPropertyRelative(m_ElementPaths[i]).doubleValue;
|
||||
m_PostNormalizedValues[parentProperty] = postNormalizedValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdatePreNormalizedValues()
|
||||
{
|
||||
for (var i = 0; i < m_NumElements; ++i)
|
||||
{
|
||||
var p = m_VectorProperty.FindPropertyRelative(m_ElementPaths[i]);
|
||||
m_PreNormalizedValues[i] = p.hasMultipleDifferentValues ? (double?)null : p.doubleValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyPreNormalizedValues()
|
||||
{
|
||||
m_VectorProperty.serializedObject.ApplyModifiedProperties();
|
||||
for (var i = 0; i < m_NumElements; ++i)
|
||||
{
|
||||
if (m_PreNormalizedValues[i] != null)
|
||||
m_VectorProperty.FindPropertyRelative(m_ElementPaths[i]).doubleValue = m_PreNormalizedValues[i].Value;
|
||||
}
|
||||
}
|
||||
|
||||
public void UnapplyPreNormalizedValues()
|
||||
{
|
||||
foreach (var target in m_PostNormalizedValues)
|
||||
{
|
||||
target.Key.serializedObject.Update();
|
||||
for (var i = 0; i < m_NumElements; ++i)
|
||||
{
|
||||
target.Key.FindPropertyRelative(m_ElementPaths[i]).doubleValue = target.Value[i];
|
||||
target.Key.serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
m_VectorProperty.serializedObject.Update();
|
||||
}
|
||||
|
||||
public void PostNormalize(Func<double4, double4> normalize)
|
||||
{
|
||||
m_VectorProperty.serializedObject.ApplyModifiedProperties();
|
||||
foreach (var target in m_PostNormalizedValues)
|
||||
{
|
||||
target.Key.serializedObject.Update();
|
||||
var postNormalizedValue = new double4();
|
||||
for (var i = 0; i < m_NumElements; ++i)
|
||||
postNormalizedValue[i] = target.Key.FindPropertyRelative(m_ElementPaths[i]).doubleValue;
|
||||
postNormalizedValue = normalize(normalize(postNormalizedValue));
|
||||
for (var i = 0; i < m_NumElements; ++i)
|
||||
target.Key.FindPropertyRelative(m_ElementPaths[i]).doubleValue = postNormalizedValue[i];
|
||||
target.Key.serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
UpdatePostNormalizedValues();
|
||||
m_VectorProperty.serializedObject.Update();
|
||||
}
|
||||
|
||||
public void RebuildIfDirty()
|
||||
{
|
||||
foreach (var target in m_PostNormalizedValues)
|
||||
{
|
||||
target.Key.serializedObject.Update();
|
||||
for (var i = 0; i < m_NumElements; ++i)
|
||||
{
|
||||
var serialized = target.Key.FindPropertyRelative(m_ElementPaths[i]).doubleValue;
|
||||
if (target.Value[i] != serialized)
|
||||
{
|
||||
UpdatePreNormalizedValues();
|
||||
UpdatePostNormalizedValues();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary<string, VectorPropertyGUIData> m_GUIDataPerPropertyPath = new Dictionary<string, VectorPropertyGUIData>();
|
||||
|
||||
protected virtual SerializedProperty GetVectorProperty(SerializedProperty property)
|
||||
{
|
||||
return property;
|
||||
}
|
||||
|
||||
protected virtual double4 Normalize(double4 value)
|
||||
{
|
||||
return math.normalizesafe(value);
|
||||
}
|
||||
|
||||
VectorPropertyGUIData GetGUIData(SerializedProperty property)
|
||||
{
|
||||
VectorPropertyGUIData guiData;
|
||||
if (!m_GUIDataPerPropertyPath.TryGetValue(property.propertyPath, out guiData))
|
||||
{
|
||||
guiData = new VectorPropertyGUIData(GetVectorProperty(property));
|
||||
m_GUIDataPerPropertyPath[property.propertyPath] = guiData;
|
||||
}
|
||||
return guiData;
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return GetGUIData(property).Valid ? base.GetPropertyHeight(property, label) : EditorGUIUtility.singleLineHeight;
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var guiData = GetGUIData(property);
|
||||
if (!guiData.Valid)
|
||||
{
|
||||
EditorGUI.HelpBox(
|
||||
EditorGUI.PrefixLabel(position, label),
|
||||
L10n.Tr($"{typeof(PostNormalizeAttribute).Name} only works with decimal vector types."),
|
||||
MessageType.None
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(label.tooltip))
|
||||
label.tooltip = Content.tooltip;
|
||||
|
||||
guiData.RebuildIfDirty();
|
||||
guiData.ApplyPreNormalizedValues();
|
||||
EditorGUI.BeginChangeCheck();
|
||||
base.OnGUI(position, property, label);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
guiData.UpdatePreNormalizedValues();
|
||||
guiData.PostNormalize(Normalize);
|
||||
}
|
||||
else
|
||||
{
|
||||
guiData.UnapplyPreNormalizedValues();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c060766caf7a405bb18fa4ba02780ee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,242 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.Mathematics.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(bool2)), CustomPropertyDrawer(typeof(bool3)), CustomPropertyDrawer(typeof(bool4))]
|
||||
[CustomPropertyDrawer(typeof(double2)), CustomPropertyDrawer(typeof(double3)), CustomPropertyDrawer(typeof(double4))]
|
||||
[CustomPropertyDrawer(typeof(float2)), CustomPropertyDrawer(typeof(float3)), CustomPropertyDrawer(typeof(float4))]
|
||||
[CustomPropertyDrawer(typeof(int2)), CustomPropertyDrawer(typeof(int3)), CustomPropertyDrawer(typeof(int4))]
|
||||
[CustomPropertyDrawer(typeof(uint2)), CustomPropertyDrawer(typeof(uint3)), CustomPropertyDrawer(typeof(uint4))]
|
||||
[CustomPropertyDrawer(typeof(DoNotNormalizeAttribute))]
|
||||
class PrimitiveVectorDrawer : PropertyDrawer
|
||||
{
|
||||
private string _PropertyType;
|
||||
|
||||
string GetPropertyType(SerializedProperty property)
|
||||
{
|
||||
if (_PropertyType == null)
|
||||
{
|
||||
_PropertyType = property.type;
|
||||
var isManagedRef = property.type.StartsWith("managedReference", StringComparison.Ordinal);
|
||||
if (isManagedRef)
|
||||
{
|
||||
var startIndex = "managedReference<".Length;
|
||||
var length = _PropertyType.Length - startIndex - 1;
|
||||
_PropertyType = _PropertyType.Substring("managedReference<".Length, length);
|
||||
}
|
||||
}
|
||||
|
||||
return _PropertyType;
|
||||
}
|
||||
|
||||
static class Content
|
||||
{
|
||||
public static readonly string doNotNormalizeCompatibility = L10n.Tr(
|
||||
$"{typeof(DoNotNormalizeAttribute).Name} only works with {typeof(quaternion)} and primitive vector types."
|
||||
);
|
||||
public static readonly string doNotNormalizeTooltip =
|
||||
L10n.Tr("This value is not normalized, which may produce unexpected results.");
|
||||
|
||||
public static readonly GUIContent[] labels2 = { new GUIContent("X"), new GUIContent("Y") };
|
||||
public static readonly GUIContent[] labels3 = { new GUIContent("X"), new GUIContent("Y"), new GUIContent("Z") };
|
||||
public static readonly GUIContent[] labels4 = { new GUIContent("X"), new GUIContent("Y"), new GUIContent("Z"), new GUIContent("W") };
|
||||
}
|
||||
|
||||
#if !UNITY_2023_2_OR_NEWER
|
||||
public override bool CanCacheInspectorGUI(SerializedProperty property)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var height = EditorGUIUtility.singleLineHeight;
|
||||
if (!EditorGUIUtility.wideMode)
|
||||
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
return height;
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var subLabels = Content.labels4;
|
||||
var startIter = "x";
|
||||
var propertyType = GetPropertyType(property);
|
||||
switch (propertyType[propertyType.Length - 1])
|
||||
{
|
||||
case '2':
|
||||
subLabels = Content.labels2;
|
||||
break;
|
||||
case '3':
|
||||
subLabels = Content.labels3;
|
||||
break;
|
||||
case '4':
|
||||
subLabels = Content.labels4;
|
||||
break;
|
||||
default:
|
||||
{
|
||||
if (property.type == nameof(quaternion))
|
||||
startIter = "value.x";
|
||||
else if (attribute is DoNotNormalizeAttribute)
|
||||
{
|
||||
EditorGUI.HelpBox(EditorGUI.PrefixLabel(position, label), Content.doNotNormalizeCompatibility, MessageType.None);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (attribute is DoNotNormalizeAttribute && string.IsNullOrEmpty(label.tooltip))
|
||||
label.tooltip = Content.doNotNormalizeTooltip;
|
||||
|
||||
label = EditorGUI.BeginProperty(position, label, property);
|
||||
var valuesIterator = property.FindPropertyRelative(startIter);
|
||||
MultiPropertyField(position, subLabels, valuesIterator, label);
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
void MultiPropertyField(Rect position, GUIContent[] subLabels, SerializedProperty valuesIterator, GUIContent label)
|
||||
{
|
||||
#if UNITY_2022_1_OR_NEWER
|
||||
EditorGUI.MultiPropertyField(position, subLabels, valuesIterator, label, EditorGUI.PropertyVisibility.All);
|
||||
#else
|
||||
EditorGUICopy.MultiPropertyField(position, subLabels, valuesIterator, label);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if !UNITY_2022_1_OR_NEWER
|
||||
internal class EditorGUICopy
|
||||
{
|
||||
internal const float kSpacingSubLabel = 4;
|
||||
private const float kIndentPerLevel = 15;
|
||||
internal const float kPrefixPaddingRight = 2;
|
||||
internal static int indentLevel = 0;
|
||||
private static readonly int s_FoldoutHash = "Foldout".GetHashCode();
|
||||
|
||||
// internal static readonly SVC<float> kVerticalSpacingMultiField = new SVC<float>("--theme-multifield-vertical-spacing", 0.0f);
|
||||
// kVerticalSpacingMultiField should actually look like the above line ^^^ but we don't have access to SVC<T>,
|
||||
// so instead we just set this value to what is observed in the debugger with the Unity dark theme.
|
||||
internal const float kVerticalSpacingMultiField = 2;
|
||||
|
||||
internal enum PropertyVisibility
|
||||
{
|
||||
All,
|
||||
OnlyVisible
|
||||
}
|
||||
|
||||
// This code is basically EditorGUI.MultiPropertyField(Rect, GUIContent[], SerializedProperty, GUIContent),
|
||||
// but with the property visibility assumed to be "All" instead of "OnlyVisible". We really want to have "All"
|
||||
// because it's possible for someone to hide something in the inspector with [HideInInspector] but then manually
|
||||
// draw it themselves later. In this case, if you called EditorGUI.MultiPropertyField() directly, you'd
|
||||
// end up with some fields that point to some unrelated visible property.
|
||||
public static void MultiPropertyField(Rect position, GUIContent[] subLabels, SerializedProperty valuesIterator, GUIContent label)
|
||||
{
|
||||
int id = GUIUtility.GetControlID(s_FoldoutHash, FocusType.Keyboard, position);
|
||||
position = MultiFieldPrefixLabel(position, id, label, subLabels.Length);
|
||||
position.height = EditorGUIUtility.singleLineHeight;
|
||||
MultiPropertyFieldInternal(position, subLabels, valuesIterator, PropertyVisibility.All);
|
||||
}
|
||||
|
||||
internal static void BeginDisabled(bool disabled)
|
||||
{
|
||||
// Unused, but left here to minimize changes in EditorGUICopy.MultiPropertyFieldInternal().
|
||||
}
|
||||
|
||||
internal static void EndDisabled()
|
||||
{
|
||||
// Unused, but left here to minimize changes in EditorGUICopy.MultiPropertyFieldInternal().
|
||||
}
|
||||
|
||||
internal static float CalcPrefixLabelWidth(GUIContent label, GUIStyle style = null)
|
||||
{
|
||||
if (style == null)
|
||||
style = EditorStyles.label;
|
||||
return style.CalcSize(label).x;
|
||||
}
|
||||
|
||||
internal static void MultiPropertyFieldInternal(Rect position, GUIContent[] subLabels, SerializedProperty valuesIterator, PropertyVisibility visibility, bool[] disabledMask = null, float prefixLabelWidth = -1)
|
||||
{
|
||||
int eCount = subLabels.Length;
|
||||
float w = (position.width - (eCount - 1) * kSpacingSubLabel) / eCount;
|
||||
Rect nr = new Rect(position) {width = w};
|
||||
float t = EditorGUIUtility.labelWidth;
|
||||
int l = indentLevel;
|
||||
indentLevel = 0;
|
||||
for (int i = 0; i < subLabels.Length; i++)
|
||||
{
|
||||
EditorGUIUtility.labelWidth = prefixLabelWidth > 0 ? prefixLabelWidth : CalcPrefixLabelWidth(subLabels[i]);
|
||||
|
||||
if (disabledMask != null)
|
||||
BeginDisabled(disabledMask[i]);
|
||||
EditorGUI.PropertyField(nr, valuesIterator, subLabels[i]);
|
||||
if (disabledMask != null)
|
||||
EndDisabled();
|
||||
nr.x += w + kSpacingSubLabel;
|
||||
|
||||
switch (visibility)
|
||||
{
|
||||
case PropertyVisibility.All:
|
||||
valuesIterator.Next(false);
|
||||
break;
|
||||
|
||||
case PropertyVisibility.OnlyVisible:
|
||||
valuesIterator.NextVisible(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
EditorGUIUtility.labelWidth = t;
|
||||
indentLevel = l;
|
||||
}
|
||||
|
||||
internal static bool LabelHasContent(GUIContent label)
|
||||
{
|
||||
if (label == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// @TODO: find out why checking for GUIContent.none doesn't work
|
||||
return label.text != string.Empty || label.image != null;
|
||||
}
|
||||
|
||||
internal static float indent => indentLevel * kIndentPerLevel;
|
||||
|
||||
internal static Rect MultiFieldPrefixLabel(Rect totalPosition, int id, GUIContent label, int columns)
|
||||
{
|
||||
if (!LabelHasContent(label))
|
||||
{
|
||||
return EditorGUI.IndentedRect(totalPosition);
|
||||
}
|
||||
|
||||
if (EditorGUIUtility.wideMode)
|
||||
{
|
||||
Rect labelPosition = new Rect(totalPosition.x + indent, totalPosition.y, EditorGUIUtility.labelWidth - indent, EditorGUIUtility.singleLineHeight);
|
||||
Rect fieldPosition = totalPosition;
|
||||
fieldPosition.xMin += EditorGUIUtility.labelWidth + kPrefixPaddingRight;
|
||||
|
||||
// If there are 2 columns we use the same column widths as if there had been 3 columns
|
||||
// in order to make columns line up neatly.
|
||||
if (columns == 2)
|
||||
{
|
||||
float columnWidth = (fieldPosition.width - (3 - 1) * kSpacingSubLabel) / 3f;
|
||||
fieldPosition.xMax -= (columnWidth + kSpacingSubLabel);
|
||||
}
|
||||
|
||||
EditorGUI.HandlePrefixLabel(totalPosition, labelPosition, label, id);
|
||||
return fieldPosition;
|
||||
}
|
||||
else
|
||||
{
|
||||
Rect labelPosition = new Rect(totalPosition.x + indent, totalPosition.y, totalPosition.width - indent, EditorGUIUtility.singleLineHeight);
|
||||
Rect fieldPosition = totalPosition;
|
||||
fieldPosition.xMin += indent + kIndentPerLevel;
|
||||
fieldPosition.yMin += EditorGUIUtility.singleLineHeight + kVerticalSpacingMultiField;
|
||||
EditorGUI.HandlePrefixLabel(totalPosition, labelPosition, label, id);
|
||||
return fieldPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ae914da3592740a58dd603fcb28b594
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace Unity.Mathematics.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(quaternion))]
|
||||
class QuaternionDrawer : PostNormalizedVectorDrawer
|
||||
{
|
||||
protected override SerializedProperty GetVectorProperty(SerializedProperty property)
|
||||
{
|
||||
return property.FindPropertyRelative("value");
|
||||
}
|
||||
|
||||
protected override double4 Normalize(double4 value)
|
||||
{
|
||||
return math.normalizesafe(new quaternion((float4)value)).value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b78c76192c2e742779541501cfe4ca76
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "Unity.Mathematics.Editor",
|
||||
"references": [
|
||||
"Unity.Mathematics"
|
||||
],
|
||||
"optionalUnityReferences": [],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": true
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 329b4ccd385744985bf3f83cfd77dfe7
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user