Add ScriptableObject asset command surface
This commit is contained in:
parent
659e3a5989
commit
00dbe48241
9 changed files with 149 additions and 1 deletions
|
|
@ -215,6 +215,7 @@ fn build_provider_advertisement() -> ProviderAdvertisement {
|
|||
"component.state.read",
|
||||
"selection.read",
|
||||
"asset.catalog.read",
|
||||
"asset.scriptable_object.create",
|
||||
"asset.prefab.instantiate",
|
||||
"asset.prefab.variant.create",
|
||||
"material.assign",
|
||||
|
|
@ -1495,6 +1496,11 @@ mod tests {
|
|||
assert!(unity.capabilities.contains(&"quest.input.consume"));
|
||||
assert!(unity.capabilities.contains(&"quest.pose.consume"));
|
||||
assert!(unity.capabilities.contains(&"quest.video_input.publish"));
|
||||
assert!(
|
||||
unity
|
||||
.capabilities
|
||||
.contains(&"asset.scriptable_object.create")
|
||||
);
|
||||
assert!(unity.capabilities.contains(&"material.assign"));
|
||||
assert!(!blender.capabilities.contains(&"quest.input.consume"));
|
||||
assert!(blender.capabilities.contains(&"object.graph.read"));
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ Primary Eve surface id: `brokkr.eve.tool_broker.v0`
|
|||
- `component.state.read`
|
||||
- `selection.read`
|
||||
- `asset.catalog.read`
|
||||
- `asset.scriptable_object.create`
|
||||
- `asset.prefab.instantiate`
|
||||
- `asset.prefab.variant.create`
|
||||
- `gameobject.create`
|
||||
|
|
@ -102,12 +103,15 @@ All Unity writes use `brokkr.unity.command_intent.v0` and receive
|
|||
- `instantiatePrefab`
|
||||
- `createPrefabVariant`
|
||||
- `assignMaterial`
|
||||
- `createScriptableObject`
|
||||
|
||||
Unity owns the mutation. Brokkr advertises the command surface; Verse clients
|
||||
write typed command intents; Unity executes recognized intents and publishes
|
||||
receipts. `setComponentProperty` writes the target object by default; when
|
||||
`componentType` is present, Unity resolves that component on the target
|
||||
GameObject and writes the serialized property there.
|
||||
`createScriptableObject` uses `componentType` as the ScriptableObject type and
|
||||
`assetPath` as the destination asset path.
|
||||
|
||||
## Blender Command Actions
|
||||
|
||||
|
|
|
|||
|
|
@ -67,6 +67,17 @@ namespace GameCult.Brokkr.Editor
|
|||
await node.FlushAsync(soft: true);
|
||||
}
|
||||
|
||||
internal async Task PublishCommandAsync(BrokkrUnityCommand command)
|
||||
{
|
||||
RequireRunning();
|
||||
var commandId = string.IsNullOrWhiteSpace(command.commandId)
|
||||
? Guid.NewGuid().ToString("N")
|
||||
: command.commandId;
|
||||
command.commandId = commandId;
|
||||
await node.Database.PutAsync(new CultRecordKey($"unity/commands/{commandId}"), command);
|
||||
await node.FlushAsync(soft: true);
|
||||
}
|
||||
|
||||
internal async Task PublishQuestRouteAsync(BrokkrQuestRoute route)
|
||||
{
|
||||
RequireRunning();
|
||||
|
|
|
|||
|
|
@ -97,5 +97,23 @@ namespace GameCult.Brokkr.Editor
|
|||
get => EditorPrefs.GetString("GameCult.Brokkr.BlenderCustomPropertyPath", "");
|
||||
set => EditorPrefs.SetString("GameCult.Brokkr.BlenderCustomPropertyPath", value);
|
||||
}
|
||||
|
||||
internal static string ScriptableObjectType
|
||||
{
|
||||
get => EditorPrefs.GetString("GameCult.Brokkr.ScriptableObjectType", "");
|
||||
set => EditorPrefs.SetString("GameCult.Brokkr.ScriptableObjectType", value);
|
||||
}
|
||||
|
||||
internal static string ScriptableObjectName
|
||||
{
|
||||
get => EditorPrefs.GetString("GameCult.Brokkr.ScriptableObjectName", "");
|
||||
set => EditorPrefs.SetString("GameCult.Brokkr.ScriptableObjectName", value);
|
||||
}
|
||||
|
||||
internal static string ScriptableObjectAssetPath
|
||||
{
|
||||
get => EditorPrefs.GetString("GameCult.Brokkr.ScriptableObjectAssetPath", "Assets/BrokkrAsset.asset");
|
||||
set => EditorPrefs.SetString("GameCult.Brokkr.ScriptableObjectAssetPath", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ namespace GameCult.Brokkr.Editor
|
|||
"instantiatePrefab" => InstantiatePrefab(command),
|
||||
"createPrefabVariant" => CreatePrefabVariant(command),
|
||||
"assignMaterial" => AssignMaterial(command),
|
||||
"createScriptableObject" => CreateScriptableObject(command),
|
||||
_ => Failed(command, $"Unsupported Unity command action: {command.action}")
|
||||
};
|
||||
}
|
||||
|
|
@ -182,6 +183,27 @@ namespace GameCult.Brokkr.Editor
|
|||
return Accepted(command, $"Prefab variant saved: {variantPath}", variantPath);
|
||||
}
|
||||
|
||||
private static BrokkrUnityCommandReceipt CreateScriptableObject(BrokkrUnityCommand command)
|
||||
{
|
||||
var type = BrokkrUnitySnapshotBuilder.ResolveType(command.componentType);
|
||||
if (type == null || !typeof(ScriptableObject).IsAssignableFrom(type))
|
||||
{
|
||||
return Failed(command, $"ScriptableObject type is not available: {command.componentType}");
|
||||
}
|
||||
|
||||
var asset = ScriptableObject.CreateInstance(type);
|
||||
asset.name = string.IsNullOrWhiteSpace(command.name) ? type.Name : command.name.Trim();
|
||||
var assetPath = string.IsNullOrWhiteSpace(command.assetPath)
|
||||
? $"Assets/{asset.name}.asset"
|
||||
: command.assetPath.Trim();
|
||||
EnsureAssetFolder(assetPath);
|
||||
assetPath = AssetDatabase.GenerateUniqueAssetPath(assetPath);
|
||||
AssetDatabase.CreateAsset(asset, assetPath);
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
return Accepted(command, $"ScriptableObject created: {assetPath}", BrokkrUnitySnapshotBuilder.GetObjectId(asset));
|
||||
}
|
||||
|
||||
private static BrokkrUnityCommandReceipt AssignMaterial(BrokkrUnityCommand command)
|
||||
{
|
||||
var gameObject = ResolveGameObject(command.targetObjectId);
|
||||
|
|
@ -309,6 +331,28 @@ namespace GameCult.Brokkr.Editor
|
|||
return created;
|
||||
}
|
||||
|
||||
private static void EnsureAssetFolder(string assetPath)
|
||||
{
|
||||
var folder = System.IO.Path.GetDirectoryName(assetPath)?.Replace("\\", "/");
|
||||
if (string.IsNullOrWhiteSpace(folder) || folder == "Assets" || AssetDatabase.IsValidFolder(folder))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var parts = folder.Split('/');
|
||||
var current = parts[0];
|
||||
for (var index = 1; index < parts.Length; index++)
|
||||
{
|
||||
var next = $"{current}/{parts[index]}";
|
||||
if (!AssetDatabase.IsValidFolder(next))
|
||||
{
|
||||
AssetDatabase.CreateFolder(current, parts[index]);
|
||||
}
|
||||
|
||||
current = next;
|
||||
}
|
||||
}
|
||||
|
||||
private static void AttachParent(GameObject gameObject, string parentObjectId)
|
||||
{
|
||||
var parent = ResolveGameObject(parentObjectId);
|
||||
|
|
|
|||
|
|
@ -160,7 +160,9 @@ namespace GameCult.Brokkr.Editor
|
|||
path = path,
|
||||
guid = AssetDatabase.AssetPathToGUID(path),
|
||||
typeName = type?.FullName ?? "",
|
||||
isPrefab = path.EndsWith(".prefab", StringComparison.OrdinalIgnoreCase)
|
||||
isPrefab = path.EndsWith(".prefab", StringComparison.OrdinalIgnoreCase),
|
||||
isScriptableObject = type != null && typeof(ScriptableObject).IsAssignableFrom(type),
|
||||
name = System.IO.Path.GetFileNameWithoutExtension(path)
|
||||
};
|
||||
})
|
||||
.ToArray();
|
||||
|
|
|
|||
|
|
@ -35,6 +35,9 @@ namespace GameCult.Brokkr.Editor
|
|||
private string unityCustomPropertyComponentType = "";
|
||||
private string unityCustomPropertyPath = "";
|
||||
private string blenderCustomPropertyPath = "";
|
||||
private string scriptableObjectType = "";
|
||||
private string scriptableObjectName = "";
|
||||
private string scriptableObjectAssetPath = "Assets/BrokkrAsset.asset";
|
||||
|
||||
[MenuItem("GameCult/Brokkr")]
|
||||
public static void Open()
|
||||
|
|
@ -59,6 +62,9 @@ namespace GameCult.Brokkr.Editor
|
|||
unityCustomPropertyComponentType = BrokkrSettings.UnityCustomPropertyComponentType;
|
||||
unityCustomPropertyPath = BrokkrSettings.UnityCustomPropertyPath;
|
||||
blenderCustomPropertyPath = BrokkrSettings.BlenderCustomPropertyPath;
|
||||
scriptableObjectType = BrokkrSettings.ScriptableObjectType;
|
||||
scriptableObjectName = BrokkrSettings.ScriptableObjectName;
|
||||
scriptableObjectAssetPath = BrokkrSettings.ScriptableObjectAssetPath;
|
||||
Selection.selectionChanged += Repaint;
|
||||
EditorSceneManagerBridge.SceneDirtied += OnEditorSignal;
|
||||
EditorApplication.playModeStateChanged += OnPlayModeChanged;
|
||||
|
|
@ -101,6 +107,9 @@ namespace GameCult.Brokkr.Editor
|
|||
BrokkrSettings.UnityCustomPropertyComponentType = unityCustomPropertyComponentType;
|
||||
BrokkrSettings.UnityCustomPropertyPath = unityCustomPropertyPath;
|
||||
BrokkrSettings.BlenderCustomPropertyPath = blenderCustomPropertyPath;
|
||||
BrokkrSettings.ScriptableObjectType = scriptableObjectType;
|
||||
BrokkrSettings.ScriptableObjectName = scriptableObjectName;
|
||||
BrokkrSettings.ScriptableObjectAssetPath = scriptableObjectAssetPath;
|
||||
SetStatus("Settings saved.", MessageType.Info);
|
||||
}
|
||||
|
||||
|
|
@ -146,9 +155,24 @@ namespace GameCult.Brokkr.Editor
|
|||
EditorGUILayout.LabelField("Selection", string.Join(", ", lastSnapshot.selectedObjectNames));
|
||||
}
|
||||
|
||||
DrawAssetCommandSection();
|
||||
DrawSyncSection();
|
||||
}
|
||||
|
||||
private void DrawAssetCommandSection()
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("Unity Assets", EditorStyles.boldLabel);
|
||||
scriptableObjectType = EditorGUILayout.TextField("ScriptableObject Type", scriptableObjectType);
|
||||
scriptableObjectName = EditorGUILayout.TextField("Asset Name", scriptableObjectName);
|
||||
scriptableObjectAssetPath = EditorGUILayout.TextField("Asset Path", scriptableObjectAssetPath);
|
||||
|
||||
if (GUILayout.Button("Create ScriptableObject Asset"))
|
||||
{
|
||||
PublishCreateScriptableObjectCommand();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawSyncSection()
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
|
|
@ -279,6 +303,35 @@ namespace GameCult.Brokkr.Editor
|
|||
}
|
||||
}
|
||||
|
||||
private void PublishCreateScriptableObjectCommand()
|
||||
{
|
||||
try
|
||||
{
|
||||
RequireMirror();
|
||||
if (string.IsNullOrWhiteSpace(scriptableObjectType))
|
||||
{
|
||||
throw new InvalidOperationException("Enter a ScriptableObject type before creating an asset.");
|
||||
}
|
||||
|
||||
var command = new BrokkrUnityCommand
|
||||
{
|
||||
commandId = StableId("unity-command", "scriptable-object", Guid.NewGuid().ToString("N")),
|
||||
action = "createScriptableObject",
|
||||
componentType = scriptableObjectType.Trim(),
|
||||
name = scriptableObjectName.Trim(),
|
||||
assetPath = string.IsNullOrWhiteSpace(scriptableObjectAssetPath)
|
||||
? "Assets/BrokkrAsset.asset"
|
||||
: scriptableObjectAssetPath.Trim()
|
||||
};
|
||||
mirror.PublishCommandAsync(command).GetAwaiter().GetResult();
|
||||
PollAndExecuteCommand(true);
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
SetStatus(error.Message, MessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void PublishSelectedObjectSync()
|
||||
{
|
||||
try
|
||||
|
|
|
|||
|
|
@ -86,6 +86,8 @@ namespace GameCult.Brokkr
|
|||
[Key(1)] public string guid = "";
|
||||
[Key(2)] public string typeName = "";
|
||||
[Key(3)] public bool isPrefab;
|
||||
[Key(4)] public bool isScriptableObject;
|
||||
[Key(5)] public string name = "";
|
||||
}
|
||||
|
||||
[CultDocument("brokkr.unity.command_intent", "brokkr.unity.command_intent.v0")]
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ In Unity:
|
|||
4. Click `Start CultMesh Mirror`.
|
||||
5. Click `Capture Snapshot`.
|
||||
6. Click `Publish Mirror`.
|
||||
7. To create a ScriptableObject through the mirror, fill `ScriptableObject Type`,
|
||||
`Asset Name`, and `Asset Path`, then click `Create ScriptableObject Asset`.
|
||||
|
||||
The Unity adapter writes the latest editor snapshot to:
|
||||
|
||||
|
|
@ -50,5 +52,11 @@ to:
|
|||
unity/receipts/{commandId}
|
||||
```
|
||||
|
||||
Recognized Unity asset commands include:
|
||||
|
||||
- `instantiatePrefab`
|
||||
- `createPrefabVariant`
|
||||
- `createScriptableObject`
|
||||
|
||||
The Unity plugin is still an adapter. Unity owns Unity editor truth; Brokkr owns
|
||||
provider discovery; CultCache and CultMesh own the live mirror lane.
|
||||
|
|
|
|||
Loading…
Reference in a new issue