-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: Prefab Feature Updates #611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dsarno
merged 26 commits into
CoplayDev:beta
from
whatevertogo:enhancement/Prefab-management
Jan 26, 2026
Merged
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
8b10c6f
feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs)
whatevertogo d0cb1ba
fix: Use correct API to save prefab stage changes
whatevertogo 94a78ec
refactor: improve code quality and error handling
whatevertogo 8493558
feat: Remove list_prefabs action and update related documentation
whatevertogo 5859fec
feat: Enhance prefab management with detailed parameter descriptions …
whatevertogo 6a59050
feat: Simplify prefab creation logic and unify logging for asset repl…
whatevertogo 943e7ad
feat: Update SaveStagePrefab method to use SetDirty and SaveAssets fo…
whatevertogo 228f9fb
feat: Add PrefabUtilityHelper class with utility methods for prefab a…
whatevertogo 2e61b21
feat: Refactor action constants and enhance parameter validation in p…
whatevertogo aac6ec8
feat: Update ValidateSourceObjectForPrefab method to remove replaceEx…
whatevertogo f44e1b3
fix: Fix searchInactive parameter and improve prefab management
whatevertogo 14e3847
feat: Add path validation and security checks for prefab operations
whatevertogo c21c860
feat: Remove pagination from GetHierarchy method and simplify prefab …
whatevertogo 40de0d0
feat: Remove mode parameter from prefab management functions to simpl…
whatevertogo 72de29d
fix: Improve path validation and replace logic in prefab management
whatevertogo d0c7135
feat: Enhance prefab management by adding nesting depth and parent pr…
whatevertogo aa8d358
Merge branch 'CoplayDev:beta' into enhancement/Prefab-management
whatevertogo b74cc00
fix: resolve Unknown pseudo class last-child USS warnings
dsarno f0a2cc5
Merge branch 'enhancement/Prefab-management' of https://github.com/wh…
dsarno 7c8d478
fix: improve prefab stage save for automated workflows
dsarno b1471de
Merge branch 'CoplayDev:beta' into enhancement/Prefab-management
whatevertogo 56a8d23
Merge pull request #1 from dsarno/fix/prefab-save-dialogs-and-force-p…
whatevertogo 2ccf8f1
Update prefab.py
whatevertogo e4d3c8c
refactor: remove unnecessary blank line before create function
whatevertogo f752290
feat: add info and hierarchy commands to prefab CLI for enhanced pref…
whatevertogo 1bcc6e1
feat: enhance prefab management with comprehensive CRUD tests and ens…
whatevertogo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using UnityEditor; | ||
| using UnityEngine; | ||
|
|
||
| namespace MCPForUnity.Editor.Helpers | ||
| { | ||
| /// <summary> | ||
| /// Provides common utility methods for working with Unity Prefab assets. | ||
| /// </summary> | ||
| public static class PrefabUtilityHelper | ||
| { | ||
| /// <summary> | ||
| /// Gets the GUID for a prefab asset path. | ||
| /// </summary> | ||
| /// <param name="assetPath">The Unity asset path (e.g., "Assets/Prefabs/MyPrefab.prefab")</param> | ||
| /// <returns>The GUID string, or null if the path is invalid.</returns> | ||
| public static string GetPrefabGUID(string assetPath) | ||
| { | ||
| if (string.IsNullOrEmpty(assetPath)) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| return AssetDatabase.AssetPathToGUID(assetPath); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| McpLog.Warn($"Failed to get GUID for asset path '{assetPath}': {ex.Message}"); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets variant information if the prefab is a variant. | ||
| /// </summary> | ||
| /// <param name="prefabAsset">The prefab GameObject to check.</param> | ||
| /// <returns>A tuple containing (isVariant, parentPath, parentGuid).</returns> | ||
| public static (bool isVariant, string parentPath, string parentGuid) GetVariantInfo(GameObject prefabAsset) | ||
| { | ||
| if (prefabAsset == null) | ||
| { | ||
| return (false, null, null); | ||
| } | ||
|
|
||
| try | ||
| { | ||
| PrefabAssetType assetType = PrefabUtility.GetPrefabAssetType(prefabAsset); | ||
| if (assetType != PrefabAssetType.Variant) | ||
| { | ||
| return (false, null, null); | ||
| } | ||
|
|
||
| GameObject parentAsset = PrefabUtility.GetCorrespondingObjectFromSource(prefabAsset); | ||
| if (parentAsset == null) | ||
| { | ||
| return (true, null, null); | ||
| } | ||
|
|
||
| string parentPath = AssetDatabase.GetAssetPath(parentAsset); | ||
| string parentGuid = GetPrefabGUID(parentPath); | ||
|
|
||
| return (true, parentPath, parentGuid); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| McpLog.Warn($"Failed to get variant info for '{prefabAsset.name}': {ex.Message}"); | ||
| return (false, null, null); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the list of component type names on a GameObject. | ||
| /// </summary> | ||
| /// <param name="obj">The GameObject to inspect.</param> | ||
| /// <returns>A list of component type full names.</returns> | ||
| public static List<string> GetComponentTypeNames(GameObject obj) | ||
| { | ||
| var typeNames = new List<string>(); | ||
|
|
||
| if (obj == null) | ||
| { | ||
| return typeNames; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| var components = obj.GetComponents<Component>(); | ||
| foreach (var component in components) | ||
| { | ||
| if (component != null) | ||
| { | ||
| typeNames.Add(component.GetType().FullName); | ||
| } | ||
| } | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| McpLog.Warn($"Failed to get component types for '{obj.name}': {ex.Message}"); | ||
| } | ||
|
|
||
| return typeNames; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Recursively counts all children in the hierarchy. | ||
| /// </summary> | ||
| /// <param name="transform">The root transform to count from.</param> | ||
| /// <returns>Total number of children in the hierarchy.</returns> | ||
| public static int CountChildrenRecursive(Transform transform) | ||
| { | ||
| if (transform == null) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| int count = transform.childCount; | ||
| for (int i = 0; i < transform.childCount; i++) | ||
| { | ||
| count += CountChildrenRecursive(transform.GetChild(i)); | ||
| } | ||
| return count; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the source prefab path for a nested prefab instance. | ||
| /// </summary> | ||
| /// <param name="gameObject">The GameObject to check.</param> | ||
| /// <returns>The asset path of the source prefab, or null if not a nested prefab.</returns> | ||
| public static string GetNestedPrefabPath(GameObject gameObject) | ||
| { | ||
| if (gameObject == null || !PrefabUtility.IsAnyPrefabInstanceRoot(gameObject)) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| var sourcePrefab = PrefabUtility.GetCorrespondingObjectFromSource(gameObject); | ||
| if (sourcePrefab != null) | ||
| { | ||
| return AssetDatabase.GetAssetPath(sourcePrefab); | ||
| } | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| McpLog.Warn($"Failed to get nested prefab path for '{gameObject.name}': {ex.Message}"); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.