123456789101112131415161718192021222324252627282930 |
- using UnityEngine;
- using UnityEditor;
- using JetBrains.Annotations;
- namespace LLM.Editor.Commands
- {
- [UsedImplicitly]
- public class InstantiatePrefabCommand : ICommand
- {
- public InstantiatePrefabCommand(string jsonParams) { } // No params needed for this one
- public void Execute(Data.CommandContext context)
- {
- // Use the context key defined in CreatePrefabCommand
- if (!context.transientData.TryGetValue(CreatePrefabCommand.CONTEXT_KEY_PREFAB_PATH, out var pathObj))
- {
- Debug.LogError("[InstantiatePrefabCommand] Could not find prefab path in context.");
- return;
- }
- var prefabPath = pathObj as string;
- var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
- var instance = (GameObject)PrefabUtility.InstantiatePrefab(prefab);
- Undo.RegisterCreatedObjectUndo(instance, "Instantiate " + instance.name);
- Selection.activeObject = instance;
- Debug.Log($"[InstantiatePrefabCommand] Instantiated '{prefab.name}' into the scene.");
- }
- }
- }
|