Initial commit
This commit is contained in:
62
Assets/Scripts/Editor/ResetParentTransform.cs
Normal file
62
Assets/Scripts/Editor/ResetParentTransform.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class ResetParentTransform : EditorWindow
|
||||
{
|
||||
[MenuItem("Tools/Reset Parent Transform")]
|
||||
public static void ShowWindow()
|
||||
{
|
||||
GetWindow<ResetParentTransform>("Reset Parent Transform");
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
GUILayout.Label("Reset Parent Transform", EditorStyles.boldLabel);
|
||||
|
||||
if (GUILayout.Button("Reset Transform for Selected Parent and Adjust Children"))
|
||||
{
|
||||
ResetTransform();
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetTransform()
|
||||
{
|
||||
if (Selection.activeGameObject == null)
|
||||
{
|
||||
Debug.LogWarning("No GameObject selected. Please select a GameObject in the hierarchy.");
|
||||
return;
|
||||
}
|
||||
|
||||
Transform parentTransform = Selection.activeGameObject.transform;
|
||||
|
||||
if (parentTransform.childCount == 0)
|
||||
{
|
||||
Debug.LogWarning("Selected GameObject has no children. Operation aborted.");
|
||||
return;
|
||||
}
|
||||
|
||||
List<Transform> children = new List<Transform>();
|
||||
foreach (Transform child in parentTransform)
|
||||
{
|
||||
children.Add(child);
|
||||
}
|
||||
|
||||
foreach (Transform child in children)
|
||||
{
|
||||
child.transform.parent = null;
|
||||
}
|
||||
|
||||
// Reset the parent's transform to default values
|
||||
parentTransform.localPosition = Vector3.zero;
|
||||
parentTransform.localRotation = Quaternion.identity;
|
||||
parentTransform.localScale = Vector3.one;
|
||||
|
||||
foreach (Transform child in children)
|
||||
{
|
||||
child.transform.parent = parentTransform;
|
||||
}
|
||||
|
||||
Debug.Log("Parent transform reset and children adjusted.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user