From d4afed0dd4b211e76fcbf1d8157ffbfbdf19cc8f Mon Sep 17 00:00:00 2001 From: Chris Dailey Date: Tue, 16 Nov 2021 08:58:55 -0500 Subject: [PATCH 1/2] Adds `HexAttribute` and associated property drawer. `HexPropertyDrawer` will draw an integer type decorated with `[Hex]` represented as a hexadecimal string. The user can modify the hex value and it will re-serialize as expected. If the `0x` is removed from the field, or the user enters a decimal number, that number will be serialized as decimal, but still displayed as hexadecimal. `HexAttribute` allows a manual setting of a minimum display width, adjusting how many potential 0s the hexadecimal string is padded with. By default, the the minimum width will be automatically determined based on the type of the field. --- .../Samples/DemoScene/DemoScene.unity | 153 ++++++++++++++---- .../Core/DrawerAttributes/HexAttribute.cs | 35 ++++ .../DrawerAttributes/HexAttribute.cs.meta | 11 ++ .../PropertyDrawers/HexPropertyDrawer.cs | 78 +++++++++ .../PropertyDrawers/HexPropertyDrawer.cs.meta | 11 ++ .../NaughtyAttributes/Scripts/Test/HexTest.cs | 51 ++++++ .../Scripts/Test/HexTest.cs.meta | 11 ++ 7 files changed, 322 insertions(+), 28 deletions(-) create mode 100644 Assets/NaughtyAttributes/Scripts/Core/DrawerAttributes/HexAttribute.cs create mode 100644 Assets/NaughtyAttributes/Scripts/Core/DrawerAttributes/HexAttribute.cs.meta create mode 100644 Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/HexPropertyDrawer.cs create mode 100644 Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/HexPropertyDrawer.cs.meta create mode 100644 Assets/NaughtyAttributes/Scripts/Test/HexTest.cs create mode 100644 Assets/NaughtyAttributes/Scripts/Test/HexTest.cs.meta diff --git a/Assets/NaughtyAttributes/Samples/DemoScene/DemoScene.unity b/Assets/NaughtyAttributes/Samples/DemoScene/DemoScene.unity index d4be8e1a..55a551c2 100644 --- a/Assets/NaughtyAttributes/Samples/DemoScene/DemoScene.unity +++ b/Assets/NaughtyAttributes/Samples/DemoScene/DemoScene.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.44657874, g: 0.49641258, b: 0.5748172, a: 1} + m_IndirectSpecularColor: {r: 0.18028378, g: 0.22571412, b: 0.30692285, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -184,7 +184,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 23 + m_RootOrder: 24 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &114650325 MonoBehaviour: @@ -201,23 +201,32 @@ MonoBehaviour: enable1: 0 enable2: 0 enum1: 0 + enum2: 0 enableIfAll: enableIfAny: enableIfEnum: + enableIfEnumFlag: + enableIfEnumFlagMulti: nest1: enable1: 1 enable2: 0 enum1: 0 + enum2: 0 enableIfAll: 1 enableIfAny: 2 enableIfEnum: 0 + enableIfEnumFlag: 0 + enableIfEnumFlagMulti: 0 nest2: enable1: 1 enable2: 1 enum1: 0 + enum2: 0 enableIfAll: {x: 0.25, y: 0.75} enableIfAny: {x: 0.25, y: 0.75} enableIfEnum: {x: 0.25, y: 0.75} + enableIfEnumFlag: {x: 0, y: 0} + enableIfEnumFlagMulti: {x: 0, y: 0} --- !u!114 &114650326 MonoBehaviour: m_ObjectHideFlags: 0 @@ -233,23 +242,32 @@ MonoBehaviour: disable1: 0 disable2: 0 enum1: 0 + enum2: 0 disableIfAll: disableIfAny: disableIfEnum: + disableIfEnumFlag: + disableIfEnumFlagMulti: nest1: disable1: 1 disable2: 0 enum1: 0 + enum2: 0 disableIfAll: 1 disableIfAny: 2 disableIfEnum: 3 + disableIfEnumFlag: 0 + disableIfEnumFlagMulti: 0 nest2: disable1: 1 disable2: 1 enum1: 0 + enum2: 0 enableIfAll: {x: 0.25, y: 0.75} enableIfAny: {x: 0.25, y: 0.75} enableIfEnum: {x: 0.25, y: 0.75} + disableIfEnumFlag: {x: 0, y: 0} + disableIfEnumFlagMulti: {x: 0, y: 0} --- !u!1 &155697335 GameObject: m_ObjectHideFlags: 0 @@ -279,7 +297,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 9 + m_RootOrder: 10 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &155697337 MonoBehaviour: @@ -327,7 +345,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 27 + m_RootOrder: 28 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &237121642 MonoBehaviour: @@ -375,7 +393,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 30 + m_RootOrder: 31 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &369789278 MonoBehaviour: @@ -423,7 +441,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 22 + m_RootOrder: 23 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &572382751 MonoBehaviour: @@ -476,7 +494,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 11 + m_RootOrder: 12 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &607441875 MonoBehaviour: @@ -538,8 +556,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 9c928ea15ae74a44089beb2e534c1a35, type: 3} m_Name: m_EditorClassIdentifier: - layerName: Default - layerIndex: 4 --- !u!1 &732714203 GameObject: m_ObjectHideFlags: 0 @@ -568,7 +584,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 20 + m_RootOrder: 21 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &779670086 GameObject: @@ -647,7 +663,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 15 + m_RootOrder: 16 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &892661556 MonoBehaviour: @@ -695,7 +711,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 16 + m_RootOrder: 17 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &933563386 MonoBehaviour: @@ -747,7 +763,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 12 + m_RootOrder: 13 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &948946035 MonoBehaviour: @@ -797,7 +813,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 10 + m_RootOrder: 11 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &993534227 MonoBehaviour: @@ -848,7 +864,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 7 + m_RootOrder: 8 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1139446981 MonoBehaviour: @@ -901,6 +917,7 @@ Transform: - {fileID: 779670087} - {fileID: 2015414598} - {fileID: 1622801696} + - {fileID: 1536277549} - {fileID: 1139446980} - {fileID: 1552114400} - {fileID: 155697336} @@ -1032,7 +1049,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 18 + m_RootOrder: 19 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1194502639 MonoBehaviour: @@ -1075,7 +1092,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 14 + m_RootOrder: 15 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1202167596 MonoBehaviour: @@ -1147,7 +1164,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 25 + m_RootOrder: 26 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1293624597 MonoBehaviour: @@ -1195,7 +1212,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 19 + m_RootOrder: 20 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1380469386 MonoBehaviour: @@ -1336,7 +1353,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 31 + m_RootOrder: 32 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1463483879 MonoBehaviour: @@ -1355,6 +1372,10 @@ MonoBehaviour: int1: 0 nest2: int2: 0 + inheritedNest: + int1: 0 + nest2: + int2: 0 --- !u!1 &1524906390 GameObject: m_ObjectHideFlags: 0 @@ -1385,7 +1406,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 24 + m_RootOrder: 25 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1524906392 MonoBehaviour: @@ -1402,23 +1423,32 @@ MonoBehaviour: show1: 0 show2: 0 enum1: 0 + enum2: 0 showIfAll: showIfAny: showIfEnum: + showIfEnumFlag: + showIfEnumFlagMulti: nest1: show1: 1 show2: 0 enum1: 0 + enum2: 0 showIfAll: 0 showIfAny: 0 showIfEnum: 0 + showIfEnumFlag: 0 + showIfEnumFlagMulti: 0 nest2: show1: 1 show2: 1 enum1: 0 + enum2: 0 showIfAll: {x: 0.25, y: 0.75} showIfAny: {x: 0.25, y: 0.75} showIfEnum: {x: 0.25, y: 0.75} + showIfEnumFlag: {x: 0, y: 0} + showIfEnumFlagMulti: {x: 0, y: 0} --- !u!114 &1524906393 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1434,23 +1464,90 @@ MonoBehaviour: hide1: 0 hide2: 0 enum1: 0 + enum2: 0 hideIfAll: hideIfAny: hideIfEnum: + hideIfEnumFlag: + hideIfEnumFlagMulti: nest1: hide1: 1 hide2: 0 enum1: 0 + enum2: 0 hideIfAll: 0 hideIfAny: 0 hideIfEnum: 0 + hideIfEnumFlag: 0 + hideIfEnumFlagMulti: 0 nest2: hide1: 1 hide2: 1 enum1: 0 + enum2: 0 hideIfAll: {x: 0.25, y: 0.75} hideIfAny: {x: 0.25, y: 0.75} hideIfEnum: {x: 0.25, y: 0.75} + hideIfEnumFlag: {x: 0, y: 0} + hideIfEnumFlagMulti: {x: 0, y: 0} +--- !u!1 &1536277548 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1536277549} + - component: {fileID: 1536277550} + m_Layer: 0 + m_Name: Hex + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1536277549 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1536277548} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 1148579784} + m_RootOrder: 7 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1536277550 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1536277548} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a3ad78e38899d42479c9d5b1d73ef9b5, type: 3} + m_Name: + m_EditorClassIdentifier: + hexHexAssign: 42405 + hexDecimalAssign: 1234 + hexShort: 4660 + hexByte: 204 + hexULong: 18446744069720004216 + hexMinimumWidth8: 0 + hexMinimumWidth4: 291 + hexMinimumWidth1: 291 + hexMinimumWidth0: 291 + hexMaximumValue: 65535 + hexCantApply: 0 + nest1: + hexNested1: 43981 + nest2: + hexNested2: 4275878552 --- !u!1 &1552114399 GameObject: m_ObjectHideFlags: 0 @@ -1480,7 +1577,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 8 + m_RootOrder: 9 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1552114401 MonoBehaviour: @@ -1667,7 +1764,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 28 + m_RootOrder: 29 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1706612701 GameObject: @@ -1698,7 +1795,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 29 + m_RootOrder: 30 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1706612703 MonoBehaviour: @@ -1773,7 +1870,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 13 + m_RootOrder: 14 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1747151589 MonoBehaviour: @@ -1834,7 +1931,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 21 + m_RootOrder: 22 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1784643786 MonoBehaviour: @@ -1887,7 +1984,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 26 + m_RootOrder: 27 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1871127831 MonoBehaviour: @@ -1935,7 +2032,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1148579784} - m_RootOrder: 17 + m_RootOrder: 18 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1989156460 MonoBehaviour: diff --git a/Assets/NaughtyAttributes/Scripts/Core/DrawerAttributes/HexAttribute.cs b/Assets/NaughtyAttributes/Scripts/Core/DrawerAttributes/HexAttribute.cs new file mode 100644 index 00000000..08bc5589 --- /dev/null +++ b/Assets/NaughtyAttributes/Scripts/Core/DrawerAttributes/HexAttribute.cs @@ -0,0 +1,35 @@ +using System; +using UnityEngine; + +namespace NaughtyAttributes +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public class HexAttribute : DrawerAttribute + { + public int MinimumDisplayWidth { get; set; } + + public HexAttribute(int minimumDisplayWidth = -1) + { + MinimumDisplayWidth = minimumDisplayWidth; + } + + public int GetDefaultWidthForType(string propertyTypeName) + { + return propertyTypeName switch + { + "byte" => 2, + "sbyte" => 2, + "char" => 4, + "int" => 8, + "uint" => 8, + "nint" => IntPtr.Size * 2, + "nuint" => UIntPtr.Size * 2, + "long" => 16, + "ulong" => 16, + "short" => 4, + "ushort" => 4, + _ => 0, + }; + } + } +} diff --git a/Assets/NaughtyAttributes/Scripts/Core/DrawerAttributes/HexAttribute.cs.meta b/Assets/NaughtyAttributes/Scripts/Core/DrawerAttributes/HexAttribute.cs.meta new file mode 100644 index 00000000..c64e5841 --- /dev/null +++ b/Assets/NaughtyAttributes/Scripts/Core/DrawerAttributes/HexAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6535845650e51014496208a7860fa8bf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/HexPropertyDrawer.cs b/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/HexPropertyDrawer.cs new file mode 100644 index 00000000..2fa378e3 --- /dev/null +++ b/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/HexPropertyDrawer.cs @@ -0,0 +1,78 @@ +using System.Globalization; +using UnityEditor; +using UnityEngine; + +namespace NaughtyAttributes.Editor +{ + [CustomPropertyDrawer(typeof(HexAttribute))] + public class HexPropertyDrawer : PropertyDrawerBase + { + private const string TypeWarningMessage = "{0} must be an integer type"; + + protected override float GetPropertyHeight_Internal(SerializedProperty property, GUIContent label) + { + bool validPropertyType = property.propertyType == SerializedPropertyType.Integer; + + return validPropertyType + ? GetPropertyHeight(property) + : GetPropertyHeight(property) + GetHelpBoxHeight(); + } + + protected override void OnGUI_Internal(Rect rect, SerializedProperty property, GUIContent label) + { + HexAttribute hexAttribute = (HexAttribute)attribute; + + EditorGUI.BeginProperty(rect, label, property); + + switch (property.propertyType) + { + case SerializedPropertyType.Integer: + DrawPropertyForInt(rect, property, label, hexAttribute); + break; + default: + string message = string.Format(TypeWarningMessage, property.name); + DrawDefaultPropertyAndHelpBox(rect, property, message, MessageType.Warning); + break; + } + + EditorGUI.EndProperty(); + } + + + private static void DrawPropertyForInt(Rect rect, SerializedProperty property, GUIContent label, HexAttribute hexAttribute) + { + int width = hexAttribute.MinimumDisplayWidth; + + if (width < 0) + { + width = hexAttribute.GetDefaultWidthForType(property.type); + } + + string stringValue = width <= 0 + ? $"0x{property.longValue:X}" + : "0x" + property.longValue.ToString($"X{width}"); + + stringValue = EditorGUI.TextField(rect, label, stringValue).ToLower(); + + if (stringValue.StartsWith("0x")) + { + // strip the 0x from the beginning, then parse as hex. + string no0X = stringValue.Remove(0, 2); + if (long.TryParse(no0X, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out long resultHex)) + { + property.longValue = resultHex; + } + } + else if (long.TryParse(stringValue, NumberStyles.Any, CultureInfo.CurrentCulture, out long resultAny)) + { + // no 0x, parse the number as decimal + property.longValue = resultAny; + } + else if (string.IsNullOrWhiteSpace(stringValue)) + { + // no value, default to zero. + property.longValue = 0; + } + } + } +} diff --git a/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/HexPropertyDrawer.cs.meta b/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/HexPropertyDrawer.cs.meta new file mode 100644 index 00000000..8c546e92 --- /dev/null +++ b/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/HexPropertyDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8dee9e81c946a6a4487fab6ccd5920eb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/NaughtyAttributes/Scripts/Test/HexTest.cs b/Assets/NaughtyAttributes/Scripts/Test/HexTest.cs new file mode 100644 index 00000000..56be3956 --- /dev/null +++ b/Assets/NaughtyAttributes/Scripts/Test/HexTest.cs @@ -0,0 +1,51 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace NaughtyAttributes.Test +{ + public class HexTest : MonoBehaviour + { + [Hex] + public int hexHexAssign = 0xA5A5; + [Hex] + public int hexDecimalAssign = 1234; + [Hex] + public ushort hexShort = 0x1234; + [Hex] + public byte hexByte = 0xCC; + [Hex] + public ulong hexULong = 0xFFFFFFFF_12345678; + [Hex(MinimumDisplayWidth = 8)] + public int hexMinimumWidth8; + [Hex(MinimumDisplayWidth = 4)] + public int hexMinimumWidth4 = 0x123; + [Hex(MinimumDisplayWidth = 1)] + public int hexMinimumWidth1 = 0x123; + [Hex(MinimumDisplayWidth = 0)] + public int hexMinimumWidth0 = 0x123; + [Hex, MaxValue(ushort.MaxValue)] + public int hexMaximumValue = 0x0123FFFF; + + [Hex] + public float hexCantApply; + + public HexNest1 nest1; + } + + [System.Serializable] + public class HexNest1 + { + [Hex] + public int hexNested1 = 0xABCD; + + public HexNest2 nest2; + } + + [System.Serializable] + public class HexNest2 + { + [Hex] + public uint hexNested2 = 0xFEDCBA98; + } +} \ No newline at end of file diff --git a/Assets/NaughtyAttributes/Scripts/Test/HexTest.cs.meta b/Assets/NaughtyAttributes/Scripts/Test/HexTest.cs.meta new file mode 100644 index 00000000..91e834ab --- /dev/null +++ b/Assets/NaughtyAttributes/Scripts/Test/HexTest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a3ad78e38899d42479c9d5b1d73ef9b5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 5ca56e5054bb0b9ffdb9205107fbac66446e3b50 Mon Sep 17 00:00:00 2001 From: Chris Dailey Date: Tue, 16 Nov 2021 09:08:31 -0500 Subject: [PATCH 2/2] Add README entry and screenshot for `Hex`. --- .../Documentation~/Hex_Inspector.png | Bin 0 -> 8866 bytes README.md | 15 +++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 Assets/NaughtyAttributes/Documentation~/Hex_Inspector.png diff --git a/Assets/NaughtyAttributes/Documentation~/Hex_Inspector.png b/Assets/NaughtyAttributes/Documentation~/Hex_Inspector.png new file mode 100644 index 0000000000000000000000000000000000000000..4bf26046f5ed8b86c36f85ee70e0d664893bac37 GIT binary patch literal 8866 zcmbuFXH-+o+wM_RK)R74MFfNZQUap%-lT>i5TzNaNDVbelO71=k&Zx+jtHR%hOQ6@ zMX3sc6bT)q1f)qjo9F+&>pf?kwa%CGA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-wXV$0!@G98J@CkBxR*dilbCQp|czGqxKhfLWzBI$@c<^@)=+aa) z((8*fBUX=p(DQa2*f76lgf)ZI8SKRb?N+XFJVkQh<0nwCMnIBvJ1FQlG9~_R$%)8Z z)_@68=UyF|t1YSFZeMyJMBj$IJj<8TDy^yaqbPS4Hh)xkONvn3id)^$cmZyYy9?ZHWbPEpFYslctbWP>N(f#^tWhnGz4Q$KUE1 z1}>#3usI1IuFg?Ib}Fez$u<_jrD@k8Y$a^3UKf14@7$HLv!fR&zS@%qk#zk5$wK0h zf+Sp{WS&tYMwWrVy|uLXK*v7wTg2dzMz>qmWNSC}Qs~0F zJ$^Rm%c5}awcp3HJrG)yjW(hIQi|Ouag}a1J4A7qwUjL@y8oK$yOh@wDt2!MICVKT zYe&*Q3vj8D9yhp77~8&nW%=*SK-($pBNPSTDa;X<<jp9?&JQ5*xhnwW0N+CN ifc`&AwCUzK*-(a);_U1o0r;+jOk2Z19jp2*{C@#o%xO~q literal 0 HcmV?d00001 diff --git a/README.md b/README.md index e7fa6f71..fc14ce6d 100644 --- a/README.md +++ b/README.md @@ -190,6 +190,21 @@ public class NaughtyComponent : MonoBehaviour ![inspector](https://github.com/dbrizov/NaughtyAttributes/blob/master/Assets/NaughtyAttributes/Documentation~/Expandable_Inspector.png) +### Hex +Draws the editor field for an integer in hexadecimal. Can be modified as hex, or decimal, but will always draw as hex. + +```csharp +public class NaughtyComponent : MonoBehaviour +{ + [Hex] + public int myHexValue = 0x1234; + [Hex] + public int myIntValue = 1234; +} +``` + +![inspector](https://github.com/dbrizov/NaughtyAttributes/blob/master/Assets/NaughtyAttributes/Documentation~/Hex_Inspector.png) + ### HorizontalLine ```csharp