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().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); } } }