using UnityEngine;
using UnityEditor;

public class SwapYAndZCoordinates : EditorWindow
{
    [MenuItem("Tools/Swap Y and Z Coordinates")]
    public static void ShowWindow()
    {
        GetWindow<SwapYAndZCoordinates>("Swap Y and Z Coordinates");
    }

    private void OnGUI()
    {
        GUILayout.Label("Swap Y and Z Coordinates", EditorStyles.boldLabel);

        if (GUILayout.Button("Swap Y and Z for Selected Object and Children"))
        {
            SwapCoordinates();
        }
    }

    private void SwapCoordinates()
    {
        if (Selection.activeGameObject == null)
        {
            Debug.LogWarning("No GameObject selected. Please select a GameObject in the hierarchy.");
            return;
        }

        Transform selectedTransform = Selection.activeGameObject.transform;
        SwapYAndZRecursive(selectedTransform);
    }

    private void SwapYAndZRecursive(Transform parentTransform)
    {
        foreach (Transform child in parentTransform)
        {
            SwapYAndZRecursive(child);
        }

        // Swap the position's Y and Z, and invert the Z-axis
        Vector3 newPosition = parentTransform.localPosition;
        newPosition = new Vector3(newPosition.x, newPosition.z, -newPosition.y);
        parentTransform.localPosition = newPosition;

        // Swap the rotation's Y and Z, and rotate by -90 degrees on the X-axis
        // Vector3 newRotation = parentTransform.localEulerAngles;
        // newRotation = new Vector3(newRotation.x - 90, newRotation.z, newRotation.y);
        // parentTransform.localEulerAngles = newRotation;

        // // Swap the scale's Y and Z, and invert the Z-axis
        // Vector3 newScale = parentTransform.localScale;
        // newScale = new Vector3(newScale.x, newScale.z, -newScale.y);
        // parentTransform.localScale = newScale;
    }
}