mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 19:34:47 +00:00
49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
|
using UnityEngine;
|
||
|
using UnityEngine.SceneManagement;
|
||
|
using UnityEngine.EventSystems;
|
||
|
|
||
|
namespace HPJ.Examples
|
||
|
{
|
||
|
public class SceneLoader : MonoBehaviour
|
||
|
{
|
||
|
private void Update()
|
||
|
{
|
||
|
if (EventSystem.current.currentSelectedGameObject != null)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (Input.GetKeyDown(KeyCode.KeypadMinus))
|
||
|
{
|
||
|
LoadPreviousScene();
|
||
|
}
|
||
|
else if (Input.GetKeyDown(KeyCode.KeypadPlus))
|
||
|
{
|
||
|
LoadNextScene();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void LoadNextScene()
|
||
|
{
|
||
|
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
|
||
|
int nextSceneIndex = currentSceneIndex + 1;
|
||
|
if (nextSceneIndex == SceneManager.sceneCountInBuildSettings)
|
||
|
{
|
||
|
nextSceneIndex = 0;
|
||
|
}
|
||
|
SceneManager.LoadScene(nextSceneIndex);
|
||
|
}
|
||
|
|
||
|
public void LoadPreviousScene()
|
||
|
{
|
||
|
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
|
||
|
int previousSceneIndex = currentSceneIndex - 1;
|
||
|
if (previousSceneIndex < 0)
|
||
|
{
|
||
|
previousSceneIndex = SceneManager.sceneCountInBuildSettings - 1;
|
||
|
}
|
||
|
SceneManager.LoadScene(previousSceneIndex);
|
||
|
}
|
||
|
}
|
||
|
}
|