mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-01-19 21:00:08 +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()
|
||||
{
|
||||
if (EditorApplication.isPlayingOrWillChangePlaymode) return;
|
||||
|
||||
EditorApplication.delayCall += () =>
|
||||
{
|
||||
if (this == null) return;
|
||||
|
||||
gameObject.hideFlags = HideFlags.HideInHierarchy;
|
||||
gameObject.hideFlags = HIDE_FLAGS;
|
||||
if (!HasMAComponentsInScene())
|
||||
{
|
||||
var scene = gameObject.scene;
|
||||
@ -75,24 +77,34 @@ namespace nadena.dev.modular_avatar.core
|
||||
if (!scene.IsValid() || EditorSceneManager.IsPreviewScene(scene)) return;
|
||||
if (EditorApplication.isPlayingOrWillChangePlaymode) return;
|
||||
|
||||
bool rootPresent = false;
|
||||
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();
|
||||
try
|
||||
{
|
||||
SceneManager.SetActiveScene(scene);
|
||||
var gameObject = new GameObject(TAG_OBJECT_NAME);
|
||||
gameObject.AddComponent<Activator>();
|
||||
gameObject.hideFlags = HideFlags.HideInHierarchy;
|
||||
gameObject.hideFlags = HIDE_FLAGS;
|
||||
}
|
||||
finally
|
||||
{
|
||||
SceneManager.SetActiveScene(oldActiveScene);
|
||||
}
|
||||
}
|
||||
|
||||
private const HideFlags HIDE_FLAGS = HideFlags.HideInHierarchy;
|
||||
}
|
||||
|
||||
[AddComponentMenu("")]
|
||||
|
Loading…
Reference in New Issue
Block a user