unity-mcp/TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ManagePrefabsCrudTests.cs

870 lines
35 KiB
C#
Raw Normal View History

feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.TestTools;
using MCPForUnity.Editor.Tools.Prefabs;
using static MCPForUnityTests.Editor.TestUtilities;
namespace MCPForUnityTests.Editor.Tools
{
/// <summary>
/// Tests for Prefab CRUD operations: create_from_gameobject, get_info, get_hierarchy, modify_contents.
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
/// </summary>
public class ManagePrefabsCrudTests
{
private const string TempDirectory = "Assets/Temp/ManagePrefabsCrudTests";
[SetUp]
public void SetUp()
{
StageUtility.GoToMainStage();
EnsureFolder(TempDirectory);
}
[TearDown]
public void TearDown()
{
StageUtility.GoToMainStage();
if (AssetDatabase.IsValidFolder(TempDirectory))
{
AssetDatabase.DeleteAsset(TempDirectory);
}
CleanupEmptyParentFolders(TempDirectory);
}
#region CREATE Tests
[Test]
public void CreateFromGameObject_CreatesNewPrefab()
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
string prefabPath = Path.Combine(TempDirectory, "NewPrefab.prefab").Replace('\\', '/');
GameObject sceneObject = new GameObject("TestObject");
try
{
var result = ToJObject(ManagePrefabs.HandleCommand(new JObject
{
["action"] = "create_from_gameobject",
["target"] = sceneObject.name,
["prefabPath"] = prefabPath
}));
Assert.IsTrue(result.Value<bool>("success"));
Assert.AreEqual(prefabPath, result["data"].Value<string>("prefabPath"));
Assert.IsNotNull(AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}
finally
{
SafeDeleteAsset(prefabPath);
if (sceneObject != null) UnityEngine.Object.DestroyImmediate(sceneObject, true);
}
}
[Test]
public void CreateFromGameObject_HandlesExistingPrefabsAndLinks()
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
// Tests: unlinkIfInstance, allowOverwrite, unique path generation
string prefabPath = Path.Combine(TempDirectory, "Existing.prefab").Replace('\\', '/');
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
GameObject sourceObject = new GameObject("SourceObject");
try
{
// Create initial prefab and link source object
PrefabUtility.SaveAsPrefabAssetAndConnect(sourceObject, prefabPath, InteractionMode.AutomatedAction);
Assert.IsTrue(PrefabUtility.IsAnyPrefabInstanceRoot(sourceObject));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
// Without unlink - should fail (already linked)
string newPath = Path.Combine(TempDirectory, "New.prefab").Replace('\\', '/');
var failResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
["action"] = "create_from_gameobject",
["target"] = sourceObject.name,
["prefabPath"] = newPath
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}));
Assert.IsFalse(failResult.Value<bool>("success"));
Assert.IsTrue(failResult.Value<string>("error").Contains("already linked"));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
// With unlinkIfInstance - should succeed
var unlinkResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
["action"] = "create_from_gameobject",
["target"] = sourceObject.name,
["prefabPath"] = newPath,
["unlinkIfInstance"] = true
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}));
Assert.IsTrue(unlinkResult.Value<bool>("success"));
Assert.IsTrue(unlinkResult["data"].Value<bool>("wasUnlinked"));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
// With allowOverwrite - should replace
GameObject anotherObject = new GameObject("AnotherObject");
var overwriteResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
["action"] = "create_from_gameobject",
["target"] = anotherObject.name,
["prefabPath"] = newPath,
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
["allowOverwrite"] = true
}));
Assert.IsTrue(overwriteResult.Value<bool>("success"));
Assert.IsTrue(overwriteResult["data"].Value<bool>("wasReplaced"));
UnityEngine.Object.DestroyImmediate(anotherObject, true);
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
// Without overwrite on existing - should generate unique path
GameObject thirdObject = new GameObject("ThirdObject");
var uniqueResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
["action"] = "create_from_gameobject",
["target"] = thirdObject.name,
["prefabPath"] = newPath
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}));
Assert.IsTrue(uniqueResult.Value<bool>("success"));
Assert.AreNotEqual(newPath, uniqueResult["data"].Value<string>("prefabPath"));
SafeDeleteAsset(uniqueResult["data"].Value<string>("prefabPath"));
UnityEngine.Object.DestroyImmediate(thirdObject, true);
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}
finally
{
SafeDeleteAsset(prefabPath);
SafeDeleteAsset(Path.Combine(TempDirectory, "New.prefab").Replace('\\', '/'));
if (sourceObject != null) UnityEngine.Object.DestroyImmediate(sourceObject, true);
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}
}
[Test]
public void CreateFromGameObject_FindsInactiveObject_WhenSearchInactiveIsTrue()
{
string prefabPath = Path.Combine(TempDirectory, "InactiveTest.prefab").Replace('\\', '/');
GameObject inactiveObject = new GameObject("InactiveObject");
inactiveObject.SetActive(false);
try
{
// Without searchInactive - should fail to find inactive object
var failResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
["action"] = "create_from_gameobject",
["target"] = inactiveObject.name,
["prefabPath"] = prefabPath
}));
Assert.IsFalse(failResult.Value<bool>("success"));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
// With searchInactive - should succeed
var successResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
["action"] = "create_from_gameobject",
["target"] = inactiveObject.name,
["prefabPath"] = prefabPath,
["searchInactive"] = true
}));
Assert.IsTrue(successResult.Value<bool>("success"));
Assert.IsNotNull(AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}
finally
{
SafeDeleteAsset(prefabPath);
if (inactiveObject != null) UnityEngine.Object.DestroyImmediate(inactiveObject, true);
}
}
#endregion
#region READ Tests
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
[Test]
public void GetInfo_ReturnsMetadata()
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
string prefabPath = CreateTestPrefab("InfoTest");
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
try
{
var result = ToJObject(ManagePrefabs.HandleCommand(new JObject
{
["action"] = "get_info",
["prefabPath"] = prefabPath
}));
Assert.IsTrue(result.Value<bool>("success"));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
var data = result["data"] as JObject;
Assert.AreEqual(prefabPath, data.Value<string>("assetPath"));
Assert.IsNotNull(data.Value<string>("guid"));
Assert.AreEqual("Regular", data.Value<string>("prefabType"));
Assert.AreEqual("InfoTest", data.Value<string>("rootObjectName"));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}
finally
{
SafeDeleteAsset(prefabPath);
}
}
[Test]
public void GetHierarchy_ReturnsHierarchyWithNestingInfo()
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
// Create a prefab with nested prefab instance
string childPrefabPath = CreateTestPrefab("ChildPrefab");
string containerPath = null;
try
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
GameObject container = new GameObject("Container");
GameObject child1 = new GameObject("Child1");
child1.transform.parent = container.transform;
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
// Add nested prefab instance
GameObject nestedInstance = PrefabUtility.InstantiatePrefab(
AssetDatabase.LoadAssetAtPath<GameObject>(childPrefabPath)) as GameObject;
nestedInstance.transform.parent = container.transform;
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
containerPath = Path.Combine(TempDirectory, "Container.prefab").Replace('\\', '/');
PrefabUtility.SaveAsPrefabAsset(container, containerPath, out bool _);
UnityEngine.Object.DestroyImmediate(container);
AssetDatabase.Refresh();
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
var result = ToJObject(ManagePrefabs.HandleCommand(new JObject
{
["action"] = "get_hierarchy",
["prefabPath"] = containerPath
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}));
Assert.IsTrue(result.Value<bool>("success"));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
var data = result["data"] as JObject;
var items = data["items"] as JArray;
Assert.IsTrue(data.Value<int>("total") >= 3); // Container, Child1, nested prefab
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
// Verify root and nested prefab info
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
var root = items.Cast<JObject>().FirstOrDefault(j => j["prefab"]["isRoot"].Value<bool>());
Assert.IsNotNull(root);
Assert.AreEqual("Container", root.Value<string>("name"));
var nested = items.Cast<JObject>().FirstOrDefault(j => j["prefab"]["isNestedRoot"].Value<bool>());
Assert.IsNotNull(nested);
Assert.AreEqual(1, nested["prefab"]["nestingDepth"].Value<int>());
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}
finally
{
if (containerPath != null) SafeDeleteAsset(containerPath);
SafeDeleteAsset(childPrefabPath);
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}
}
#endregion
#region UPDATE Tests (ModifyContents)
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
[Test]
public void ModifyContents_ModifiesTransformWithoutOpeningStage()
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
string prefabPath = CreateTestPrefab("ModifyTest");
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
try
{
StageUtility.GoToMainStage();
Assert.IsNull(PrefabStageUtility.GetCurrentPrefabStage());
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
var result = ToJObject(ManagePrefabs.HandleCommand(new JObject
{
["action"] = "modify_contents",
["prefabPath"] = prefabPath,
["position"] = new JArray(1f, 2f, 3f),
["rotation"] = new JArray(45f, 0f, 0f),
["scale"] = new JArray(2f, 2f, 2f)
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}));
Assert.IsTrue(result.Value<bool>("success"));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
// Verify no stage was opened (headless editing)
Assert.IsNull(PrefabStageUtility.GetCurrentPrefabStage());
// Verify changes persisted
GameObject reloaded = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
Assert.AreEqual(new Vector3(1f, 2f, 3f), reloaded.transform.localPosition);
Assert.AreEqual(new Vector3(2f, 2f, 2f), reloaded.transform.localScale);
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}
finally
{
SafeDeleteAsset(prefabPath);
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}
}
[Test]
public void ModifyContents_TargetsChildrenByNameAndPath()
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
string prefabPath = CreateNestedTestPrefab("TargetTest");
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
try
{
// Target by name
var nameResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
["action"] = "modify_contents",
["prefabPath"] = prefabPath,
["target"] = "Child1",
["position"] = new JArray(10f, 10f, 10f)
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}));
Assert.IsTrue(nameResult.Value<bool>("success"));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
// Target by path
var pathResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
["action"] = "modify_contents",
["prefabPath"] = prefabPath,
["target"] = "Child1/Grandchild",
["scale"] = new JArray(3f, 3f, 3f)
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}));
Assert.IsTrue(pathResult.Value<bool>("success"));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
// Verify changes
GameObject reloaded = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
Assert.AreEqual(new Vector3(10f, 10f, 10f), reloaded.transform.Find("Child1").localPosition);
Assert.AreEqual(new Vector3(3f, 3f, 3f), reloaded.transform.Find("Child1/Grandchild").localScale);
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}
finally
{
SafeDeleteAsset(prefabPath);
}
}
[Test]
public void ModifyContents_AddsAndRemovesComponents()
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
string prefabPath = CreateTestPrefab("ComponentTest");
// Cube primitive has BoxCollider by default
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
try
{
// Add Rigidbody
var addResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
["action"] = "modify_contents",
["prefabPath"] = prefabPath,
["componentsToAdd"] = new JArray("Rigidbody")
}));
Assert.IsTrue(addResult.Value<bool>("success"));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
// Remove BoxCollider
var removeResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
["action"] = "modify_contents",
["prefabPath"] = prefabPath,
["componentsToRemove"] = new JArray("BoxCollider")
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}));
Assert.IsTrue(removeResult.Value<bool>("success"));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
// Verify
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
GameObject reloaded = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
Assert.IsNotNull(reloaded.GetComponent<Rigidbody>());
Assert.IsNull(reloaded.GetComponent<BoxCollider>());
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}
finally
{
SafeDeleteAsset(prefabPath);
}
}
[Test]
public void ModifyContents_SetsPropertiesAndRenames()
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
string prefabPath = CreateNestedTestPrefab("PropertiesTest");
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
try
{
var result = ToJObject(ManagePrefabs.HandleCommand(new JObject
{
["action"] = "modify_contents",
["prefabPath"] = prefabPath,
["target"] = "Child1",
["name"] = "RenamedChild",
["tag"] = "MainCamera",
["layer"] = "UI",
["setActive"] = false
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}));
Assert.IsTrue(result.Value<bool>("success"));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
GameObject reloaded = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
Transform renamed = reloaded.transform.Find("RenamedChild");
Assert.IsNotNull(renamed);
Assert.IsNull(reloaded.transform.Find("Child1")); // Old name gone
Assert.AreEqual("MainCamera", renamed.gameObject.tag);
Assert.AreEqual(LayerMask.NameToLayer("UI"), renamed.gameObject.layer);
Assert.IsFalse(renamed.gameObject.activeSelf);
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}
finally
{
SafeDeleteAsset(prefabPath);
}
}
[Test]
public void ModifyContents_WorksOnComplexMultiComponentPrefab()
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
// Create a complex prefab: Vehicle with multiple children, each with multiple components
string prefabPath = CreateComplexTestPrefab("Vehicle");
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
try
{
// Modify root - add Rigidbody
var rootResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
["action"] = "modify_contents",
["prefabPath"] = prefabPath,
["componentsToAdd"] = new JArray("Rigidbody")
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}));
Assert.IsTrue(rootResult.Value<bool>("success"));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
// Modify child by name - reposition FrontWheel, add SphereCollider
var wheelResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
{
["action"] = "modify_contents",
["prefabPath"] = prefabPath,
["target"] = "FrontWheel",
["position"] = new JArray(0f, 0.5f, 2f),
["componentsToAdd"] = new JArray("SphereCollider")
}));
Assert.IsTrue(wheelResult.Value<bool>("success"));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
// Modify nested child by path - scale Barrel inside Turret
var barrelResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
["action"] = "modify_contents",
["prefabPath"] = prefabPath,
["target"] = "Turret/Barrel",
["scale"] = new JArray(0.5f, 0.5f, 3f),
["tag"] = "Player"
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}));
Assert.IsTrue(barrelResult.Value<bool>("success"));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
// Remove component from child
var removeResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
["action"] = "modify_contents",
["prefabPath"] = prefabPath,
["target"] = "BackWheel",
["componentsToRemove"] = new JArray("BoxCollider")
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}));
Assert.IsTrue(removeResult.Value<bool>("success"));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
// Verify all changes persisted
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
GameObject reloaded = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
// Root has Rigidbody
Assert.IsNotNull(reloaded.GetComponent<Rigidbody>(), "Root should have Rigidbody");
// FrontWheel repositioned and has SphereCollider
Transform frontWheel = reloaded.transform.Find("FrontWheel");
Assert.AreEqual(new Vector3(0f, 0.5f, 2f), frontWheel.localPosition);
Assert.IsNotNull(frontWheel.GetComponent<SphereCollider>(), "FrontWheel should have SphereCollider");
// Turret/Barrel scaled and tagged
Transform barrel = reloaded.transform.Find("Turret/Barrel");
Assert.AreEqual(new Vector3(0.5f, 0.5f, 3f), barrel.localScale);
Assert.AreEqual("Player", barrel.gameObject.tag);
// BackWheel BoxCollider removed
Transform backWheel = reloaded.transform.Find("BackWheel");
Assert.IsNull(backWheel.GetComponent<BoxCollider>(), "BackWheel BoxCollider should be removed");
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}
finally
{
SafeDeleteAsset(prefabPath);
}
}
[Test]
public void ModifyContents_ReparentsChildWithinPrefab()
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
string prefabPath = CreateNestedTestPrefab("ReparentTest");
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
try
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
// Reparent Child2 under Child1
var result = ToJObject(ManagePrefabs.HandleCommand(new JObject
{
["action"] = "modify_contents",
["prefabPath"] = prefabPath,
["target"] = "Child2",
["parent"] = "Child1"
}));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
Assert.IsTrue(result.Value<bool>("success"));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
// Verify Child2 is now under Child1
GameObject reloaded = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
Assert.IsNull(reloaded.transform.Find("Child2"), "Child2 should no longer be direct child of root");
Assert.IsNotNull(reloaded.transform.Find("Child1/Child2"), "Child2 should now be under Child1");
}
finally
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
SafeDeleteAsset(prefabPath);
}
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}
[Test]
public void ModifyContents_PreventsHierarchyLoops()
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
string prefabPath = CreateNestedTestPrefab("HierarchyLoopTest");
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
try
{
// Attempt to parent Child1 under its own descendant (Grandchild)
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
var result = ToJObject(ManagePrefabs.HandleCommand(new JObject
{
["action"] = "modify_contents",
["prefabPath"] = prefabPath,
["target"] = "Child1",
["parent"] = "Child1/Grandchild"
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}));
Assert.IsFalse(result.Value<bool>("success"));
Assert.IsTrue(result.Value<string>("error").Contains("hierarchy loop") ||
result.Value<string>("error").Contains("would create"),
"Error should mention hierarchy loop prevention");
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}
finally
{
SafeDeleteAsset(prefabPath);
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}
}
[Test]
public void ModifyContents_CreateChild_AddsSingleChildWithPrimitive()
{
string prefabPath = CreateTestPrefab("CreateChildTest");
try
{
var result = ToJObject(ManagePrefabs.HandleCommand(new JObject
{
["action"] = "modify_contents",
["prefabPath"] = prefabPath,
["createChild"] = new JObject
{
["name"] = "NewSphere",
["primitive_type"] = "Sphere",
["position"] = new JArray(1f, 2f, 3f),
["scale"] = new JArray(0.5f, 0.5f, 0.5f)
}
}));
Assert.IsTrue(result.Value<bool>("success"));
GameObject reloaded = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
Transform child = reloaded.transform.Find("NewSphere");
Assert.IsNotNull(child, "Child should exist");
Assert.AreEqual(new Vector3(1f, 2f, 3f), child.localPosition);
Assert.AreEqual(new Vector3(0.5f, 0.5f, 0.5f), child.localScale);
Assert.IsNotNull(child.GetComponent<SphereCollider>(), "Sphere primitive should have SphereCollider");
}
finally
{
SafeDeleteAsset(prefabPath);
}
}
[Test]
public void ModifyContents_CreateChild_AddsEmptyGameObject()
{
string prefabPath = CreateTestPrefab("EmptyChildTest");
try
{
var result = ToJObject(ManagePrefabs.HandleCommand(new JObject
{
["action"] = "modify_contents",
["prefabPath"] = prefabPath,
["createChild"] = new JObject
{
["name"] = "EmptyChild",
["position"] = new JArray(0f, 5f, 0f)
}
}));
Assert.IsTrue(result.Value<bool>("success"));
GameObject reloaded = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
Transform child = reloaded.transform.Find("EmptyChild");
Assert.IsNotNull(child, "Empty child should exist");
Assert.AreEqual(new Vector3(0f, 5f, 0f), child.localPosition);
// Empty GO should only have Transform
Assert.AreEqual(1, child.GetComponents<Component>().Length, "Empty child should only have Transform");
}
finally
{
SafeDeleteAsset(prefabPath);
}
}
[Test]
public void ModifyContents_CreateChild_AddsMultipleChildrenFromArray()
{
string prefabPath = CreateTestPrefab("MultiChildTest");
try
{
var result = ToJObject(ManagePrefabs.HandleCommand(new JObject
{
["action"] = "modify_contents",
["prefabPath"] = prefabPath,
["createChild"] = new JArray
{
new JObject { ["name"] = "Child1", ["primitive_type"] = "Cube", ["position"] = new JArray(1f, 0f, 0f) },
new JObject { ["name"] = "Child2", ["primitive_type"] = "Sphere", ["position"] = new JArray(-1f, 0f, 0f) },
new JObject { ["name"] = "Child3", ["position"] = new JArray(0f, 1f, 0f) }
}
}));
Assert.IsTrue(result.Value<bool>("success"));
GameObject reloaded = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
Assert.IsNotNull(reloaded.transform.Find("Child1"), "Child1 should exist");
Assert.IsNotNull(reloaded.transform.Find("Child2"), "Child2 should exist");
Assert.IsNotNull(reloaded.transform.Find("Child3"), "Child3 should exist");
Assert.IsNotNull(reloaded.transform.Find("Child1").GetComponent<BoxCollider>(), "Child1 should be Cube");
Assert.IsNotNull(reloaded.transform.Find("Child2").GetComponent<SphereCollider>(), "Child2 should be Sphere");
}
finally
{
SafeDeleteAsset(prefabPath);
}
}
[Test]
public void ModifyContents_CreateChild_SupportsNestedParenting()
{
string prefabPath = CreateNestedTestPrefab("NestedCreateChildTest");
try
{
var result = ToJObject(ManagePrefabs.HandleCommand(new JObject
{
["action"] = "modify_contents",
["prefabPath"] = prefabPath,
["createChild"] = new JObject
{
["name"] = "NewGrandchild",
["parent"] = "Child1",
["primitive_type"] = "Capsule"
}
}));
Assert.IsTrue(result.Value<bool>("success"));
GameObject reloaded = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
Transform newChild = reloaded.transform.Find("Child1/NewGrandchild");
Assert.IsNotNull(newChild, "NewGrandchild should be under Child1");
Assert.IsNotNull(newChild.GetComponent<CapsuleCollider>(), "Should be Capsule primitive");
}
finally
{
SafeDeleteAsset(prefabPath);
}
}
[Test]
public void ModifyContents_CreateChild_ReturnsErrorForInvalidInput()
{
string prefabPath = CreateTestPrefab("InvalidChildTest");
try
{
// Missing required 'name' field
var missingName = ToJObject(ManagePrefabs.HandleCommand(new JObject
{
["action"] = "modify_contents",
["prefabPath"] = prefabPath,
["createChild"] = new JObject
{
["primitive_type"] = "Cube"
}
}));
Assert.IsFalse(missingName.Value<bool>("success"));
Assert.IsTrue(missingName.Value<string>("error").Contains("name"));
// Invalid parent
var invalidParent = ToJObject(ManagePrefabs.HandleCommand(new JObject
{
["action"] = "modify_contents",
["prefabPath"] = prefabPath,
["createChild"] = new JObject
{
["name"] = "TestChild",
["parent"] = "NonexistentParent"
}
}));
Assert.IsFalse(invalidParent.Value<bool>("success"));
Assert.IsTrue(invalidParent.Value<string>("error").Contains("not found"));
// Invalid primitive type
var invalidPrimitive = ToJObject(ManagePrefabs.HandleCommand(new JObject
{
["action"] = "modify_contents",
["prefabPath"] = prefabPath,
["createChild"] = new JObject
{
["name"] = "TestChild",
["primitive_type"] = "InvalidType"
}
}));
Assert.IsFalse(invalidPrimitive.Value<bool>("success"));
Assert.IsTrue(invalidPrimitive.Value<string>("error").Contains("Invalid primitive type"));
}
finally
{
SafeDeleteAsset(prefabPath);
}
}
#endregion
#region Error Handling
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
[Test]
public void HandleCommand_ValidatesParameters()
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
// Null params
var nullResult = ToJObject(ManagePrefabs.HandleCommand(null));
Assert.IsFalse(nullResult.Value<bool>("success"));
Assert.IsTrue(nullResult.Value<string>("error").Contains("null"));
// Missing action
var missingAction = ToJObject(ManagePrefabs.HandleCommand(new JObject()));
Assert.IsFalse(missingAction.Value<bool>("success"));
Assert.IsTrue(missingAction.Value<string>("error").Contains("Action parameter is required"));
// Unknown action
var unknownAction = ToJObject(ManagePrefabs.HandleCommand(new JObject { ["action"] = "invalid" }));
Assert.IsFalse(unknownAction.Value<bool>("success"));
Assert.IsTrue(unknownAction.Value<string>("error").Contains("Unknown action"));
// Path traversal
GameObject testObj = new GameObject("Test");
var traversal = ToJObject(ManagePrefabs.HandleCommand(new JObject
{
["action"] = "create_from_gameobject",
["target"] = "Test",
["prefabPath"] = "../../etc/passwd"
}));
Assert.IsFalse(traversal.Value<bool>("success"));
Assert.IsTrue(traversal.Value<string>("error").Contains("path traversal") ||
traversal.Value<string>("error").Contains("Invalid"));
UnityEngine.Object.DestroyImmediate(testObj, true);
}
[Test]
public void ModifyContents_ReturnsErrorsForInvalidInputs()
{
string prefabPath = CreateTestPrefab("ErrorTest");
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
try
{
// Invalid target
var invalidTarget = ToJObject(ManagePrefabs.HandleCommand(new JObject
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
{
["action"] = "modify_contents",
["prefabPath"] = prefabPath,
["target"] = "NonexistentChild"
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}));
Assert.IsFalse(invalidTarget.Value<bool>("success"));
Assert.IsTrue(invalidTarget.Value<string>("error").Contains("not found"));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
// Invalid path
LogAssert.Expect(LogType.Error, new Regex(".*modify_contents.*does not exist.*"));
var invalidPath = ToJObject(ManagePrefabs.HandleCommand(new JObject
{
["action"] = "modify_contents",
["prefabPath"] = "Assets/Nonexistent.prefab"
}));
Assert.IsFalse(invalidPath.Value<bool>("success"));
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}
finally
{
SafeDeleteAsset(prefabPath);
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
}
}
#endregion
#region Test Helpers
private static string CreateTestPrefab(string name)
{
EnsureFolder(TempDirectory);
GameObject temp = GameObject.CreatePrimitive(PrimitiveType.Cube);
temp.name = name;
string path = Path.Combine(TempDirectory, name + ".prefab").Replace('\\', '/');
PrefabUtility.SaveAsPrefabAsset(temp, path, out bool success);
UnityEngine.Object.DestroyImmediate(temp);
AssetDatabase.Refresh();
if (!success) throw new Exception($"Failed to create test prefab at {path}");
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
return path;
}
private static string CreateNestedTestPrefab(string name)
{
EnsureFolder(TempDirectory);
GameObject root = new GameObject(name);
GameObject child1 = new GameObject("Child1") { transform = { parent = root.transform } };
GameObject child2 = new GameObject("Child2") { transform = { parent = root.transform } };
GameObject grandchild = new GameObject("Grandchild") { transform = { parent = child1.transform } };
string path = Path.Combine(TempDirectory, name + ".prefab").Replace('\\', '/');
PrefabUtility.SaveAsPrefabAsset(root, path, out bool success);
UnityEngine.Object.DestroyImmediate(root);
AssetDatabase.Refresh();
if (!success) throw new Exception($"Failed to create nested test prefab at {path}");
return path;
}
private static string CreateComplexTestPrefab(string name)
{
// Creates: Vehicle (root with BoxCollider)
// - FrontWheel (Cube with MeshRenderer, BoxCollider)
// - BackWheel (Cube with MeshRenderer, BoxCollider)
// - Turret (empty)
// - Barrel (Cylinder with MeshRenderer, CapsuleCollider)
EnsureFolder(TempDirectory);
GameObject root = new GameObject(name);
root.AddComponent<BoxCollider>();
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
GameObject frontWheel = GameObject.CreatePrimitive(PrimitiveType.Cube);
frontWheel.name = "FrontWheel";
frontWheel.transform.parent = root.transform;
frontWheel.transform.localPosition = new Vector3(0, 0.5f, 1f);
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
GameObject backWheel = GameObject.CreatePrimitive(PrimitiveType.Cube);
backWheel.name = "BackWheel";
backWheel.transform.parent = root.transform;
backWheel.transform.localPosition = new Vector3(0, 0.5f, -1f);
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
GameObject turret = new GameObject("Turret");
turret.transform.parent = root.transform;
turret.transform.localPosition = new Vector3(0, 1f, 0);
GameObject barrel = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
barrel.name = "Barrel";
barrel.transform.parent = turret.transform;
barrel.transform.localPosition = new Vector3(0, 0, 1f);
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
string path = Path.Combine(TempDirectory, name + ".prefab").Replace('\\', '/');
PrefabUtility.SaveAsPrefabAsset(root, path, out bool success);
UnityEngine.Object.DestroyImmediate(root);
AssetDatabase.Refresh();
if (!success) throw new Exception($"Failed to create complex test prefab at {path}");
feat: Prefab Feature Updates (#611) * feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs) - Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info) - Add get_hierarchy: get prefab internal structure with pagination support - Add list_prefabs: search prefabs in project with optional name filtering - Extract PrefabUtilityHelper class for reusable prefab utility methods - Update Python tool descriptions and parameter documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Use correct API to save prefab stage changes Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with EditorSceneManager.SaveScene to properly save stage modifications. This fixes the issue where component additions were lost after closing the prefab stage. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: improve code quality and error handling - Add pagination constants (DefaultPageSize, MaxPageSize) - Extract SaveAndRefreshStage helper to reduce duplication - Change all user-facing messages to English - Add REQUIRED_PARAMS validation in Python - Split path parameter into prefab_path and folder_path for clarity - Improve error handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: Remove list_prefabs action and update related documentation * feat: Enhance prefab management with detailed parameter descriptions and new unlinking option * feat: Simplify prefab creation logic and unify logging for asset replacement * feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving * feat: Add PrefabUtilityHelper class with utility methods for prefab asset management * feat: Refactor action constants and enhance parameter validation in prefab management * feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic * fix: Fix searchInactive parameter and improve prefab management - Fix searchInactive not working correctly for child objects - Improve error message accuracy for object not found - Use Application.dataPath for reliable directory path resolution * feat: Add path validation and security checks for prefab operations * feat: Remove pagination from GetHierarchy method and simplify prefab retrieval * feat: Remove mode parameter from prefab management functions to simplify usage * fix: Improve path validation and replace logic in prefab management * feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval * fix: resolve Unknown pseudo class last-child USS warnings Unity UI Toolkit does not support the :last-child pseudo-class. Replace it with a .section-last class that is applied programmatically to the last section in each .section-stack container. Also moves the Configure All Detected Clients button to the bottom of the Client Configuration section and makes it auto-width. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: improve prefab stage save for automated workflows - Add force parameter to save_open_stage for automated workflows where isDirty may not be correctly set - Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving - Mark prefab stage scene dirty when modifying GameObjects in prefab mode - Skip save when no changes and force=false (prevents false dirty flag) The force parameter ensures reliable saving in CI/automation scenarios where Unity dirty tracking may be inconsistent with programmatic changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update prefab.py * refactor: remove unnecessary blank line before create function * feat: add info and hierarchy commands to prefab CLI for enhanced prefab management * feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-26 08:36:29 +08:00
return path;
}
#endregion
}
}