mirror of
https://github.com/AnnulusGames/Alchemy.git
synced 2025-01-22 08:18:51 -05:00
Add: handling of child objects
This commit is contained in:
parent
a482cb2afd
commit
855d0faa89
@ -4,6 +4,7 @@ using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Alchemy.Hierarchy;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Alchemy.Editor
|
||||
{
|
||||
@ -14,23 +15,51 @@ namespace Alchemy.Editor
|
||||
public void OnProcessScene(Scene scene, BuildReport report)
|
||||
{
|
||||
foreach (var obj in scene.GetRootGameObjects()
|
||||
.Select(x => x.GetComponent<HierarchyObject>())
|
||||
.SelectMany(x => x.GetComponentsInChildren<HierarchyObject>())
|
||||
.Where(x => x != null))
|
||||
{
|
||||
switch (obj.HierarchyObjectMode)
|
||||
{
|
||||
case HierarchyObjectMode.None: break;
|
||||
case HierarchyObjectMode.RemoveInPlayMode:
|
||||
obj.OnObjectRemoved();
|
||||
UnityEngine.Object.DestroyImmediate(obj.gameObject);
|
||||
OnObjectRemoved(obj);
|
||||
break;
|
||||
case HierarchyObjectMode.RemoveInBuild:
|
||||
if (EditorApplication.isPlaying) break;
|
||||
obj.OnObjectRemoved();
|
||||
UnityEngine.Object.DestroyImmediate(obj.gameObject);
|
||||
OnObjectRemoved(obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void OnObjectRemoved(HierarchyObject obj)
|
||||
{
|
||||
Transform root;
|
||||
while (true)
|
||||
{
|
||||
root = obj.transform.parent;
|
||||
if (root == null) goto LOOP_END;
|
||||
if (!root.TryGetComponent<HierarchyObject>(out var hierarchyObject)) goto LOOP_END;
|
||||
|
||||
switch (hierarchyObject.HierarchyObjectMode)
|
||||
{
|
||||
case HierarchyObjectMode.None:
|
||||
goto LOOP_END;
|
||||
case HierarchyObjectMode.RemoveInPlayMode:
|
||||
break;
|
||||
case HierarchyObjectMode.RemoveInBuild:
|
||||
if (EditorApplication.isPlaying) goto LOOP_END;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LOOP_END:
|
||||
foreach (Transform child in obj.transform)
|
||||
{
|
||||
child.SetParent(root);
|
||||
}
|
||||
|
||||
UnityEngine.Object.DestroyImmediate(obj.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,5 @@ namespace Alchemy.Hierarchy
|
||||
{
|
||||
[SerializeField] HierarchyObjectMode hierarchyObjectMode = HierarchyObjectMode.RemoveInBuild;
|
||||
public HierarchyObjectMode HierarchyObjectMode => hierarchyObjectMode;
|
||||
|
||||
public virtual void OnObjectRemoved() { }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user