�
���gN � �H � d Z ddlmZmZmZmZ ddlmZmZ ddl m
Z
defd�Zy)z4Tools for inspecting and manipulating Unity objects.� )�Optional�List�Dict�Any)�FastMCP�Context)�get_unity_connection�mcpc � � | j � dt dt dt t t f fd�� }| j � dt dt dt dt t t f fd�� }| j � dt dt dt
t t t f fd�� }| j � dt d t dt
t t t f fd
�� }| j � dt dt t t f fd�� }| j � dt dt t t f fd�� }| j � dt dt dt t t f fd
�� }| j � dt dt t t t f fd�� }| j � ddt dt t dt dt dt
t t t f f
d�� } y)zJRegister all object inspection and manipulation tools with the MCP server.�ctx�name�returnc � � t � j dd|i� }|S # t $ r}ddt |� � �icY d}~S d}~ww xY w)a Get all properties of a specified game object.
Args:
ctx: The MCP context
name: Name of the game object to inspect
Returns:
Dict containing the object's properties, components, and their values
�GET_OBJECT_PROPERTIESr
�errorz!Failed to get object properties: N�r �send_command� Exception�str�r r
�response�es ��C:\1_Sagyo\VRchat\Project\IshouJidouChouseiToul\Library\PackageCache\com.zundamonnovrchat.unity-mcp-ollama@994ecdcda9\Python\tools\object_tools.py�get_object_propertiesz4register_object_tools.<locals>.get_object_properties
sY � � K�+�-�:�:�;R���U� �H� �O��� K��@��Q���I�J�J�� K�� � � A�>�A�A�object_name�component_typec � � t � j d||d�� }|S # t $ r}ddt |� � �icY d}~S d}~ww xY w)a9 Get properties of a specific component on a game object.
Args:
ctx: The MCP context
object_name: Name of the game object
component_type: Type of the component to inspect
Returns:
Dict containing the component's properties and their values
�GET_COMPONENT_PROPERTIES)r r r z$Failed to get component properties: Nr )r r r r r s r �get_component_propertiesz7register_object_tools.<locals>.get_component_properties sZ � � N�+�-�:�:�;U�*�"0�X� �H� �O��� N��C�C��F�8�L�M�M�� N�s �! � A�?�A�Ac � � t � j dd|i� }|j dg � S # t $ r}ddt |� � �igcY d}~S d}~ww xY w)z�Find game objects in the scene by name.
Args:
ctx: The MCP context
name: Name to search for (partial matches are supported)
Returns:
List of dicts containing object names and their paths
�FIND_OBJECTS_BY_NAMEr
�objectsr �Failed to find objects: N�r r �getr r r s r �find_objects_by_namez3register_object_tools.<locals>.find_objects_by_name9 sh � � D�+�-�:�:�;Q���T� �H� �<�<� �2�.�.��� D�� 8��Q���A�B�C�C�� D�� �-0 � A�A� A�A�tagc � � t � j dd|i� }|j dg � S # t $ r}ddt |� � �igcY d}~S d}~ww xY w)z�Find game objects in the scene by tag.
Args:
ctx: The MCP context
tag: Tag to search for
Returns:
List of dicts containing object names and their paths
�FIND_OBJECTS_BY_TAGr) r# r r$ Nr% )r r) r r s r �find_objects_by_tagz2register_object_tools.<locals>.find_objects_by_tagO sh � � D�+�-�:�:�;P��s�S� �H� �<�<� �2�.�.��� D�� 8��Q���A�B�C�C�� D�r( c � � t � j d� }|S # t $ r}ddt |� � �icY d}~S d}~ww xY w)z�Get information about the current scene.
Args:
ctx: The MCP context
Returns:
Dict containing scene information including name and root objects
�GET_SCENE_INFOr zFailed to get scene info: Nr �r r r s r �get_scene_infoz-register_object_tools.<locals>.get_scene_infoe sJ � � D�+�-�:�:�;K�L�H��O��� D��9�#�a�&��B�C�C�� D�� � � A �;�A �A c � � t � j d� }|S # t $ r}ddt |� � �icY d}~S d}~ww xY w)z�Get the current hierarchy of game objects in the scene.
Args:
ctx: The MCP context
Returns:
Dict containing the scene hierarchy as a tree structure
�
GET_HIERARCHYr zFailed to get hierarchy: Nr r/ s r �
get_hierarchyz,register_object_tools.<locals>.get_hierarchyu sI � � C�+�-�:�:�?�K�H��O��� C��8��Q���A�B�B�� C�r1 c � � t � j dd|i� }|S # t $ r}ddt |� � �icY d}~S d}~ww xY w)z�Select a game object in the Unity Editor.
Args:
ctx: The MCP context
name: Name of the object to select
Returns:
Dict containing the name of the selected object
�
SELECT_OBJECTr
r zFailed to select object: Nr r s r �
select_objectz,register_object_tools.<locals>.select_object� sX � � C�+�-�:�:�?���M� �H� �O��� C��8��Q���A�B�B�� C�r c � � t � j d� }|j d� S # t $ r}ddt |� � �icY d}~S d}~ww xY w)z�Get the currently selected game object in the Unity Editor.
Args:
ctx: The MCP context
Returns:
Dict containing the selected object's name and path, or None if no object is selected
�GET_SELECTED_OBJECT�selectedr zFailed to get selected object: Nr% r/ s r �get_selected_objectz2register_object_tools.<locals>.get_selected_object� sT � � I�+�-�:�:�;P�Q�H��<�<�
�+�+��� I��>�s�1�v�h�G�H�H�� I�s �), � A�A
�A�
AN�type�search_pattern�folderc � � t � j d|||d�� }|j dg � S # t $ r}ddt |� � �igcY d}~S d}~ww xY w)aV Get a list of assets in the project.
Args:
ctx: The MCP context
type: Optional asset type to filter by
search_pattern: Pattern to search for in asset names
folder: Folder to search in (default: "Assets")
Returns:
List of dicts containing asset information
�GET_ASSET_LIST)r<