Skip to content

Commit

Permalink
Blob viewer (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
quabug authored Aug 25, 2021
1 parent 7e4205b commit 94b9655
Show file tree
Hide file tree
Showing 77 changed files with 679 additions and 110 deletions.
3 changes: 3 additions & 0 deletions Assets/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
public class Example : MonoBehaviour
{
public BlobAsset<ExampleBlob> Blob;
public BlobViewer Viewer;

private void Awake()
{
// get `BlobAssetReference` from `BlobAsset`
BlobAssetReference<ExampleBlob> blob = Blob.Reference;
// or use blob value directly
var _ = Blob.Value.Float3;

Viewer.View(Blob.Reference);
}
}

Expand Down
71 changes: 38 additions & 33 deletions Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -865,6 +865,9 @@ MonoBehaviour:
Blob:
Builder:
id: 0
Viewer:
Viewer:
id: 1
references:
version: 1
00000000:
Expand All @@ -885,7 +888,6 @@ MonoBehaviour:
- Enum
- Arrays
Builders:
- id: 1
- id: 2
- id: 3
- id: 4
Expand All @@ -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:
Expand All @@ -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,
Expand All @@ -979,58 +984,58 @@ 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,
Unity.Entities, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]],
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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions Assets/TestCustomBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ public override void Build(BlobBuilder builder, ref BlobString data)
}
}

[Serializable]
public class GuidViewer : Viewer<Guid>
{
public string Guid = System.Guid.NewGuid().ToString();

public override void View(ref Guid data)
{
Guid = data.ToString();
}
}

[Serializable]
public class ObjectName : Builder<BlobString>
{
Expand Down
6 changes: 4 additions & 2 deletions Packages/blob-editor/Editor/Blob.Editor.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
File renamed without changes.
27 changes: 6 additions & 21 deletions Packages/blob-editor/Editor/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> Yield<T>(this T value)
Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
3 changes: 3 additions & 0 deletions Packages/blob-editor/Editor/ViewerDrawer.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 94b9655

Please sign in to comment.