Closed joaquingrech closed 1 year ago
This is a little bit hacky, and I didn't test it too much, but seems like following approach will work:
using Battlehub.RTCommon;
using UnityEngine;
namespace Battlehub.RTEditor.Examples
{
public class SetObjectRoot : EditorExtension
{
private IRTE m_rte;
[SerializeField]
private GameObject m_root;
protected override void OnInit()
{
base.OnInit();
m_rte = IOC.Resolve<IRTE>();
m_rte.Object.Started += Object_Started;
}
protected override void OnDestroy()
{
base.OnDestroy();
m_rte.Object.Started -= Object_Started;
}
private void Object_Started(ExposeToEditor obj)
{
if (obj.transform.parent == null)
{
obj.transform.SetParent(m_root.transform, true);
}
}
}
}
Is there a way to select a root gameobject as the parent for everything you do in the editor? This means that if I create anything new, duplicate, or whatever, instead of being at the root of the unity hierarchy, it would all be under my "root" gameobject.