�
���g�* � �8 � d dl mZ d dlmZmZ d dlmZ defd�Zy)� )�Optional)�FastMCP�Context)�get_unity_connection�mcpc �� � | j � ddt dt dt dt dt f
d�� }| j � ddt dt dt d t d
t dt dt d
t dt fd�� }| j � ddt dt dt dt dt f
d�� }| j � dt dt dt fd�� }y)z8Register all asset management tools with the MCP server.�ctx�source_path�target_path� overwrite�returnc � �� t � }|rt |t � sdS �rt �t � sdS ddl}|j j |� sd|� d�S dj
�j d� dd � }�j d� d }|j d ||xs d
d�� j dg � }t �fd
�|D � � } | r|sd�� d�S |j d|�|d�� }
|
j dd� sd|
j dd� � d|� d�� d�S |
j dd� S # t $ r}dt |� � d|� d�� d�cY d}~S d}~ww xY w)a� Import an asset (e.g., 3D model, texture) into the Unity project.
Args:
ctx: The MCP context
source_path: Path to the source file on disk
target_path: Path where the asset should be imported in the Unity project (relative to Assets folder)
overwrite: Whether to overwrite if an asset already exists at the target path (default: False)
Returns:
str: Success message or error details
z9Error importing asset: source_path must be a valid stringz9Error importing asset: target_path must be a valid stringr Nz$Error importing asset: Source file 'z' does not exist�/������GET_ASSET_LIST�Assets)�search_pattern�folder�assetsc 3 �F �K � | ] }|j d � �k( �� � y�w��pathN��get)�.0�assetr s ���C:\1_Sagyo\VRchat\Project\IshouJidouChouseiToul\Library\PackageCache\com.zundamonnovrchat.unity-mcp-ollama@994ecdcda9\Python\tools\asset_tools.py� <genexpr>z=register_asset_tools.<locals>.import_asset.<locals>.<genexpr>4 s �� �� �]�_�E�u�y�y��0�K�?�_�� �!zAsset already exists at '�$'. Use overwrite=True to replace it.�IMPORT_ASSET)r
r r �successFzError importing asset: �error�
Unknown errorz
(Source: z
, Target: �)�messagezAsset imported successfully)r �
isinstance�str�osr �exists�join�split�send_commandr �any� Exception)r r
r r �unityr) �
target_dir�target_filename�existing_assets�asset_exists�response�es ` r �import_assetz*register_asset_tools.<locals>.import_asset s� �� �$) e�(�*�E� �j��c�&B�R�S��j��c�&B�R�S�
��7�7�>�>�+�.�=�k�]�JZ�[�[� ���+�"3�"3�C�"8��"�"=�>�J�)�/�/��4�R�8�O� $�0�0�1A�"1�$�0��D� � �s�8�R� �
� �]�_�]�]�L��I�2�;�-�?c�d�d��)�)�.�*�*�&�;� �H� �<�<� �5�1�0����g��1W�0X�Xb�cn�bo�oy� {F� zG� GH� I� I��<�<� �+H�I�I��� e�,�S��V�H�J�{�m�:�Va�Ub�bc�d�d�� e�s; �D. �D. �$D. �A=D. �AD. �D. �. E�7E�E�E�prefab_path�
position_x�
position_y�
position_z�
rotation_x�
rotation_y�
rotation_zc � �� t � }�rt �t � sdS ||||||d�} | j � D ]# \ }
}t |t t
f� r�d|
� d�c S dj
�j d� dd � xs d}�j d� d }
|
j � j d � s
|
� d �}
�� d ��|j d
d|
|d�� j d
g � }t �fd�|D � � }|sd�� d�S |j d�||||||d�� }|j dd� sd|j dd� � d�� d�S d|j dd� � d�S # t $ r}dt |� � d�� d�cY d}~S d}~ww xY w)a� Instantiate a prefab into the current scene at a specified location.
Args:
ctx: The MCP context
prefab_path: Path to the prefab asset (relative to Assets folder)
position_x: X position in world space (default: 0.0)
position_y: Y position in world space (default: 0.0)
position_z: Z position in world space (default: 0.0)
rotation_x: X rotation in degrees (default: 0.0)
rotation_y: Y rotation in degrees (default: 0.0)
rotation_z: Z rotation in degrees (default: 0.0)
Returns:
str: Success message or error details
z>Error instantiating prefab: prefab_path must be a valid string)r9 r: r; r<