Add random room route system
This commit is contained in:
6
.vsconfig
Normal file
6
.vsconfig
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0",
|
||||||
|
"components": [
|
||||||
|
"Microsoft.VisualStudio.Workload.ManagedGame"
|
||||||
|
]
|
||||||
|
}
|
||||||
8
Assets/01_Scenes/test.meta
Normal file
8
Assets/01_Scenes/test.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1c8e12991b4e9da4cae8a152c52eadba
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
BIN
Assets/01_Scenes/test/1.unity
LFS
Normal file
BIN
Assets/01_Scenes/test/1.unity
LFS
Normal file
Binary file not shown.
7
Assets/01_Scenes/test/1.unity.meta
Normal file
7
Assets/01_Scenes/test/1.unity.meta
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 35897533394ad724cab0afd3b3bea74b
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
BIN
Assets/01_Scenes/test/2.unity
LFS
Normal file
BIN
Assets/01_Scenes/test/2.unity
LFS
Normal file
Binary file not shown.
7
Assets/01_Scenes/test/2.unity.meta
Normal file
7
Assets/01_Scenes/test/2.unity.meta
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 70194d04fb069be4b84ec6f17a5041cc
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
BIN
Assets/01_Scenes/test/3.unity
LFS
Normal file
BIN
Assets/01_Scenes/test/3.unity
LFS
Normal file
Binary file not shown.
7
Assets/01_Scenes/test/3.unity.meta
Normal file
7
Assets/01_Scenes/test/3.unity.meta
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 44d13b2a5a7bee0409f1a5c7d0486e35
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
BIN
Assets/01_Scenes/test/4.unity
LFS
Normal file
BIN
Assets/01_Scenes/test/4.unity
LFS
Normal file
Binary file not shown.
7
Assets/01_Scenes/test/4.unity.meta
Normal file
7
Assets/01_Scenes/test/4.unity.meta
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: fda7347beb006a24fafc02220fe9d5f5
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
BIN
Assets/01_Scenes/test/test.unity
LFS
Normal file
BIN
Assets/01_Scenes/test/test.unity
LFS
Normal file
Binary file not shown.
7
Assets/01_Scenes/test/test.unity.meta
Normal file
7
Assets/01_Scenes/test/test.unity.meta
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9cb5c840e1b895a4d81a65fe59250140
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
18
Assets/02_Scripts/Managers/RoomMoveButton.cs
Normal file
18
Assets/02_Scripts/Managers/RoomMoveButton.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class RoomMoveButton : MonoBehaviour
|
||||||
|
{
|
||||||
|
[Header("이 버튼을 눌렀을 때 이동할 방 번호 입력")]
|
||||||
|
[SerializeField] private int targetRoomNumber;
|
||||||
|
|
||||||
|
public void OnClickMoveRoom()
|
||||||
|
{
|
||||||
|
if (RoomRouteManager.Instance == null)
|
||||||
|
{
|
||||||
|
Debug.LogError("RoomRouteManager가 없습니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RoomRouteManager.Instance.MoveToRoom(targetRoomNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
2
Assets/02_Scripts/Managers/RoomMoveButton.cs.meta
Normal file
2
Assets/02_Scripts/Managers/RoomMoveButton.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8eb4311a25437fd468487f681f4662e3
|
||||||
92
Assets/02_Scripts/Managers/RoomRouteDebugTester.cs
Normal file
92
Assets/02_Scripts/Managers/RoomRouteDebugTester.cs
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.InputSystem;
|
||||||
|
|
||||||
|
public class RoomRouteDebugTester : MonoBehaviour
|
||||||
|
{
|
||||||
|
private List<RoomRouteManager.RoomData> currentChoices =
|
||||||
|
new List<RoomRouteManager.RoomData>();
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
if (RoomRouteManager.Instance == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Keyboard.current == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// C키: 방문 안 한 방 중 랜덤 후보 뽑기
|
||||||
|
if (Keyboard.current.cKey.wasPressedThisFrame)
|
||||||
|
{
|
||||||
|
currentChoices = RoomRouteManager.Instance.GetRandomNextRooms();
|
||||||
|
|
||||||
|
Debug.Log($"현재 선택 가능한 후보 개수: {currentChoices.Count}");
|
||||||
|
|
||||||
|
for (int i = 0; i < currentChoices.Count; i++)
|
||||||
|
{
|
||||||
|
Debug.Log($"{i + 1}번 선택지 → 방 번호: {currentChoices[i].roomNumber}, 씬 이름: {currentChoices[i].sceneName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1키: 첫 번째 후보 선택
|
||||||
|
if (Keyboard.current.digit1Key.wasPressedThisFrame)
|
||||||
|
{
|
||||||
|
MoveToChoice(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2키: 두 번째 후보 선택
|
||||||
|
if (Keyboard.current.digit2Key.wasPressedThisFrame)
|
||||||
|
{
|
||||||
|
MoveToChoice(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// T키: 방문 상태 확인
|
||||||
|
if (Keyboard.current.tKey.wasPressedThisFrame)
|
||||||
|
{
|
||||||
|
Debug.Log($"방문한 방 개수: {RoomRouteManager.Instance.VisitedRoomCount} / {RoomRouteManager.Instance.TotalRoomCount}");
|
||||||
|
Debug.Log($"현재 방 번호: {RoomRouteManager.Instance.CurrentRoomNumber}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// X키: 테스트용 방문 기록 초기화
|
||||||
|
if (Keyboard.current.xKey.wasPressedThisFrame)
|
||||||
|
{
|
||||||
|
Debug.Log("방문 기록 초기화");
|
||||||
|
currentChoices.Clear();
|
||||||
|
RoomRouteManager.Instance.ResetVisitedRooms();
|
||||||
|
}
|
||||||
|
|
||||||
|
// F키: 모든 방 방문 후 마지막 씬 이동 테스트
|
||||||
|
if (Keyboard.current.fKey.wasPressedThisFrame)
|
||||||
|
{
|
||||||
|
Debug.Log("마지막 씬 이동 테스트");
|
||||||
|
RoomRouteManager.Instance.MoveToFinalScene();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MoveToChoice(int index)
|
||||||
|
{
|
||||||
|
if (currentChoices == null || currentChoices.Count == 0)
|
||||||
|
{
|
||||||
|
Debug.LogWarning("먼저 C키를 눌러 랜덤 후보를 뽑아야 합니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index < 0 || index >= currentChoices.Count)
|
||||||
|
{
|
||||||
|
Debug.LogWarning("해당 번호의 선택지가 없습니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int targetRoomNumber = currentChoices[index].roomNumber;
|
||||||
|
|
||||||
|
Debug.Log($"{index + 1}번 선택지 선택 → 방 {targetRoomNumber} 이동");
|
||||||
|
|
||||||
|
currentChoices.Clear();
|
||||||
|
|
||||||
|
RoomRouteManager.Instance.MoveToRoom(targetRoomNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
2
Assets/02_Scripts/Managers/RoomRouteDebugTester.cs.meta
Normal file
2
Assets/02_Scripts/Managers/RoomRouteDebugTester.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9e414802b02a03e469c541b086f805bb
|
||||||
219
Assets/02_Scripts/Managers/RoomRouteManager.cs
Normal file
219
Assets/02_Scripts/Managers/RoomRouteManager.cs
Normal file
@@ -0,0 +1,219 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class RoomRouteManager : MonoBehaviour
|
||||||
|
{
|
||||||
|
public static RoomRouteManager Instance;
|
||||||
|
|
||||||
|
[System.Serializable]
|
||||||
|
public class RoomData
|
||||||
|
{
|
||||||
|
[Header("방 번호 입력")]
|
||||||
|
public int roomNumber;
|
||||||
|
|
||||||
|
[Header("이 방에 해당하는 Scene 이름 입력")]
|
||||||
|
public string sceneName;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Header("전체 방 정보 입력")]
|
||||||
|
[SerializeField] private List<RoomData> rooms = new List<RoomData>();
|
||||||
|
|
||||||
|
[Header("시작 방 번호 입력")]
|
||||||
|
[SerializeField] private int startRoomNumber;
|
||||||
|
|
||||||
|
[Header("랜덤 선택지 개수")]
|
||||||
|
[SerializeField] private int randomChoiceCount = 2;
|
||||||
|
|
||||||
|
[Header("모든 방 방문 후 이동할 마지막 Scene 이름")]
|
||||||
|
[SerializeField] private string finalSceneName;
|
||||||
|
|
||||||
|
private int _currentRoomNumber;
|
||||||
|
private readonly HashSet<int> _visitedRooms = new HashSet<int>();
|
||||||
|
|
||||||
|
public int CurrentRoomNumber => _currentRoomNumber;
|
||||||
|
public int VisitedRoomCount => _visitedRooms.Count;
|
||||||
|
public int TotalRoomCount => rooms.Count;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
if (Instance == null)
|
||||||
|
{
|
||||||
|
Instance = this;
|
||||||
|
DontDestroyOnLoad(gameObject);
|
||||||
|
|
||||||
|
_currentRoomNumber = startRoomNumber;
|
||||||
|
|
||||||
|
if (startRoomNumber != 0)
|
||||||
|
{
|
||||||
|
_visitedRooms.Add(startRoomNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Destroy(gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 방문하지 않은 방 전체 반환
|
||||||
|
public List<RoomData> GetUnvisitedRooms()
|
||||||
|
{
|
||||||
|
List<RoomData> result = new List<RoomData>();
|
||||||
|
|
||||||
|
foreach (RoomData room in rooms)
|
||||||
|
{
|
||||||
|
if (!_visitedRooms.Contains(room.roomNumber))
|
||||||
|
{
|
||||||
|
result.Add(room);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 대화 선택지에 보여줄 랜덤 방 목록 반환
|
||||||
|
public List<RoomData> GetRandomNextRooms()
|
||||||
|
{
|
||||||
|
List<RoomData> unvisitedRooms = GetUnvisitedRooms();
|
||||||
|
List<RoomData> randomRooms = new List<RoomData>();
|
||||||
|
|
||||||
|
int count = Mathf.Min(randomChoiceCount, unvisitedRooms.Count);
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
int randomIndex = Random.Range(0, unvisitedRooms.Count);
|
||||||
|
|
||||||
|
randomRooms.Add(unvisitedRooms[randomIndex]);
|
||||||
|
unvisitedRooms.RemoveAt(randomIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return randomRooms;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 버튼이나 대화 선택지에서 호출
|
||||||
|
public void MoveToRoom(int roomNumber)
|
||||||
|
{
|
||||||
|
if (SceneLoadManager.Instance == null)
|
||||||
|
{
|
||||||
|
Debug.LogError("SceneLoadManager가 씬에 없습니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SceneLoadManager.Instance.IsChangingScene)
|
||||||
|
{
|
||||||
|
Debug.Log("이미 씬 이동 중입니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RoomData targetRoom = GetRoomData(roomNumber);
|
||||||
|
|
||||||
|
if (targetRoom == null)
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"방 정보를 찾을 수 없습니다. 방 번호: {roomNumber}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_visitedRooms.Contains(roomNumber))
|
||||||
|
{
|
||||||
|
Debug.Log($"이미 방문한 방입니다. 방 번호: {roomNumber}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(targetRoom.sceneName))
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"방 {roomNumber}의 Scene 이름이 비어있습니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_currentRoomNumber = roomNumber;
|
||||||
|
_visitedRooms.Add(roomNumber);
|
||||||
|
|
||||||
|
SceneLoadManager.Instance.RequestSceneChange(targetRoom.sceneName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 랜덤 방 하나로 바로 이동하고 싶을 때 사용
|
||||||
|
public void MoveToRandomRoom()
|
||||||
|
{
|
||||||
|
List<RoomData> unvisitedRooms = GetUnvisitedRooms();
|
||||||
|
|
||||||
|
if (unvisitedRooms.Count <= 0)
|
||||||
|
{
|
||||||
|
Debug.Log("방문하지 않은 방이 없습니다.");
|
||||||
|
|
||||||
|
if (IsAllRoomsVisited())
|
||||||
|
{
|
||||||
|
MoveToFinalScene();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int randomIndex = Random.Range(0, unvisitedRooms.Count);
|
||||||
|
RoomData randomRoom = unvisitedRooms[randomIndex];
|
||||||
|
|
||||||
|
MoveToRoom(randomRoom.roomNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsAllRoomsVisited()
|
||||||
|
{
|
||||||
|
return rooms.Count > 0 && _visitedRooms.Count >= rooms.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MoveToFinalScene()
|
||||||
|
{
|
||||||
|
if (!IsAllRoomsVisited())
|
||||||
|
{
|
||||||
|
Debug.Log("아직 모든 방을 방문하지 않았습니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SceneLoadManager.Instance == null)
|
||||||
|
{
|
||||||
|
Debug.LogError("SceneLoadManager가 씬에 없습니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SceneLoadManager.Instance.IsChangingScene)
|
||||||
|
{
|
||||||
|
Debug.Log("이미 씬 이동 중입니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(finalSceneName))
|
||||||
|
{
|
||||||
|
Debug.LogWarning("마지막 Scene 이름이 비어있습니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SceneLoadManager.Instance.RequestSceneChange(finalSceneName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsVisitedRoom(int roomNumber)
|
||||||
|
{
|
||||||
|
return _visitedRooms.Contains(roomNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResetVisitedRooms()
|
||||||
|
{
|
||||||
|
_visitedRooms.Clear();
|
||||||
|
|
||||||
|
_currentRoomNumber = startRoomNumber;
|
||||||
|
|
||||||
|
if (startRoomNumber != 0)
|
||||||
|
{
|
||||||
|
_visitedRooms.Add(startRoomNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private RoomData GetRoomData(int roomNumber)
|
||||||
|
{
|
||||||
|
foreach (RoomData room in rooms)
|
||||||
|
{
|
||||||
|
if (room.roomNumber == roomNumber)
|
||||||
|
{
|
||||||
|
return room;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
2
Assets/02_Scripts/Managers/RoomRouteManager.cs.meta
Normal file
2
Assets/02_Scripts/Managers/RoomRouteManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0a9c2a7a081e65e43806d1ecb3cca28c
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
public class SceneLoadManager : MonoBehaviour
|
public class SceneLoadManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
public static SceneLoadManager Instance;
|
public static SceneLoadManager Instance;
|
||||||
@@ -9,16 +10,20 @@ public class SceneLoadManager : MonoBehaviour
|
|||||||
[SerializeField] private Camera _loadingCam;
|
[SerializeField] private Camera _loadingCam;
|
||||||
[SerializeField] private Transform _loadingCamTargetTransform;
|
[SerializeField] private Transform _loadingCamTargetTransform;
|
||||||
|
|
||||||
|
private bool _isChangingScene = false;
|
||||||
|
|
||||||
|
public bool IsChangingScene => _isChangingScene;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
if (Instance == null)
|
if (Instance == null)
|
||||||
{
|
{
|
||||||
Instance = this; //만들어진 자신을 인스턴스로 설정
|
Instance = this; // 만들어진 자신을 인스턴스로 설정
|
||||||
DontDestroyOnLoad(gameObject);
|
DontDestroyOnLoad(gameObject);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Destroy(gameObject); //이미 인스턴스가 있으면 자신을 파괴
|
Destroy(gameObject); // 이미 인스턴스가 있으면 자신을 파괴
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,15 +33,23 @@ private void Start()
|
|||||||
OnSceneLoaded(SceneManager.GetActiveScene(), LoadSceneMode.Single);
|
OnSceneLoaded(SceneManager.GetActiveScene(), LoadSceneMode.Single);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
if (Instance == this)
|
||||||
|
{
|
||||||
|
SceneManager.sceneLoaded -= OnSceneLoaded;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if(_loadingCamTargetTransform != null)
|
if (_loadingRoot != null && _loadingCamTargetTransform != null)
|
||||||
{
|
{
|
||||||
_loadingRoot.transform.position = _loadingCamTargetTransform.position;
|
_loadingRoot.transform.position = _loadingCamTargetTransform.position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//씬이 로드되었을때 호출
|
// 씬이 로드되었을때 호출
|
||||||
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||||
{
|
{
|
||||||
MonoBehaviour[] allObjs = UnityEngine.Object.FindObjectsByType<MonoBehaviour>(FindObjectsSortMode.None);
|
MonoBehaviour[] allObjs = UnityEngine.Object.FindObjectsByType<MonoBehaviour>(FindObjectsSortMode.None);
|
||||||
@@ -45,7 +58,7 @@ private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
|||||||
{
|
{
|
||||||
if (obj is ISceneInitializable initializable)
|
if (obj is ISceneInitializable initializable)
|
||||||
{
|
{
|
||||||
//씬에서 ISceneInitializable 인터페이스를 가진 오브젝트의 초기화 로직을 실행
|
// 씬에서 ISceneInitializable 인터페이스를 가진 오브젝트의 초기화 로직을 실행
|
||||||
initializable.OnSceneLoaded();
|
initializable.OnSceneLoaded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,11 +66,23 @@ private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
|||||||
|
|
||||||
public void SetSceneLoadingProgressValue(float value)
|
public void SetSceneLoadingProgressValue(float value)
|
||||||
{
|
{
|
||||||
|
// 여기에 로딩바 UI 연결 예정
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RequestSceneChange(string sceneName)
|
public void RequestSceneChange(string sceneName)
|
||||||
{
|
{
|
||||||
|
if (_isChangingScene)
|
||||||
|
{
|
||||||
|
Debug.Log("이미 씬 전환 중입니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(sceneName))
|
||||||
|
{
|
||||||
|
Debug.LogWarning("이동할 씬 이름이 비어있습니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_ = SceneChange(sceneName);
|
_ = SceneChange(sceneName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,35 +90,49 @@ private async Awaitable SceneChange(string sceneName)
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//로딩바 수치 0으로 설정
|
_isChangingScene = true;
|
||||||
|
|
||||||
|
// 로딩바 수치 0으로 설정
|
||||||
SetSceneLoadingProgressValue(0f);
|
SetSceneLoadingProgressValue(0f);
|
||||||
|
|
||||||
|
if (_loadingRoot != null)
|
||||||
|
{
|
||||||
|
_loadingRoot.SetActive(true);
|
||||||
|
}
|
||||||
|
|
||||||
AsyncOperation op = SceneManager.LoadSceneAsync(sceneName);
|
AsyncOperation op = SceneManager.LoadSceneAsync(sceneName);
|
||||||
|
|
||||||
//자동 전환을 하고 싶지 않을 경우 해당값을 false로 두었다가 true로 바꾸면 그 때 전환됨
|
if (op == null)
|
||||||
|
{
|
||||||
|
Debug.LogError($"씬 로드 실패: {sceneName}");
|
||||||
|
_isChangingScene = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 자동 전환을 하고 싶지 않을 경우 false로 두었다가 true로 바꾸면 그 때 전환됨
|
||||||
op.allowSceneActivation = false;
|
op.allowSceneActivation = false;
|
||||||
|
|
||||||
//화면에 보여줄 로딩 수치
|
// 화면에 보여줄 로딩 수치
|
||||||
float displayProgress = 0f;
|
float displayProgress = 0f;
|
||||||
|
|
||||||
//op.progress 0.9가 데이터 로딩이 끝난 기준 allowSceneActivation이 트루면 다음으로 넘어가면서 op.isDone이 true가 된다.
|
// op.progress 0.9가 데이터 로딩이 끝난 기준
|
||||||
while (op.progress < 0.9f)
|
while (op.progress < 0.9f)
|
||||||
{
|
{
|
||||||
//실제 로딩 수치
|
// 실제 로딩 수치
|
||||||
float realProgress = Mathf.Clamp01(op.progress / 0.9f);
|
float realProgress = Mathf.Clamp01(op.progress / 0.9f);
|
||||||
|
|
||||||
//보여줄 값을 실제값을 향해 부드럽게 이동
|
// 보여줄 값을 실제값을 향해 부드럽게 이동
|
||||||
displayProgress = Mathf.MoveTowards(displayProgress, realProgress, Time.deltaTime * 0.5f);
|
displayProgress = Mathf.MoveTowards(displayProgress, realProgress, Time.deltaTime * 0.5f);
|
||||||
|
|
||||||
// 로딩바 UI에 값 적용
|
// 로딩바 UI에 값 적용
|
||||||
SetSceneLoadingProgressValue(displayProgress);
|
SetSceneLoadingProgressValue(displayProgress);
|
||||||
|
|
||||||
//자기자신이 파괴될때 토큰에 취소요청을 보냄
|
// 자기자신이 파괴될때 토큰에 취소요청을 보냄
|
||||||
await Awaitable.NextFrameAsync(this.destroyCancellationToken);
|
await Awaitable.NextFrameAsync(this.destroyCancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
//로딩바 수치 1(100%)로 설정 (데이터 로딩은 이미 끝이기 때문에)
|
// 로딩바 수치 1(100%)로 설정
|
||||||
SetSceneLoadingProgressValue(1);
|
SetSceneLoadingProgressValue(1f);
|
||||||
|
|
||||||
// 잠시 대기했다가 전환
|
// 잠시 대기했다가 전환
|
||||||
await Awaitable.WaitForSecondsAsync(1.0f, this.destroyCancellationToken);
|
await Awaitable.WaitForSecondsAsync(1.0f, this.destroyCancellationToken);
|
||||||
@@ -102,19 +141,29 @@ private async Awaitable SceneChange(string sceneName)
|
|||||||
op.allowSceneActivation = true;
|
op.allowSceneActivation = true;
|
||||||
|
|
||||||
// 씬 활성화가 완전히 끝날 때까지 대기
|
// 씬 활성화가 완전히 끝날 때까지 대기
|
||||||
// allowSceneActivation가 true가 되고 완전히 전환되기까지는 몇프레임 걸림. op.isDone 은 이 과정이 끝난 뒤에 true가 됨.
|
while (!op.isDone)
|
||||||
while(!op.isDone)
|
|
||||||
{
|
{
|
||||||
await Awaitable.NextFrameAsync(this.destroyCancellationToken);
|
await Awaitable.NextFrameAsync(this.destroyCancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
//VR용 로직
|
// VR용 로직
|
||||||
//트래킹이 중단되면 안되기 때문에 카메라를 유지해야 한다
|
// 트래킹이 중단되면 안되기 때문에 카메라를 유지해야 한다
|
||||||
_loadingCamTargetTransform = Camera.main.transform; // 새로운 씬의 메인카메라를 따라가게끔 설정
|
if (Camera.main != null)
|
||||||
|
{
|
||||||
|
_loadingCamTargetTransform = Camera.main.transform;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_loadingRoot != null)
|
||||||
|
{
|
||||||
|
_loadingRoot.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
_isChangingScene = false;
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
Debug.Log("씬 전환 작업이 취소됨");
|
Debug.Log("씬 전환 작업이 취소됨");
|
||||||
|
_isChangingScene = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
Reference in New Issue
Block a user