- BlobBuilder: Edit
BlobAsset
in Inspector and then easily create from code. - BlobViewer: Display
Blob
data in Inspector at editor-playing-mode.
BlobAssetV1
- (Recommend) OpenUPM:
openupm add com.quabug.blob-editor
- or UPM: edit Packages/manifest.json
{
"dependencies": {
"com.quabug.blob-editor": "1.4.0",
...
},
"scopedRegistries": [
{
"name": "package.openupm.com",
"url": "https://package.openupm.com",
"scopes": [
"com.quabug.blob-editor"
]
}
]
}
Edit and build BlobAsset
from inspector
public class SingleBlobComponent : MonoBehaviour
{
public BlobAsset<BlobArray<int>> IntArray;
private void Awake()
{
// get `BlobAssetReference` from `BlobAsset`
BlobAssetReference<BlobArray<int>> blob = IntArray.Reference;
// or use blob value directly
ref BlobArray<int> _ = ref IntArray.Value;
}
}
struct Blob
{
public int Int;
public BlobString String;
}
public class BlobStructureComponent : MonoBehaviour
{
public BlobAsset<Blob> BlobValue;
private void Awake()
{
// get `BlobAssetReference` from `BlobAsset`
BlobAssetReference<BlobData> blob = BlobValue.Reference;
// or use blob value directly
string _ = BlobValue.Value.String.ToString();
}
}
Builders of primitive types and com.unity.mathematics types are provided by default.
A specific builder must be provided for any new type.
Take Guid
as example:
public struct GuidBlob
{
public Guid Value;
}
[Serializable]
public class GuidBuilder : Builder<Guid>
{
public string Guid = System.Guid.NewGuid().ToString();
public override void Build(BlobBuilder builder, ref Guid data)
{
data = System.Guid.Parse(Guid);
}
}
PlainDataBuilder<>
: Builder of POD. Show the POD as whole in inspector. Not support data with its own builder, e.g.BlobPtr
,BlobArray
orBlobString
.BlobDataBuilder<>
: Builder of structure with Blob-Specific data inside. Split each data inside structure into its own builder to show and edit. Support data withDefaultBuilder
orCustomBuilder
, e.g.BlobPtr
,BlobArray
orBlobString
.ArrayBuilder<>
: Builder forBlobArray<>
.PtrBuilder<>
: Builder forBlobPtr<>
.
There's may have multiple builders for a single type, one of them must be defined as DefaultBuilder
, or use CustomBuilder
to assign a specific builder for a value of blob.
[Serializable, DefaultBuilder]
public class StringBuilder : Builder<BlobString>
{
public string Value = "";
public override void Build(BlobBuilder builder, ref BlobString data)
{
builder.AllocateString(ref data, Value);
}
}
// a builder of `BlobString` which save name of *GameObject* into `BlobString`
[Serializable]
public class ObjectName : Builder<BlobString>
{
public GameObject GameObject;
public override void Build(BlobBuilder builder, ref BlobString data)
{
builder.AllocateString(ref data, GameObject == null ? "" : GameObject.name);
}
}
public struct Blob
{
public BlobString String; // will use `StringBuilder` by default
[CustomBuilder(typeof(ObjectName))] public BlobString ObjectName;
}
Display Blob
data in Inspector at editor-playing-mode
public class BlobViewerComponent : MonoBehaviour
{
public BlobViewer Viewer;
private void Awake()
{
// set blob into viewer to inspect
BlobAssetReference<SomeBlob> someBlob = ...;
Viewer.View(someBlob);
}
}
[Serializable]
public class GuidViewer : Viewer<Guid /* data type in blob */>
{
// declare a serialized field for unity to show in inspector.
public string Guid = System.Guid.NewGuid().ToString();
// assign value from blob data to serialized field in `View` method.
public override void View(ref Guid data)
{
Guid = data.ToString();
}
}