mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-02-01 03:02:56 +08:00
fix: multiple bugs in Activator
* Activator tries to mark scene dirty in play mode (fixes #164) * Activator creates multiple hidden objects which build up over time
This commit is contained in:
parent
39be252f12
commit
5351b7befb
@ -56,11 +56,13 @@ namespace nadena.dev.modular_avatar.core
|
|||||||
|
|
||||||
private void OnValidate()
|
private void OnValidate()
|
||||||
{
|
{
|
||||||
|
if (EditorApplication.isPlayingOrWillChangePlaymode) return;
|
||||||
|
|
||||||
EditorApplication.delayCall += () =>
|
EditorApplication.delayCall += () =>
|
||||||
{
|
{
|
||||||
if (this == null) return;
|
if (this == null) return;
|
||||||
|
|
||||||
gameObject.hideFlags = HideFlags.HideInHierarchy;
|
gameObject.hideFlags = HIDE_FLAGS;
|
||||||
if (!HasMAComponentsInScene())
|
if (!HasMAComponentsInScene())
|
||||||
{
|
{
|
||||||
var scene = gameObject.scene;
|
var scene = gameObject.scene;
|
||||||
@ -75,24 +77,34 @@ namespace nadena.dev.modular_avatar.core
|
|||||||
if (!scene.IsValid() || EditorSceneManager.IsPreviewScene(scene)) return;
|
if (!scene.IsValid() || EditorSceneManager.IsPreviewScene(scene)) return;
|
||||||
if (EditorApplication.isPlayingOrWillChangePlaymode) return;
|
if (EditorApplication.isPlayingOrWillChangePlaymode) return;
|
||||||
|
|
||||||
|
bool rootPresent = false;
|
||||||
foreach (var root in scene.GetRootGameObjects())
|
foreach (var root in scene.GetRootGameObjects())
|
||||||
{
|
{
|
||||||
if (root.GetComponent<Activator>() != null) return;
|
if (root.GetComponent<Activator>() != null)
|
||||||
|
{
|
||||||
|
root.hideFlags = HIDE_FLAGS;
|
||||||
|
if (rootPresent) DestroyImmediate(root);
|
||||||
|
rootPresent = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rootPresent) return;
|
||||||
|
|
||||||
var oldActiveScene = SceneManager.GetActiveScene();
|
var oldActiveScene = SceneManager.GetActiveScene();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SceneManager.SetActiveScene(scene);
|
SceneManager.SetActiveScene(scene);
|
||||||
var gameObject = new GameObject(TAG_OBJECT_NAME);
|
var gameObject = new GameObject(TAG_OBJECT_NAME);
|
||||||
gameObject.AddComponent<Activator>();
|
gameObject.AddComponent<Activator>();
|
||||||
gameObject.hideFlags = HideFlags.HideInHierarchy;
|
gameObject.hideFlags = HIDE_FLAGS;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
SceneManager.SetActiveScene(oldActiveScene);
|
SceneManager.SetActiveScene(oldActiveScene);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private const HideFlags HIDE_FLAGS = HideFlags.HideInHierarchy;
|
||||||
}
|
}
|
||||||
|
|
||||||
[AddComponentMenu("")]
|
[AddComponentMenu("")]
|
||||||
|
Loading…
Reference in New Issue
Block a user