using System.Collections; using System.Collections.Generic; using UnityEngine; public class grouping : MonoBehaviour { public static void off() { //print("OOOOOFFFFFFFFFFFF"); GameObject SEL = SceneModeManager.Selected; if (SEL.transform.Find("Group") != null) { Transform GROUP = SceneModeManager.Selected.transform.Find("Group"); foreach (Transform child in GROUP) { child.SetParent(SceneModeManager.Scene); if (SEL.transform.Find("Group") != null) Destroy(GROUP.gameObject); DOIT.SaveObjectPositionInData(child); } } } public static void Group(GameObject parent, GameObject child) { bool oknew = false; if (parent.transform.Find("Group") == null) { oknew = true; } else { if (Get.o2(parent.name, "Group").transform.Find(child.name) == null) { print("else====null"); oknew = true; } else { print("else====exist"); } } if (oknew) { Material mat = child.GetComponent().material; child.GetComponent().material = _G.GBT; Vector3 rot = parent.transform.eulerAngles; parent.transform.eulerAngles = new Vector3(0, 0, 0); Vector3 TARpos = child.transform.position; Quaternion TARrot = child.transform.rotation; Vector3 TARscale = child.transform.localScale; if (parent.transform.Find("Group") == null) { GameObject Group = new GameObject("Group"); Group.transform.SetParent(parent.transform, true); child.transform.SetParent(Group.transform, true); } else { GameObject Group = parent.transform.Find("Group").gameObject; Group.transform.SetParent(parent.transform, false); child.transform.SetParent(Group.transform, true); //child.transform.localPosition=TARpos; //child.transform.rotation=TARrot; } parent.transform.eulerAngles = rot; child.transform.rotation = TARrot; child.transform.position = TARpos; } } public static void Ungroup(GameObject parent) { if (parent.transform.Find("Group") != null) { GameObject GROUP = Get.o2(parent.name, "Group"); List objectToMove = new List(); foreach (Transform child in GROUP.transform) { objectToMove.Add(child); } foreach (Transform child in objectToMove) { child.SetParent(SceneModeManager.Scene); DOIT.SaveObjectPositionInData(child); //child.GetComponent().material = _G.INV; // need to remove the blue mat } if (parent.transform.Find("Group") != null) Destroy(GROUP); } //DOIT.AllSelOff(); } public static GameObject GetNewParent(GameObject parent) { GameObject newParent = null; Transform groupGameObject = parent.transform.Find("Group"); // need to check what hit what other if (groupGameObject == null) return null; foreach (Transform O in groupGameObject) { if (O.name != parent.name && DOIT.exist(Get.GetObjectIndex(O.name))) { if (O.GetComponent().Hit) { newParent = O.gameObject; break; } } } return newParent; } public static void SwitchBackParent(GameObject newParent) { Transform groupGameObject = newParent.transform.parent; if (groupGameObject.name != "Group") { return; } GameObject current = groupGameObject.transform.parent.gameObject; List gameObjects = new List { current }; foreach (Transform c in groupGameObject) { if (c.gameObject.name != newParent.name) { gameObjects.Add(c.gameObject); } } grouping.Ungroup(current); newParent.transform.parent = SceneModeManager.Scene; foreach (var g in gameObjects) { grouping.Group(newParent, g); } SceneModeManager.SelectedName = newParent.name; } public static void SwitchParent(GameObject parent) { GameObject newParent = GetNewParent(parent); if (newParent == null) return; Transform groupGameObject = parent.transform.Find("Group"); if (groupGameObject == null) return; List gameObjects = new List { parent }; foreach (Transform c in groupGameObject.transform) { if (c.gameObject.name != newParent.name) { gameObjects.Add(c.gameObject); } } grouping.Ungroup(parent); newParent.transform.parent = SceneModeManager.Scene; foreach (var g in gameObjects) { grouping.Group(newParent, g); } SceneModeManager.SelectedName = newParent.name; } }