Skip to content

Commit

Permalink
-update: debug play level directly in prefab level
Browse files Browse the repository at this point in the history
  • Loading branch information
aprius committed Nov 3, 2023
1 parent 7186c11 commit 972966f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
25 changes: 18 additions & 7 deletions Assets/Heart/Modules/LevelSystem/Runtime/LevelComponent.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Pancake.Apex;
using Pancake.Scriptable;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace Pancake.LevelSystem
{
Expand Down Expand Up @@ -50,16 +51,26 @@ protected virtual void OnDespawned()

#if UNITY_EDITOR

[Button]
private void PlayThisLevel()
[Button, ButtonHeight(30)]
public void PlayThisLevel()
{
LevelDebug.IsTest = true;
LevelDebug.PathLevelPrefab = UnityEditor.AssetDatabase.GetAssetPath(UnityEditor.Selection.activeGameObject);
if (UnityEditor.SceneManagement.EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
LevelDebug.LevelPrefab = null;
LevelDebug.PathLevelPrefab = UnityEditor.AssetDatabase.GetAssetPath(UnityEditor.Selection.activeGameObject);
if (!Application.isPlaying)
{
string path = UnityEngine.SceneManagement.SceneUtility.GetScenePathByBuildIndex(0);
UnityEditor.SceneManagement.EditorSceneManager.OpenScene(path, UnityEditor.SceneManagement.OpenSceneMode.Single);
UnityEditor.EditorApplication.isPlaying = true;
if (UnityEditor.SceneManagement.EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
{
string path = SceneUtility.GetScenePathByBuildIndex(0);
UnityEditor.SceneManagement.EditorSceneManager.OpenScene(path, UnityEditor.SceneManagement.OpenSceneMode.Single);
UnityEditor.EditorApplication.isPlaying = true;
}
}
else
{
// recreate
var levelInstantiate = FindObjectOfType<LevelInstantiate>();
levelInstantiate.OnReCreateLevelLoaded();
}
}
#endif
Expand Down
1 change: 1 addition & 0 deletions Assets/Heart/Modules/LevelSystem/Runtime/LevelDebug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static LevelComponent LevelPrefab
levelPrefab = AssetDatabase.LoadAssetAtPath<GameObject>(PathLevelPrefab)?.GetComponent<LevelComponent>();
return levelPrefab;
}
internal set => levelPrefab = value;
}

static LevelDebug() { EditorApplication.playModeStateChanged += OnPlayModeStateChanged; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Pancake.LevelSystem;
using Pancake.Scriptable;
using UnityEngine;

namespace Pancake.SceneFlow
namespace Pancake.LevelSystem
{
public class LevelInstantiate : GameComponent
{
Expand All @@ -19,10 +18,16 @@ public void Start()

protected override void OnDisabled() { reCreateLevelLoadedEvent.OnRaised -= OnReCreateLevelLoaded; }

private void OnReCreateLevelLoaded()
public void OnReCreateLevelLoaded()
{
root.RemoveAllChildren();
var _ = Instantiate(loadLevelCachedEvent.Raise(), root, false);
LevelComponent levelComponent = null;
#if UNITY_EDITOR
levelComponent = LevelDebug.IsTest ? LevelDebug.LevelPrefab : loadLevelCachedEvent.Raise();
#else
levelComponent = loadLevelCachedEvent.Raise();
#endif
var _ = Instantiate(levelComponent, root, false);
}
}
}
4 changes: 2 additions & 2 deletions Assets/_Root/Prefabs/Level/LevelNormal/Level_1.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: b4a2f3af39cf1cc449dc56c4adc5135b, type: 3}
m_Name:
m_EditorClassIdentifier:
originLevelIndex: 1
currentLevelIndex: 37
originLevelIndex: 0
currentLevelIndex: 0
winEvent: {fileID: 0}
loseEvent: {fileID: 0}
replayEvent: {fileID: 0}
Expand Down

0 comments on commit 972966f

Please sign in to comment.