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(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."); } } }