diff --git a/Assets/Example.cs b/Assets/Example.cs index 0cc9b74..ebb96e1 100644 --- a/Assets/Example.cs +++ b/Assets/Example.cs @@ -8,6 +8,7 @@ public class Example : MonoBehaviour { public BlobAsset Blob; + public BlobViewer Viewer; private void Awake() { @@ -15,6 +16,8 @@ private void Awake() BlobAssetReference blob = Blob.Reference; // or use blob value directly var _ = Blob.Value.Float3; + + Viewer.View(Blob.Reference); } } diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 78f0f35..36dccc2 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -315,7 +315,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!114 &1351734625 MonoBehaviour: m_ObjectHideFlags: 0 @@ -491,7 +491,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!114 &1386176992 MonoBehaviour: m_ObjectHideFlags: 0 @@ -642,7 +642,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!114 &1534642738 MonoBehaviour: m_ObjectHideFlags: 0 @@ -767,7 +767,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!114 &1645349337 MonoBehaviour: m_ObjectHideFlags: 0 @@ -865,6 +865,9 @@ MonoBehaviour: Blob: Builder: id: 0 + Viewer: + Viewer: + id: 1 references: version: 1 00000000: @@ -885,7 +888,6 @@ MonoBehaviour: - Enum - Arrays Builders: - - id: 1 - id: 2 - id: 3 - id: 4 @@ -896,48 +898,51 @@ MonoBehaviour: - id: 9 - id: 10 - id: 11 + - id: 12 00000001: + type: {class: , ns: , asm: } + 00000002: type: {class: Int32Builder, ns: Blob.Primitive, asm: Blob.Builder} data: Value: 1 - 00000002: + 00000003: type: {class: float3Builder, ns: Blob.Mathematics, asm: Blob.Builder} data: Value: x: 2 y: 3 z: 4 - 00000003: + 00000004: type: {class: StringBuilder, ns: Blob, asm: Blob.Builder} data: Value: 5 - 00000004: + 00000005: type: {class: double2ArrayBuilder, ns: Blob.Mathematics, asm: Blob.Builder} data: Value: - - id: 12 - id: 13 - 00000005: + - id: 14 + 00000006: type: {class: StringArrayBuilder, ns: Blob, asm: Blob.Builder} data: Value: - - id: 14 - id: 15 - id: 16 - 00000006: + - id: 17 + 00000007: type: {class: Int64PtrBuilder, ns: Blob.Primitive, asm: Blob.Builder} data: Value: - id: 17 - 00000007: + id: 18 + 00000008: type: {class: GuidBuilder, ns: , asm: Assembly-CSharp} data: Guid: c0a52acf-55e8-4fe9-86b9-f926d4d9755a - 00000008: + 00000009: type: {class: ObjectName, ns: , asm: Assembly-CSharp} data: GameObject: {fileID: 1805661907} - 00000009: + 0000000A: type: {class: AnimationCurveBlobBuilder, ns: Blob, asm: Blob.Builder} data: Value: @@ -964,13 +969,13 @@ MonoBehaviour: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 - 0000000A: + 0000000B: type: {class: DynamicIntEnumBuilder, ns: Blob, asm: Blob.Builder} data: EnumTypeName: Unity.Entities.ComponentType+AccessMode, Unity.Entities, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null Value: 0 - 0000000B: + 0000000C: type: {class: DynamicArrayBuilder, ns: Blob, asm: Blob.Builder} data: ArrayElementType: Unity.Entities.BlobArray`1[[Unity.Entities.BlobArray`1[[Unity.Entities.BlobPtr`1[[Unity.Entities.BlobString, @@ -979,36 +984,36 @@ MonoBehaviour: Unity.Entities, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], Unity.Entities, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null Value: - - id: 18 - 0000000C: + - id: 19 + 0000000D: type: {class: double2Builder, ns: Blob.Mathematics, asm: Blob.Builder} data: Value: x: 11 y: 22 - 0000000D: + 0000000E: type: {class: double2Builder, ns: Blob.Mathematics, asm: Blob.Builder} data: Value: x: 33 y: 44 - 0000000E: + 0000000F: type: {class: StringBuilder, ns: Blob, asm: Blob.Builder} data: Value: abc - 0000000F: + 00000010: type: {class: StringBuilder, ns: Blob, asm: Blob.Builder} data: Value: deF - 00000010: + 00000011: type: {class: StringBuilder, ns: Blob, asm: Blob.Builder} data: Value: FFFFF - 00000011: + 00000012: type: {class: Int64Builder, ns: Blob.Primitive, asm: Blob.Builder} data: Value: 1239 - 00000012: + 00000013: type: {class: DynamicArrayBuilder, ns: Blob, asm: Blob.Builder} data: ArrayElementType: Unity.Entities.BlobArray`1[[Unity.Entities.BlobPtr`1[[Unity.Entities.BlobString, @@ -1016,21 +1021,21 @@ MonoBehaviour: Unity.Entities, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], Unity.Entities, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null Value: - - id: 19 - 00000013: + - id: 20 + 00000014: type: {class: DynamicArrayBuilder, ns: Blob, asm: Blob.Builder} data: ArrayElementType: Unity.Entities.BlobPtr`1[[Unity.Entities.BlobString, Unity.Entities, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], Unity.Entities, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null Value: - - id: 20 - 00000014: + - id: 21 + 00000015: type: {class: StringPtrBuilder, ns: Blob, asm: Blob.Builder} data: Value: - id: 21 - 00000015: + id: 22 + 00000016: type: {class: StringBuilder, ns: Blob, asm: Blob.Builder} data: Value: fdfdaf @@ -1064,7 +1069,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!114 &2106881378 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/TestCustomBuilder.cs b/Assets/TestCustomBuilder.cs index 9950034..5e2c5c3 100644 --- a/Assets/TestCustomBuilder.cs +++ b/Assets/TestCustomBuilder.cs @@ -46,6 +46,17 @@ public override void Build(BlobBuilder builder, ref BlobString data) } } +[Serializable] +public class GuidViewer : Viewer +{ + public string Guid = System.Guid.NewGuid().ToString(); + + public override void View(ref Guid data) + { + Guid = data.ToString(); + } +} + [Serializable] public class ObjectName : Builder { diff --git a/Packages/blob-editor/Editor/Blob.Editor.asmdef b/Packages/blob-editor/Editor/Blob.Editor.asmdef index 7868656..8eae24e 100644 --- a/Packages/blob-editor/Editor/Blob.Editor.asmdef +++ b/Packages/blob-editor/Editor/Blob.Editor.asmdef @@ -3,13 +3,15 @@ "rootNamespace": "", "references": [ "GUID:2128cfde978da5c44bf90b8dda521ff6", - "GUID:734d92eba21c94caba915361bd5ac177" + "GUID:734d92eba21c94caba915361bd5ac177", + "GUID:6d84eb5386377416e93c122a00485b68", + "GUID:2bfccbc67fab343fe842fd447669165f" ], "includePlatforms": [ "Editor" ], "excludePlatforms": [], - "allowUnsafeCode": false, + "allowUnsafeCode": true, "overrideReferences": false, "precompiledReferences": [], "autoReferenced": false, diff --git a/Packages/blob-editor/Editor/Drawer.meta b/Packages/blob-editor/Editor/BuilderDrawer.meta similarity index 100% rename from Packages/blob-editor/Editor/Drawer.meta rename to Packages/blob-editor/Editor/BuilderDrawer.meta diff --git a/Packages/blob-editor/Editor/Drawer/ArrayBuilderDrawer.cs b/Packages/blob-editor/Editor/BuilderDrawer/ArrayBuilderDrawer.cs similarity index 100% rename from Packages/blob-editor/Editor/Drawer/ArrayBuilderDrawer.cs rename to Packages/blob-editor/Editor/BuilderDrawer/ArrayBuilderDrawer.cs diff --git a/Packages/blob-editor/Editor/Drawer/ArrayBuilderDrawer.cs.meta b/Packages/blob-editor/Editor/BuilderDrawer/ArrayBuilderDrawer.cs.meta similarity index 100% rename from Packages/blob-editor/Editor/Drawer/ArrayBuilderDrawer.cs.meta rename to Packages/blob-editor/Editor/BuilderDrawer/ArrayBuilderDrawer.cs.meta diff --git a/Packages/blob-editor/Editor/Drawer/BlobAssetDrawer.cs b/Packages/blob-editor/Editor/BuilderDrawer/BlobAssetDrawer.cs similarity index 100% rename from Packages/blob-editor/Editor/Drawer/BlobAssetDrawer.cs rename to Packages/blob-editor/Editor/BuilderDrawer/BlobAssetDrawer.cs diff --git a/Packages/blob-editor/Editor/Drawer/BlobAssetDrawer.cs.meta b/Packages/blob-editor/Editor/BuilderDrawer/BlobAssetDrawer.cs.meta similarity index 100% rename from Packages/blob-editor/Editor/Drawer/BlobAssetDrawer.cs.meta rename to Packages/blob-editor/Editor/BuilderDrawer/BlobAssetDrawer.cs.meta diff --git a/Packages/blob-editor/Editor/Drawer/BlobAssetV1Drawer.cs b/Packages/blob-editor/Editor/BuilderDrawer/BlobAssetV1Drawer.cs similarity index 100% rename from Packages/blob-editor/Editor/Drawer/BlobAssetV1Drawer.cs rename to Packages/blob-editor/Editor/BuilderDrawer/BlobAssetV1Drawer.cs diff --git a/Packages/blob-editor/Editor/Drawer/BlobAssetV1Drawer.cs.meta b/Packages/blob-editor/Editor/BuilderDrawer/BlobAssetV1Drawer.cs.meta similarity index 100% rename from Packages/blob-editor/Editor/Drawer/BlobAssetV1Drawer.cs.meta rename to Packages/blob-editor/Editor/BuilderDrawer/BlobAssetV1Drawer.cs.meta diff --git a/Packages/blob-editor/Editor/Drawer/BlobDataBuilderDrawer.cs b/Packages/blob-editor/Editor/BuilderDrawer/BlobDataBuilderDrawer.cs similarity index 100% rename from Packages/blob-editor/Editor/Drawer/BlobDataBuilderDrawer.cs rename to Packages/blob-editor/Editor/BuilderDrawer/BlobDataBuilderDrawer.cs diff --git a/Packages/blob-editor/Editor/Drawer/BlobDataBuilderDrawer.cs.meta b/Packages/blob-editor/Editor/BuilderDrawer/BlobDataBuilderDrawer.cs.meta similarity index 100% rename from Packages/blob-editor/Editor/Drawer/BlobDataBuilderDrawer.cs.meta rename to Packages/blob-editor/Editor/BuilderDrawer/BlobDataBuilderDrawer.cs.meta diff --git a/Packages/blob-editor/Editor/Drawer/DynamicBuilderFactoryRegister.cs b/Packages/blob-editor/Editor/BuilderDrawer/DynamicBuilderFactoryRegister.cs similarity index 100% rename from Packages/blob-editor/Editor/Drawer/DynamicBuilderFactoryRegister.cs rename to Packages/blob-editor/Editor/BuilderDrawer/DynamicBuilderFactoryRegister.cs diff --git a/Packages/blob-editor/Editor/Drawer/DynamicBuilderFactoryRegister.cs.meta b/Packages/blob-editor/Editor/BuilderDrawer/DynamicBuilderFactoryRegister.cs.meta similarity index 100% rename from Packages/blob-editor/Editor/Drawer/DynamicBuilderFactoryRegister.cs.meta rename to Packages/blob-editor/Editor/BuilderDrawer/DynamicBuilderFactoryRegister.cs.meta diff --git a/Packages/blob-editor/Editor/Drawer/EnumBuilderDrawer.cs b/Packages/blob-editor/Editor/BuilderDrawer/EnumBuilderDrawer.cs similarity index 100% rename from Packages/blob-editor/Editor/Drawer/EnumBuilderDrawer.cs rename to Packages/blob-editor/Editor/BuilderDrawer/EnumBuilderDrawer.cs diff --git a/Packages/blob-editor/Editor/Drawer/EnumBuilderDrawer.cs.meta b/Packages/blob-editor/Editor/BuilderDrawer/EnumBuilderDrawer.cs.meta similarity index 100% rename from Packages/blob-editor/Editor/Drawer/EnumBuilderDrawer.cs.meta rename to Packages/blob-editor/Editor/BuilderDrawer/EnumBuilderDrawer.cs.meta diff --git a/Packages/blob-editor/Editor/Drawer/PtrBuilderDrawer.cs b/Packages/blob-editor/Editor/BuilderDrawer/PtrBuilderDrawer.cs similarity index 100% rename from Packages/blob-editor/Editor/Drawer/PtrBuilderDrawer.cs rename to Packages/blob-editor/Editor/BuilderDrawer/PtrBuilderDrawer.cs diff --git a/Packages/blob-editor/Editor/Drawer/PtrBuilderDrawer.cs.meta b/Packages/blob-editor/Editor/BuilderDrawer/PtrBuilderDrawer.cs.meta similarity index 100% rename from Packages/blob-editor/Editor/Drawer/PtrBuilderDrawer.cs.meta rename to Packages/blob-editor/Editor/BuilderDrawer/PtrBuilderDrawer.cs.meta diff --git a/Packages/blob-editor/Editor/Extensions.cs b/Packages/blob-editor/Editor/Extensions.cs index 487ed2f..e0af44a 100644 --- a/Packages/blob-editor/Editor/Extensions.cs +++ b/Packages/blob-editor/Editor/Extensions.cs @@ -215,17 +215,17 @@ public static Type[] FindGenericArgumentsOf(this Type type, Type baseType) throw new ArgumentException(); } - public static SerializedProperty FindProperBuilderProperty(this SerializedProperty builder) + public static SerializedProperty FindProperProperty(this SerializedProperty self) { - var builderType = builder?.GetObject()?.GetType(); - var customDrawer = builderType == null ? null : builder.GetDrawerTypeForPropertyAndType(builderType); - if (builderType != null && customDrawer == null) + var type = self?.GetObject()?.GetType(); + var customDrawer = type == null ? null : self.GetDrawerTypeForPropertyAndType(type); + if (type != null && customDrawer == null) { - var children = builder.GetVisibleChildren().ToArray(); + var children = self.GetVisibleChildren().ToArray(); if (children.Length == 1) return children[0]; } - return builder; + return self; } public static IEnumerable Yield(this T value) @@ -264,21 +264,6 @@ BuilderFactory DynamicBuilder() return new BuilderFactory(factory.BuilderType, () => factory.Create(valueType)); } } - - public static string ToReadableFullName([NotNull] this Type type) - { - return type.IsGenericType ? Regex.Replace(type.ToString(), @"(\w+)`\d+\[(.*)\]", "$1<$2>") : type.ToString(); - } - - public static string ToReadableName([NotNull] this Type type) - { - if (!type.IsGenericType) return type.Name; - var name = type.Name.Remove(type.Name.LastIndexOf('`')); - name += "<"; - name += string.Join(",", type.GenericTypeArguments.Select(t => t.ToReadableName())); - name += ">"; - return name; - } } [Serializable] diff --git a/Packages/blob-editor/Editor/Drawer/UnboxSinglePropertyBuilderAttributeDrawer.cs b/Packages/blob-editor/Editor/MultiProperty/UnboxSinglePropertyAttributeDrawer.cs similarity index 59% rename from Packages/blob-editor/Editor/Drawer/UnboxSinglePropertyBuilderAttributeDrawer.cs rename to Packages/blob-editor/Editor/MultiProperty/UnboxSinglePropertyAttributeDrawer.cs index 8c6c9f6..8ef7f6b 100644 --- a/Packages/blob-editor/Editor/Drawer/UnboxSinglePropertyBuilderAttributeDrawer.cs +++ b/Packages/blob-editor/Editor/MultiProperty/UnboxSinglePropertyAttributeDrawer.cs @@ -3,18 +3,18 @@ namespace Blob.Editor { - [CustomMultiPropertyDrawer(typeof(UnboxSinglePropertyBuilderAttribute))] - public class UnboxSinglePropertyBuilderAttributeDrawer : BaseMultiPropertyDrawer + [CustomMultiPropertyDrawer(typeof(UnboxSinglePropertyAttribute))] + public class UnboxSinglePropertyAttributeDrawer : BaseMultiPropertyDrawer { public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { - property = property.FindProperBuilderProperty(); + property = property.FindProperProperty(); return base.GetPropertyHeight(property, label); } public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { - property = property.FindProperBuilderProperty(); + property = property.FindProperProperty(); base.OnGUI(position, property, label); } } diff --git a/Packages/blob-editor/Editor/Drawer/UnboxSinglePropertyBuilderAttributeDrawer.cs.meta b/Packages/blob-editor/Editor/MultiProperty/UnboxSinglePropertyAttributeDrawer.cs.meta similarity index 100% rename from Packages/blob-editor/Editor/Drawer/UnboxSinglePropertyBuilderAttributeDrawer.cs.meta rename to Packages/blob-editor/Editor/MultiProperty/UnboxSinglePropertyAttributeDrawer.cs.meta diff --git a/Packages/blob-editor/Editor/Drawer/UnityDrawPropertyAttributeDrawer.cs b/Packages/blob-editor/Editor/MultiProperty/UnityDrawPropertyAttributeDrawer.cs similarity index 100% rename from Packages/blob-editor/Editor/Drawer/UnityDrawPropertyAttributeDrawer.cs rename to Packages/blob-editor/Editor/MultiProperty/UnityDrawPropertyAttributeDrawer.cs diff --git a/Packages/blob-editor/Editor/Drawer/UnityDrawPropertyAttributeDrawer.cs.meta b/Packages/blob-editor/Editor/MultiProperty/UnityDrawPropertyAttributeDrawer.cs.meta similarity index 100% rename from Packages/blob-editor/Editor/Drawer/UnityDrawPropertyAttributeDrawer.cs.meta rename to Packages/blob-editor/Editor/MultiProperty/UnityDrawPropertyAttributeDrawer.cs.meta diff --git a/Packages/blob-editor/Editor/ViewerDrawer.meta b/Packages/blob-editor/Editor/ViewerDrawer.meta new file mode 100644 index 0000000..9ab32bf --- /dev/null +++ b/Packages/blob-editor/Editor/ViewerDrawer.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9902b3b7cf154c94930f411951a9b376 +timeCreated: 1629897352 \ No newline at end of file diff --git a/Packages/blob-editor/Editor/ViewerDrawer/BlobDataViewerDrawer.cs b/Packages/blob-editor/Editor/ViewerDrawer/BlobDataViewerDrawer.cs new file mode 100644 index 0000000..0cb9b76 --- /dev/null +++ b/Packages/blob-editor/Editor/ViewerDrawer/BlobDataViewerDrawer.cs @@ -0,0 +1,63 @@ +using System; +using System.Reflection; +using UnityEditor; +using UnityEngine; + +namespace Blob.Editor +{ + [CustomPropertyDrawer(typeof(DynamicBlobDataViewer))] + public class BlobDataViewerDrawer : PropertyDrawer + { + public Type GetBlobType(SerializedProperty property) + { + return Type.GetType(property.FindPropertyRelative(nameof(DynamicBlobDataViewer.TypeName)).stringValue); + } + + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) + { + var height = EditorGUIUtility.singleLineHeight; + if (property.isExpanded) + { + var viewers = FieldsViewer(property); + for (var i = 0; i < viewers.arraySize; i++) + { + var viewProperty = viewers.GetArrayElementAtIndex(i); + height += EditorGUI.GetPropertyHeight(viewProperty, includeChildren: true); + } + } + return height; + } + + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + property.serializedObject.Update(); + + var blobType = GetBlobType(property); + var blobFields = blobType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); + + position = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight); + EditorGUI.PropertyField(position, property, label); + + if (property.isExpanded) + { + var viewers = FieldsViewer(property); + EditorGUI.indentLevel++; + position = EditorGUI.IndentedRect(position); + var propertyHeight = position.height; + for (var i = 0; i < blobFields.Length; i++) + { + position = new Rect(position.x, position.y + propertyHeight, position.width, position.height); + var viewProperty = viewers.GetArrayElementAtIndex(i); + EditorGUI.PropertyField(position, viewProperty, new GUIContent(blobFields[i].Name), includeChildren: true); + propertyHeight = EditorGUI.GetPropertyHeight(viewProperty, includeChildren: true); + } + EditorGUI.indentLevel--; + } + } + + private SerializedProperty FieldsViewer(SerializedProperty property) + { + return property.FindPropertyRelative(nameof(DynamicBlobDataViewer.FieldsViewer)); + } + } +} \ No newline at end of file diff --git a/Packages/blob-editor/Editor/ViewerDrawer/BlobDataViewerDrawer.cs.meta b/Packages/blob-editor/Editor/ViewerDrawer/BlobDataViewerDrawer.cs.meta new file mode 100644 index 0000000..5ddea08 --- /dev/null +++ b/Packages/blob-editor/Editor/ViewerDrawer/BlobDataViewerDrawer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0a2e7c5328324733a8538f209f09ac6e +timeCreated: 1629898445 \ No newline at end of file diff --git a/Packages/blob-editor/Editor/ViewerDrawer/BlobViewerDrawer.cs b/Packages/blob-editor/Editor/ViewerDrawer/BlobViewerDrawer.cs new file mode 100644 index 0000000..262ae0b --- /dev/null +++ b/Packages/blob-editor/Editor/ViewerDrawer/BlobViewerDrawer.cs @@ -0,0 +1,27 @@ +using UnityEditor; +using UnityEngine; + +namespace Blob.Editor +{ + [CustomPropertyDrawer(typeof(BlobViewer))] + public class BlobViewerDrawer : PropertyDrawer + { + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) + { + property = property.FindPropertyRelative(nameof(BlobViewer.Viewer)); + return EditorGUI.GetPropertyHeight(property, label, true); + } + + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + property.serializedObject.Update(); + var typeName = property.FindPropertyRelative(nameof(BlobViewer.TypeName)).stringValue; + var writable = property.FindPropertyRelative(nameof(BlobViewer.Writable)).boolValue; + var enabled = GUI.enabled; + GUI.enabled = writable; + property = property.FindPropertyRelative(nameof(BlobViewer.Viewer)); + EditorGUI.PropertyField(position, property, new GUIContent($"{label.text} : {typeName}"), true); + GUI.enabled = enabled; + } + } +} \ No newline at end of file diff --git a/Packages/blob-editor/Editor/ViewerDrawer/BlobViewerDrawer.cs.meta b/Packages/blob-editor/Editor/ViewerDrawer/BlobViewerDrawer.cs.meta new file mode 100644 index 0000000..ea732f3 --- /dev/null +++ b/Packages/blob-editor/Editor/ViewerDrawer/BlobViewerDrawer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e41cc94c3ad54e578a8ab67beca58e45 +timeCreated: 1629897387 \ No newline at end of file diff --git a/Packages/blob-editor/Editor/ViewerDrawer/EnumViewerDrawer.cs b/Packages/blob-editor/Editor/ViewerDrawer/EnumViewerDrawer.cs new file mode 100644 index 0000000..4ec2136 --- /dev/null +++ b/Packages/blob-editor/Editor/ViewerDrawer/EnumViewerDrawer.cs @@ -0,0 +1,32 @@ +using System; +using System.Runtime.InteropServices; +using Unity.Collections.LowLevel.Unsafe; +using UnityEditor; +using UnityEngine; + +namespace Blob.Editor +{ + [CustomPropertyDrawer(typeof(DynamicEnumViewer))] + public class EnumViewerDrawer : PropertyDrawer + { + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) + { + return EditorGUIUtility.singleLineHeight; + } + + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + property.serializedObject.Update(); + var enumType = Type.GetType(property.FindPropertyRelative(nameof(DynamicEnumViewer.EnumType)).stringValue); + var dataPtr = new IntPtr(property.FindPropertyRelative(nameof(DynamicEnumViewer.Ptr)).longValue); + EditorGUI.EnumPopup(position, label, (Enum)Enum.ToObject(enumType, GetEnum(enumType, dataPtr))); + } + + Enum GetEnum(Type enumType, IntPtr dataPtr) + { + var underlingType = Enum.GetUnderlyingType(enumType); + var value = Marshal.PtrToStructure(dataPtr, underlingType); + return (Enum)Enum.ToObject(enumType, value); + } + } +} \ No newline at end of file diff --git a/Packages/blob-editor/Editor/ViewerDrawer/EnumViewerDrawer.cs.meta b/Packages/blob-editor/Editor/ViewerDrawer/EnumViewerDrawer.cs.meta new file mode 100644 index 0000000..fff7b33 --- /dev/null +++ b/Packages/blob-editor/Editor/ViewerDrawer/EnumViewerDrawer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 09b5700d264a4c2a806c1442158057e5 +timeCreated: 1629898993 \ No newline at end of file diff --git a/Packages/blob-editor/Runtime/AssemblyInfo.cs.meta b/Packages/blob-editor/Runtime/AssemblyInfo.cs.meta deleted file mode 100644 index 928e856..0000000 --- a/Packages/blob-editor/Runtime/AssemblyInfo.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: a765b761b5b24277bd1c2ffc1e023dac -timeCreated: 1629274662 \ No newline at end of file diff --git a/Packages/blob-editor/Runtime/Attribute/UnboxSinglePropertyAttribute.cs b/Packages/blob-editor/Runtime/Attribute/UnboxSinglePropertyAttribute.cs new file mode 100644 index 0000000..0edc014 --- /dev/null +++ b/Packages/blob-editor/Runtime/Attribute/UnboxSinglePropertyAttribute.cs @@ -0,0 +1,4 @@ +namespace Blob +{ + public class UnboxSinglePropertyAttribute : MultiPropertyAttribute {} +} \ No newline at end of file diff --git a/Packages/blob-editor/Runtime/Attribute/UnboxSinglePropertyBuilderAttribute.cs.meta b/Packages/blob-editor/Runtime/Attribute/UnboxSinglePropertyAttribute.cs.meta similarity index 100% rename from Packages/blob-editor/Runtime/Attribute/UnboxSinglePropertyBuilderAttribute.cs.meta rename to Packages/blob-editor/Runtime/Attribute/UnboxSinglePropertyAttribute.cs.meta diff --git a/Packages/blob-editor/Runtime/Attribute/UnboxSinglePropertyBuilderAttribute.cs b/Packages/blob-editor/Runtime/Attribute/UnboxSinglePropertyBuilderAttribute.cs deleted file mode 100644 index fa3f50b..0000000 --- a/Packages/blob-editor/Runtime/Attribute/UnboxSinglePropertyBuilderAttribute.cs +++ /dev/null @@ -1,7 +0,0 @@ -using JetBrains.Annotations; - -namespace Blob -{ - [BaseTypeRequired(typeof(IBuilder))] - public class UnboxSinglePropertyBuilderAttribute : MultiPropertyAttribute {} -} \ No newline at end of file diff --git a/Packages/blob-editor/Runtime/BlobEditor.Runtime.asmdef b/Packages/blob-editor/Runtime/BlobEditor.Runtime.asmdef new file mode 100644 index 0000000..c5d178a --- /dev/null +++ b/Packages/blob-editor/Runtime/BlobEditor.Runtime.asmdef @@ -0,0 +1,16 @@ +{ + "name": "BlobEditor", + "rootNamespace": "", + "references": [ + "GUID:734d92eba21c94caba915361bd5ac177" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": true, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Packages/blob-editor/Runtime/BlobEditor.Runtime.asmdef.meta b/Packages/blob-editor/Runtime/BlobEditor.Runtime.asmdef.meta new file mode 100644 index 0000000..d4b7247 --- /dev/null +++ b/Packages/blob-editor/Runtime/BlobEditor.Runtime.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 6d84eb5386377416e93c122a00485b68 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/blob-editor/Runtime/AssemblyInfo.cs b/Packages/blob-editor/Runtime/Builder/AssemblyInfo.cs similarity index 100% rename from Packages/blob-editor/Runtime/AssemblyInfo.cs rename to Packages/blob-editor/Runtime/Builder/AssemblyInfo.cs diff --git a/Packages/blob-editor/Runtime/Builder/AssemblyInfo.cs.meta b/Packages/blob-editor/Runtime/Builder/AssemblyInfo.cs.meta new file mode 100644 index 0000000..52700a1 --- /dev/null +++ b/Packages/blob-editor/Runtime/Builder/AssemblyInfo.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a765b761b5b24277bd1c2ffc1e023dac +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/blob-editor/Runtime/Blob.Builder.asmdef b/Packages/blob-editor/Runtime/Builder/Blob.Builder.asmdef similarity index 89% rename from Packages/blob-editor/Runtime/Blob.Builder.asmdef rename to Packages/blob-editor/Runtime/Builder/Blob.Builder.asmdef index 566e544..95a0a32 100644 --- a/Packages/blob-editor/Runtime/Blob.Builder.asmdef +++ b/Packages/blob-editor/Runtime/Builder/Blob.Builder.asmdef @@ -5,7 +5,8 @@ "GUID:734d92eba21c94caba915361bd5ac177", "GUID:d8b63aba1907145bea998dd612889d6b", "GUID:39174d49d2befe84d9c54bf8b8d32755", - "GUID:cf3547b97f3ec664f9eca740d393c07c" + "GUID:cf3547b97f3ec664f9eca740d393c07c", + "GUID:6d84eb5386377416e93c122a00485b68" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Packages/blob-editor/Runtime/Blob.Builder.asmdef.meta b/Packages/blob-editor/Runtime/Builder/Blob.Builder.asmdef.meta similarity index 100% rename from Packages/blob-editor/Runtime/Blob.Builder.asmdef.meta rename to Packages/blob-editor/Runtime/Builder/Blob.Builder.asmdef.meta diff --git a/Packages/blob-editor/Runtime/BlobAsset.cs b/Packages/blob-editor/Runtime/Builder/BlobAsset.cs similarity index 89% rename from Packages/blob-editor/Runtime/BlobAsset.cs rename to Packages/blob-editor/Runtime/Builder/BlobAsset.cs index 0613716..3ebc2d6 100644 --- a/Packages/blob-editor/Runtime/BlobAsset.cs +++ b/Packages/blob-editor/Runtime/Builder/BlobAsset.cs @@ -9,7 +9,7 @@ namespace Blob [Serializable] public class BlobAsset where T : unmanaged { - [SerializeReference, UnboxSinglePropertyBuilder, UnityDrawProperty] internal IBuilder Builder; + [SerializeReference, UnboxSingleProperty, UnityDrawProperty] internal IBuilder Builder; BlobAssetReference _blobAssetReference; diff --git a/Packages/blob-editor/Runtime/BlobAsset.cs.meta b/Packages/blob-editor/Runtime/Builder/BlobAsset.cs.meta similarity index 100% rename from Packages/blob-editor/Runtime/BlobAsset.cs.meta rename to Packages/blob-editor/Runtime/Builder/BlobAsset.cs.meta diff --git a/Packages/blob-editor/Runtime/BlobAssetV1.cs b/Packages/blob-editor/Runtime/Builder/BlobAssetV1.cs similarity index 100% rename from Packages/blob-editor/Runtime/BlobAssetV1.cs rename to Packages/blob-editor/Runtime/Builder/BlobAssetV1.cs diff --git a/Packages/blob-editor/Runtime/BlobAssetV1.cs.meta b/Packages/blob-editor/Runtime/Builder/BlobAssetV1.cs.meta similarity index 100% rename from Packages/blob-editor/Runtime/BlobAssetV1.cs.meta rename to Packages/blob-editor/Runtime/Builder/BlobAssetV1.cs.meta diff --git a/Packages/blob-editor/Runtime/Builder/Builders.cs b/Packages/blob-editor/Runtime/Builder/Builders.cs index 0331af5..d3b2b06 100644 --- a/Packages/blob-editor/Runtime/Builder/Builders.cs +++ b/Packages/blob-editor/Runtime/Builder/Builders.cs @@ -48,7 +48,7 @@ public override void Build(BlobBuilder builder, ref T data) public class BlobDataBuilder : Builder where T : unmanaged { [HideInInspector] public string[] FieldNames; - [SerializeReference, UnboxSinglePropertyBuilder, UnityDrawProperty] public IBuilder[] Builders; + [SerializeReference, UnboxSingleProperty, UnityDrawProperty] public IBuilder[] Builders; public override unsafe void Build(BlobBuilder builder, ref T data) { @@ -65,7 +65,7 @@ public override unsafe void Build(BlobBuilder builder, ref T data) [Serializable] public class ArrayBuilder : Builder> where T : unmanaged { - [SerializeReference, UnboxSinglePropertyBuilder, UnityDrawProperty] public IBuilder[] Value; + [SerializeReference, UnboxSingleProperty, UnityDrawProperty] public IBuilder[] Value; public override void Build(BlobBuilder builder, ref BlobArray data) { @@ -91,7 +91,7 @@ public override void Build(BlobBuilder builder, ref BlobString data) [Serializable] public class PtrBuilder : Builder> where T : unmanaged { - [SerializeReference, UnboxSinglePropertyBuilder, UnityDrawProperty] public IBuilder Value; + [SerializeReference, UnboxSingleProperty, UnityDrawProperty] public IBuilder Value; public override unsafe void Build(BlobBuilder builder, ref BlobPtr data) { diff --git a/Packages/blob-editor/Runtime/Attribute/CustomBuilderAttribute.cs b/Packages/blob-editor/Runtime/Builder/CustomBuilderAttribute.cs similarity index 100% rename from Packages/blob-editor/Runtime/Attribute/CustomBuilderAttribute.cs rename to Packages/blob-editor/Runtime/Builder/CustomBuilderAttribute.cs diff --git a/Packages/blob-editor/Runtime/Attribute/CustomBuilderAttribute.cs.meta b/Packages/blob-editor/Runtime/Builder/CustomBuilderAttribute.cs.meta similarity index 100% rename from Packages/blob-editor/Runtime/Attribute/CustomBuilderAttribute.cs.meta rename to Packages/blob-editor/Runtime/Builder/CustomBuilderAttribute.cs.meta diff --git a/Packages/blob-editor/Runtime/Attribute/DefaultBuilderAttribute.cs b/Packages/blob-editor/Runtime/Builder/DefaultBuilderAttribute.cs similarity index 100% rename from Packages/blob-editor/Runtime/Attribute/DefaultBuilderAttribute.cs rename to Packages/blob-editor/Runtime/Builder/DefaultBuilderAttribute.cs diff --git a/Packages/blob-editor/Runtime/Attribute/DefaultBuilderAttribute.cs.meta b/Packages/blob-editor/Runtime/Builder/DefaultBuilderAttribute.cs.meta similarity index 100% rename from Packages/blob-editor/Runtime/Attribute/DefaultBuilderAttribute.cs.meta rename to Packages/blob-editor/Runtime/Builder/DefaultBuilderAttribute.cs.meta diff --git a/Packages/blob-editor/Runtime/Builder/DynamicBuilders.cs b/Packages/blob-editor/Runtime/Builder/DynamicBuilders.cs index eecceb3..03cf3fb 100644 --- a/Packages/blob-editor/Runtime/Builder/DynamicBuilders.cs +++ b/Packages/blob-editor/Runtime/Builder/DynamicBuilders.cs @@ -92,7 +92,7 @@ public class DynamicBlobDataBuilder : IBuilder { public string BlobDataType; public string[] FieldNames; - [SerializeReference, UnboxSinglePropertyBuilder, UnityDrawProperty] public IBuilder[] Builders; + [SerializeReference, UnboxSingleProperty, UnityDrawProperty] public IBuilder[] Builders; public void Build(BlobBuilder builder, IntPtr dataPtr) { @@ -116,7 +116,7 @@ public class Factory : DynamicBuilderFactory public class DynamicArrayBuilder : IBuilder { public string ArrayElementType; - [SerializeReference, UnboxSinglePropertyBuilder, UnityDrawProperty] public IBuilder[] Value; + [SerializeReference, UnboxSingleProperty, UnityDrawProperty] public IBuilder[] Value; public void Build(BlobBuilder builder, IntPtr dataPtr) { @@ -137,7 +137,7 @@ public class Factory : DynamicBuilderFactory public class DynamicPtrBuilder : IBuilder { public string DataType; - [SerializeReference, UnboxSinglePropertyBuilder, UnityDrawProperty] public IBuilder Value; + [SerializeReference, UnboxSingleProperty, UnityDrawProperty] public IBuilder Value; public void Build(BlobBuilder builder, IntPtr dataPtr) { diff --git a/Packages/blob-editor/Runtime/Builder/MathematicsBuilder.tt b/Packages/blob-editor/Runtime/Builder/MathematicsBuilder.tt index 0dae21c..0e915da 100644 --- a/Packages/blob-editor/Runtime/Builder/MathematicsBuilder.tt +++ b/Packages/blob-editor/Runtime/Builder/MathematicsBuilder.tt @@ -1,11 +1,8 @@ <#@ template language="C#" #> <#@ output extension=".cs" #> -<#@ assembly name="C:/Program Files/Unity/Hub/Editor/2020.3.14f1/Editor/Data/Managed/UnityEngine/UnityEngine.CoreModule.dll" #> -<#@ assembly name="$(SolutionDir)/Library/ScriptAssemblies/Unity.Mathematics.dll" #> -<#@ import namespace="Unity.Mathematics" #> - <#@ include file="GenerateBuilders.ttinclude" #> +<#@ include file="../Mathematics.ttinclude" #> #if ENABLE_UNITY_MATHEMATICS @@ -13,24 +10,9 @@ namespace Blob.Mathematics { <# - foreach (var type in typeof(math).Assembly.GetTypes()) - { - if (type.IsPublic && IsUnmanaged(type)) - { - GenerateBuilders(type); - } - } + foreach (var type in Mathematics) GenerateBuilders(type); #> } -#endif - -<#+ - class U where T : unmanaged { } - public bool IsUnmanaged(Type t) - { - try { typeof(U<>).MakeGenericType(t); return true; } - catch (Exception){ return false; } - } -#> \ No newline at end of file +#endif \ No newline at end of file diff --git a/Packages/blob-editor/Runtime/Builder/PrimitiveBuilder.tt b/Packages/blob-editor/Runtime/Builder/PrimitiveBuilder.tt index 440b2aa..a686247 100644 --- a/Packages/blob-editor/Runtime/Builder/PrimitiveBuilder.tt +++ b/Packages/blob-editor/Runtime/Builder/PrimitiveBuilder.tt @@ -2,18 +2,13 @@ <#@ output extension=".cs" #> <#@ include file="GenerateBuilders.ttinclude" #> +<#@ include file="../Primitives.ttinclude" #> namespace Blob.Primitive { <# - foreach (var type in typeof(int).Assembly.GetTypes()) - { - if (type.IsPrimitive) - { - GenerateBuilders(type); - } - } + foreach (var type in Primitives) GenerateBuilders(type); #> } \ No newline at end of file diff --git a/Packages/blob-editor/Runtime/Builder/DynamicBlobBuilderArray.cs b/Packages/blob-editor/Runtime/DynamicBlobBuilderArray.cs similarity index 100% rename from Packages/blob-editor/Runtime/Builder/DynamicBlobBuilderArray.cs rename to Packages/blob-editor/Runtime/DynamicBlobBuilderArray.cs diff --git a/Packages/blob-editor/Runtime/Builder/DynamicBlobBuilderArray.cs.meta b/Packages/blob-editor/Runtime/DynamicBlobBuilderArray.cs.meta similarity index 100% rename from Packages/blob-editor/Runtime/Builder/DynamicBlobBuilderArray.cs.meta rename to Packages/blob-editor/Runtime/DynamicBlobBuilderArray.cs.meta diff --git a/Packages/blob-editor/Runtime/Mathematics.ttinclude b/Packages/blob-editor/Runtime/Mathematics.ttinclude new file mode 100644 index 0000000..4e324f7 --- /dev/null +++ b/Packages/blob-editor/Runtime/Mathematics.ttinclude @@ -0,0 +1,15 @@ +<#@ assembly name="/Applications/Unity/Hub/Editor/2020.3.16f1/Unity.app/Contents/Managed/UnityEngine/UnityEngine.CoreModule.dll" #> +<#@ assembly name="$(SolutionDir)/Library/ScriptAssemblies/Unity.Mathematics.dll" #> +<#@ import namespace="Unity.Mathematics" #> +<#@ import namespace="System.Linq" #> + +<#+ + Type[] Mathematics = typeof(math).Assembly.GetTypes().Where(type => type.IsPublic && IsUnmanaged(type)).ToArray(); + + class U where T : unmanaged { } + public static bool IsUnmanaged(Type t) + { + try { typeof(U<>).MakeGenericType(t); return true; } + catch (Exception){ return false; } + } +#> diff --git a/Packages/blob-editor/Runtime/Mathematics.ttinclude.meta b/Packages/blob-editor/Runtime/Mathematics.ttinclude.meta new file mode 100644 index 0000000..b10bce0 --- /dev/null +++ b/Packages/blob-editor/Runtime/Mathematics.ttinclude.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 91cd44f87175b400e9aef63098037eaf +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/blob-editor/Runtime/Primitives.ttinclude b/Packages/blob-editor/Runtime/Primitives.ttinclude new file mode 100644 index 0000000..5783aee --- /dev/null +++ b/Packages/blob-editor/Runtime/Primitives.ttinclude @@ -0,0 +1,5 @@ +<#@ import namespace="System.Linq" #> + +<#+ + Type[] Primitives = typeof(int).Assembly.GetTypes().Where(type => type.IsPrimitive).ToArray(); +#> diff --git a/Packages/blob-editor/Runtime/Primitives.ttinclude.meta b/Packages/blob-editor/Runtime/Primitives.ttinclude.meta new file mode 100644 index 0000000..2b49a89 --- /dev/null +++ b/Packages/blob-editor/Runtime/Primitives.ttinclude.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 41575a89a40834e4286a3cc37c431b0c +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/blob-editor/Runtime/Builder/Utility.cs b/Packages/blob-editor/Runtime/Utility.cs similarity index 74% rename from Packages/blob-editor/Runtime/Builder/Utility.cs rename to Packages/blob-editor/Runtime/Utility.cs index 102cf3e..fdeb0ee 100644 --- a/Packages/blob-editor/Runtime/Builder/Utility.cs +++ b/Packages/blob-editor/Runtime/Utility.cs @@ -1,5 +1,8 @@ using System; +using System.Linq; using System.Reflection; +using System.Text.RegularExpressions; +using JetBrains.Annotations; using Unity.Collections.LowLevel.Unsafe; using Unity.Entities; @@ -35,5 +38,20 @@ private static unsafe IntPtr AllocateDynamicPtr(BlobBuilder builder, IntPtr d ref var blobPtr = ref builder.Allocate(ref data); return new IntPtr(UnsafeUtility.AddressOf(ref blobPtr)); } + + public static string ToReadableFullName([NotNull] this Type type) + { + return type.IsGenericType ? Regex.Replace(type.ToString(), @"(\w+)`\d+\[(.*)\]", "$1<$2>") : type.ToString(); + } + + public static string ToReadableName([NotNull] this Type type) + { + if (!type.IsGenericType) return type.Name; + var name = type.Name.Remove(type.Name.LastIndexOf('`')); + name += "<"; + name += string.Join(",", type.GenericTypeArguments.Select(t => t.ToReadableName())); + name += ">"; + return name; + } } } \ No newline at end of file diff --git a/Packages/blob-editor/Runtime/Builder/Utility.cs.meta b/Packages/blob-editor/Runtime/Utility.cs.meta similarity index 100% rename from Packages/blob-editor/Runtime/Builder/Utility.cs.meta rename to Packages/blob-editor/Runtime/Utility.cs.meta diff --git a/Packages/blob-editor/Runtime/Viewer.meta b/Packages/blob-editor/Runtime/Viewer.meta new file mode 100644 index 0000000..78c78f2 --- /dev/null +++ b/Packages/blob-editor/Runtime/Viewer.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9d382d409db8c44b4ab31f85284b7ba1 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/blob-editor/Runtime/Viewer/AssemblyInfo.cs b/Packages/blob-editor/Runtime/Viewer/AssemblyInfo.cs new file mode 100644 index 0000000..8c58fa2 --- /dev/null +++ b/Packages/blob-editor/Runtime/Viewer/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Blob.Editor")] \ No newline at end of file diff --git a/Packages/blob-editor/Runtime/Viewer/AssemblyInfo.cs.meta b/Packages/blob-editor/Runtime/Viewer/AssemblyInfo.cs.meta new file mode 100644 index 0000000..4754509 --- /dev/null +++ b/Packages/blob-editor/Runtime/Viewer/AssemblyInfo.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: fe325be404d542a08eea83d73f1b90f8 +timeCreated: 1629897462 \ No newline at end of file diff --git a/Packages/blob-editor/Runtime/Viewer/Blob.Viewer.asmdef b/Packages/blob-editor/Runtime/Viewer/Blob.Viewer.asmdef new file mode 100644 index 0000000..4b49ad3 --- /dev/null +++ b/Packages/blob-editor/Runtime/Viewer/Blob.Viewer.asmdef @@ -0,0 +1,24 @@ +{ + "name": "Blob.Viewer", + "rootNamespace": "", + "references": [ + "GUID:6d84eb5386377416e93c122a00485b68", + "GUID:734d92eba21c94caba915361bd5ac177", + "GUID:d8b63aba1907145bea998dd612889d6b" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": true, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [ + { + "name": "com.unity.mathematics", + "expression": "1.0.1", + "define": "ENABLE_UNITY_MATHEMATICS" + } + ], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Packages/blob-editor/Runtime/Viewer/Blob.Viewer.asmdef.meta b/Packages/blob-editor/Runtime/Viewer/Blob.Viewer.asmdef.meta new file mode 100644 index 0000000..5c9ba9d --- /dev/null +++ b/Packages/blob-editor/Runtime/Viewer/Blob.Viewer.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 2bfccbc67fab343fe842fd447669165f +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/blob-editor/Runtime/Viewer/BlobViewer.cs b/Packages/blob-editor/Runtime/Viewer/BlobViewer.cs new file mode 100644 index 0000000..7299003 --- /dev/null +++ b/Packages/blob-editor/Runtime/Viewer/BlobViewer.cs @@ -0,0 +1,38 @@ +using System; +using Unity.Entities; +using UnityEngine; + +namespace Blob +{ + [Serializable] + public class BlobViewer + { + [SerializeField] public bool Writable = false; + [SerializeField] internal string TypeName = "(Empty)"; + [SerializeReference, UnboxSingleProperty, UnityDrawProperty] internal IViewer Viewer; + + public unsafe void View(T* dataPtr) where T : unmanaged => UnsafeView(new IntPtr(dataPtr), typeof(T)); + + public void UnsafeView(IntPtr dataPtr, Type type) + { +#if UNITY_EDITOR + TypeName = type.ToReadableName(); + var viewerType = type.FindViewerType(); + if (Viewer == null || Viewer.GetType() != viewerType) + Viewer = (IViewer) Activator.CreateInstance(viewerType); + Viewer.View(dataPtr, type); +#endif + } + } + + public static class BlobViewerExtension + { + public static unsafe void View(this BlobViewer viewer, BlobAssetReference blobAssetReference) where T : unmanaged + { + fixed (T* ptr = &blobAssetReference.Value) + { + viewer.View(ptr); + } + } + } +} \ No newline at end of file diff --git a/Packages/blob-editor/Runtime/Viewer/BlobViewer.cs.meta b/Packages/blob-editor/Runtime/Viewer/BlobViewer.cs.meta new file mode 100644 index 0000000..5bf7790 --- /dev/null +++ b/Packages/blob-editor/Runtime/Viewer/BlobViewer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d0a0f9c6014b84136b7deb063425ed14 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/blob-editor/Runtime/Viewer/GenerateViewers.cs b/Packages/blob-editor/Runtime/Viewer/GenerateViewers.cs new file mode 100644 index 0000000..e98c50e --- /dev/null +++ b/Packages/blob-editor/Runtime/Viewer/GenerateViewers.cs @@ -0,0 +1,95 @@ + + + + + +namespace Blob +{ + + public class BooleanViewer : Blob.PlainDataViewer {} + public class ByteViewer : Blob.PlainDataViewer {} + public class CharViewer : Blob.PlainDataViewer {} + public class DoubleViewer : Blob.PlainDataViewer {} + public class Int16Viewer : Blob.PlainDataViewer {} + public class Int32Viewer : Blob.PlainDataViewer {} + public class Int64Viewer : Blob.PlainDataViewer {} + public class SByteViewer : Blob.PlainDataViewer {} + public class SingleViewer : Blob.PlainDataViewer {} + public class UInt16Viewer : Blob.PlainDataViewer {} + public class UInt32Viewer : Blob.PlainDataViewer {} + public class UInt64Viewer : Blob.PlainDataViewer {} + public class IntPtrViewer : Blob.PlainDataViewer {} + public class UIntPtrViewer : Blob.PlainDataViewer {} + +#if ENABLE_UNITY_MATHEMATICS + public class bool2Viewer : Blob.PlainDataViewer {} + public class bool2x2Viewer : Blob.PlainDataViewer {} + public class bool2x3Viewer : Blob.PlainDataViewer {} + public class bool2x4Viewer : Blob.PlainDataViewer {} + public class bool3Viewer : Blob.PlainDataViewer {} + public class bool3x2Viewer : Blob.PlainDataViewer {} + public class bool3x3Viewer : Blob.PlainDataViewer {} + public class bool3x4Viewer : Blob.PlainDataViewer {} + public class bool4Viewer : Blob.PlainDataViewer {} + public class bool4x2Viewer : Blob.PlainDataViewer {} + public class bool4x3Viewer : Blob.PlainDataViewer {} + public class bool4x4Viewer : Blob.PlainDataViewer {} + public class double2Viewer : Blob.PlainDataViewer {} + public class double2x2Viewer : Blob.PlainDataViewer {} + public class double2x3Viewer : Blob.PlainDataViewer {} + public class double2x4Viewer : Blob.PlainDataViewer {} + public class double3Viewer : Blob.PlainDataViewer {} + public class double3x2Viewer : Blob.PlainDataViewer {} + public class double3x3Viewer : Blob.PlainDataViewer {} + public class double3x4Viewer : Blob.PlainDataViewer {} + public class double4Viewer : Blob.PlainDataViewer {} + public class double4x2Viewer : Blob.PlainDataViewer {} + public class double4x3Viewer : Blob.PlainDataViewer {} + public class double4x4Viewer : Blob.PlainDataViewer {} + public class float2Viewer : Blob.PlainDataViewer {} + public class float2x2Viewer : Blob.PlainDataViewer {} + public class float2x3Viewer : Blob.PlainDataViewer {} + public class float2x4Viewer : Blob.PlainDataViewer {} + public class float3Viewer : Blob.PlainDataViewer {} + public class float3x2Viewer : Blob.PlainDataViewer {} + public class float3x3Viewer : Blob.PlainDataViewer {} + public class float3x4Viewer : Blob.PlainDataViewer {} + public class float4Viewer : Blob.PlainDataViewer {} + public class float4x2Viewer : Blob.PlainDataViewer {} + public class float4x3Viewer : Blob.PlainDataViewer {} + public class float4x4Viewer : Blob.PlainDataViewer {} + public class halfViewer : Blob.PlainDataViewer {} + public class half2Viewer : Blob.PlainDataViewer {} + public class half3Viewer : Blob.PlainDataViewer {} + public class half4Viewer : Blob.PlainDataViewer {} + public class int2Viewer : Blob.PlainDataViewer {} + public class int2x2Viewer : Blob.PlainDataViewer {} + public class int2x3Viewer : Blob.PlainDataViewer {} + public class int2x4Viewer : Blob.PlainDataViewer {} + public class int3Viewer : Blob.PlainDataViewer {} + public class int3x2Viewer : Blob.PlainDataViewer {} + public class int3x3Viewer : Blob.PlainDataViewer {} + public class int3x4Viewer : Blob.PlainDataViewer {} + public class int4Viewer : Blob.PlainDataViewer {} + public class int4x2Viewer : Blob.PlainDataViewer {} + public class int4x3Viewer : Blob.PlainDataViewer {} + public class int4x4Viewer : Blob.PlainDataViewer {} + public class quaternionViewer : Blob.PlainDataViewer {} + public class RandomViewer : Blob.PlainDataViewer {} + public class RigidTransformViewer : Blob.PlainDataViewer {} + public class uint2Viewer : Blob.PlainDataViewer {} + public class uint2x2Viewer : Blob.PlainDataViewer {} + public class uint2x3Viewer : Blob.PlainDataViewer {} + public class uint2x4Viewer : Blob.PlainDataViewer {} + public class uint3Viewer : Blob.PlainDataViewer {} + public class uint3x2Viewer : Blob.PlainDataViewer {} + public class uint3x3Viewer : Blob.PlainDataViewer {} + public class uint3x4Viewer : Blob.PlainDataViewer {} + public class uint4Viewer : Blob.PlainDataViewer {} + public class uint4x2Viewer : Blob.PlainDataViewer {} + public class uint4x3Viewer : Blob.PlainDataViewer {} + public class uint4x4Viewer : Blob.PlainDataViewer {} +#endif + +} + diff --git a/Packages/blob-editor/Runtime/Viewer/GenerateViewers.cs.meta b/Packages/blob-editor/Runtime/Viewer/GenerateViewers.cs.meta new file mode 100644 index 0000000..6a337b1 --- /dev/null +++ b/Packages/blob-editor/Runtime/Viewer/GenerateViewers.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9a903b2049b14ad09674a0a57ced3fe4 +timeCreated: 1629896593 \ No newline at end of file diff --git a/Packages/blob-editor/Runtime/Viewer/GenerateViewers.tt b/Packages/blob-editor/Runtime/Viewer/GenerateViewers.tt new file mode 100644 index 0000000..02f890d --- /dev/null +++ b/Packages/blob-editor/Runtime/Viewer/GenerateViewers.tt @@ -0,0 +1,30 @@ +<#@ template language="C#" #> +<#@ output extension=".cs" #> + +<#@ include file="../Primitives.ttinclude" #> +<#@ include file="../Mathematics.ttinclude" #><#@ assembly name="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" #><#@ assembly name="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" #> +<#@ import namespace="System.Linq" #> + +namespace Blob +{ + +<# + foreach (var type in Primitives) GenerateViewers(type); +#> + +#if ENABLE_UNITY_MATHEMATICS +<# + foreach (var type in Mathematics) GenerateViewers(type); +#> +#endif + +} + +<#+ + void GenerateViewers(Type type) + { +#> + public class <#= type.Name #>Viewer : Blob.PlainDataViewer<<#= type #>> {} +<#+ + } +#> diff --git a/Packages/blob-editor/Runtime/Viewer/GenerateViewers.tt.meta b/Packages/blob-editor/Runtime/Viewer/GenerateViewers.tt.meta new file mode 100644 index 0000000..80979c6 --- /dev/null +++ b/Packages/blob-editor/Runtime/Viewer/GenerateViewers.tt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 17843e3ae38a74c7c9a71d00b63ee19c +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/blob-editor/Runtime/Viewer/Viewers.cs b/Packages/blob-editor/Runtime/Viewer/Viewers.cs new file mode 100644 index 0000000..40021fe --- /dev/null +++ b/Packages/blob-editor/Runtime/Viewer/Viewers.cs @@ -0,0 +1,139 @@ +using System; +using System.Linq; +using System.Reflection; +using Unity.Assertions; +using Unity.Collections.LowLevel.Unsafe; +using Unity.Entities; +using UnityEditor; +using UnityEngine; + +namespace Blob +{ + public interface IViewer + { + void View(IntPtr dataPtr, Type type); + } + + public abstract class Viewer : IViewer where T : unmanaged + { + public unsafe void View(IntPtr dataPtr, Type type) + { + Assert.AreEqual(type, typeof(T)); + View(ref UnsafeUtility.AsRef(dataPtr.ToPointer())); + } + + public abstract void View(ref T data); + } + + [Serializable] + public class PlainDataViewer : Viewer where T : unmanaged + { + public T Value; + public override void View(ref T data) => Value = data; + } + + [Serializable] + public class StringViewer : Viewer + { + public string Value; + public override void View(ref BlobString data) => Value = data.ToString(); + } + + [Serializable] + public class DynamicArrayViewer : IViewer + { + [SerializeReference, UnboxSingleProperty, UnityDrawProperty] public IViewer[] Elements; + + public unsafe void View(IntPtr dataPtr, Type type) + { + Assert.IsTrue(type.IsGenericType && type.GetGenericTypeDefinition() == typeof(BlobArray<>)); + ref var offsetPtr = ref UnsafeUtility.AsRef(dataPtr.ToPointer()); + ref var length = ref UnsafeUtility.AsRef((dataPtr + sizeof(int)).ToPointer()); + var elementType = type.GenericTypeArguments[0]; + Array.Resize(ref Elements, length); + + var viewerType = elementType.FindViewerType(); + var elementSize = UnsafeUtility.SizeOf(elementType); + var arrayPtr = dataPtr + offsetPtr; + + for (var i = 0; i < length; i++) + { + if (Elements[i] == null || Elements[i].GetType() != viewerType) + Elements[i] = (IViewer) Activator.CreateInstance(viewerType); + var elementPtr = arrayPtr + elementSize * i; + Elements[i].View(elementPtr, elementType); + } + } + } + + [Serializable] + public class DynamicBlobDataViewer : IViewer + { + public string TypeName; + [SerializeReference, UnboxSingleProperty, UnityDrawProperty] public IViewer[] FieldsViewer; + + public void View(IntPtr dataPtr, Type type) + { + Assert.IsTrue(!type.IsPrimitive && !type.IsEnum && type.IsValueType); + TypeName = type.AssemblyQualifiedName; + var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); + Array.Resize(ref FieldsViewer, fields.Length); + for (var i = 0; i < fields.Length; i++) + { + var field = fields[i]; + var viewerType = field.FieldType.FindViewerType(); + if (FieldsViewer[i] == null || FieldsViewer[i].GetType() != viewerType) + FieldsViewer[i] = (IViewer) Activator.CreateInstance(viewerType); + var fieldOffset = UnsafeUtility.GetFieldOffset(field); + FieldsViewer[i].View(dataPtr + fieldOffset, field.FieldType); + } + } + } + + [Serializable] + public class DynamicPtrViewer : IViewer + { + [SerializeReference, UnboxSingleProperty, UnityDrawProperty] public IViewer Value; + + public unsafe void View(IntPtr dataPtr, Type type) + { + Assert.IsTrue(type.IsGenericType && type.GetGenericTypeDefinition() == typeof(BlobPtr<>)); + var dataType = type.GenericTypeArguments[0]; + var viewerType = dataType.FindViewerType(); + if (Value == null || Value.GetType() != viewerType) Value = (IViewer) Activator.CreateInstance(viewerType); + ref var offsetPtr = ref UnsafeUtility.AsRef(dataPtr.ToPointer()); + Value.View(dataPtr + offsetPtr, dataType); + } + } + + [Serializable] + public class DynamicEnumViewer : IViewer + { + public long Ptr; + public string EnumType; + + public void View(IntPtr dataPtr, Type type) + { + Assert.IsTrue(type.IsEnum); + Ptr = dataPtr.ToInt64(); + EnumType = type.AssemblyQualifiedName; + } + } + + public static class Utility + { + public static Type FindViewerType(this Type dataType) + { + var viewerType = typeof(Viewer<>).MakeGenericType(dataType); + viewerType = TypeCache.GetTypesDerivedFrom(viewerType).SingleOrDefault(); + if (viewerType != null) return viewerType; + if (dataType.IsEnum) return typeof(DynamicEnumViewer); + if (dataType.IsGenericType && dataType.GetGenericTypeDefinition() == typeof(BlobPtr<>)) + return typeof(DynamicPtrViewer); + if (dataType.IsGenericType && dataType.GetGenericTypeDefinition() == typeof(BlobArray<>)) + return typeof(DynamicArrayViewer); + if (!dataType.IsPrimitive) return typeof(DynamicBlobDataViewer); + throw new ArgumentException($"cannot find proper viewer {dataType}"); + } + } +} \ No newline at end of file diff --git a/Packages/blob-editor/Runtime/Viewer/Viewers.cs.meta b/Packages/blob-editor/Runtime/Viewer/Viewers.cs.meta new file mode 100644 index 0000000..419c2a8 --- /dev/null +++ b/Packages/blob-editor/Runtime/Viewer/Viewers.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e87f1d377b1c42638518a7d325bb31cc +timeCreated: 1629881087 \ No newline at end of file diff --git a/Packages/manifest.json b/Packages/manifest.json index a5d8084..3348af9 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -2,7 +2,7 @@ "dependencies": { "com.unity.animation": "0.7.1-preview.2", "com.unity.ide.rider": "2.0.7", - "com.unity.ide.visualstudio": "2.0.9", + "com.unity.ide.visualstudio": "2.0.11", "com.unity.ide.vscode": "1.2.3", "com.unity.test-framework": "1.1.27", "com.unity.ugui": "1.0.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index d860bbd..61ea7db 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -92,7 +92,7 @@ "url": "https://packages.unity.com" }, "com.unity.ide.visualstudio": { - "version": "2.0.9", + "version": "2.0.11", "depth": 0, "source": "registry", "dependencies": { diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index 98c9697..35d8282 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2020.3.14f1 -m_EditorVersionWithRevision: 2020.3.14f1 (d0d1bb862f9d) +m_EditorVersion: 2020.3.16f1 +m_EditorVersionWithRevision: 2020.3.16f1 (049d6eca3c44)