Files
VR-WuKong/Assets/ThirdParty/Tools/SetGroup/Editor/SetGroupEditor.cs

48 lines
1.0 KiB
C#
Raw Normal View History

2025-11-14 18:44:06 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(SetGroup))]
public class SetGroupEditor : Editor
{
SetGroup inst;
private void OnEnable()
{
inst = (SetGroup)target;
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
//
if(GUILayout.Button("SetGroup", GUILayout.Height(50)))
{
AAA();
}
}
void AAA()
{
GameObject[] curObjects = Selection.gameObjects;
Vector3 centerPos = Vector3.zero;
foreach (GameObject obj in curObjects)
{
centerPos += obj.GetComponent<MeshRenderer>().bounds.center;
}
centerPos /= curObjects.Length;
//
GameObject parent = new GameObject(inst.namee);
parent.transform.position = centerPos;
parent.transform.SetParent(inst.root);
foreach (GameObject obj in curObjects)
{
obj.transform.SetParent(parent.transform);
}
}
}