diff --git a/Gameton-06/Assets/Gameton/Scenes/Lobby.unity b/Gameton-06/Assets/Gameton/Scenes/Lobby.unity index 1682e9a4..607f7338 100644 --- a/Gameton-06/Assets/Gameton/Scenes/Lobby.unity +++ b/Gameton-06/Assets/Gameton/Scenes/Lobby.unity @@ -739,7 +739,7 @@ GameObject: m_Component: - component: {fileID: 1968431293} m_Layer: 0 - m_Name: Player + m_Name: TON.Player m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 diff --git a/Gameton-06/Assets/Gameton/Scripts/Scenes/LobbyScene.cs b/Gameton-06/Assets/Gameton/Scripts/Scenes/LobbyScene.cs index 19f2acaf..6d2bbbdf 100644 --- a/Gameton-06/Assets/Gameton/Scripts/Scenes/LobbyScene.cs +++ b/Gameton-06/Assets/Gameton/Scripts/Scenes/LobbyScene.cs @@ -7,6 +7,10 @@ namespace TON { public class LobbyScene : SceneBase { + public SerializableDictionary CharacterSpriteDict = new SerializableDictionary(); + + [SerializeField] private List playerDatas; + public override IEnumerator OnStart() { // Lobby 씬을 비동기로 로드한다. @@ -17,6 +21,49 @@ namespace TON { yield return null; } + + SpawnPlayerCharacter(); + } + + private void SpawnPlayerCharacter() + { + playerDatas = PlayerDataManager.Singleton.players; + // 저장된 인덱스 가져오기 + int selectedIndex = PlayerPrefs.GetInt("SelectedPlayerIndex", 0); + + // 인덱스가 범위를 벗어나지 않는지 확인 + if (selectedIndex < 0 || selectedIndex >= playerDatas.Count) + { + Debug.LogError($"Invalid player index: {selectedIndex}"); + return; + } + + string prefabName = playerDatas[selectedIndex].type == "b" ? "TON.Player_B" : "TON.Player_W"; + // Resources에서 프리팹 로드 + GameObject characterPrefab = Resources.Load($"Player/{prefabName}"); + if (characterPrefab == null) + { + Debug.LogError($"Failed to load character prefab: {playerDatas[selectedIndex].type}"); + return; + } + + // TON.Player 오브젝트 찾기 + GameObject playerObj = GameObject.Find("TON.Player"); + if (playerObj == null) + { + Debug.LogError("TON.Player not found in the scene!"); + return; + } + + // 기존 플레이어 제거 (필요 시) + foreach (Transform child in playerObj.transform) + { + GameObject.Destroy(child.gameObject); + } + + // 캐릭터 프리팹을 TON.Player 위치에 배치 + GameObject playerInstance = Instantiate(characterPrefab, playerObj.transform.position, Quaternion.identity); + playerInstance.transform.SetParent(playerObj.transform); } public override IEnumerator OnEnd() diff --git a/Gameton-06/Assets/Gameton/Scripts/UI/CharaterCreateUI.cs b/Gameton-06/Assets/Gameton/Scripts/UI/CharaterCreateUI.cs index 18a1d3fb..2e059840 100644 --- a/Gameton-06/Assets/Gameton/Scripts/UI/CharaterCreateUI.cs +++ b/Gameton-06/Assets/Gameton/Scripts/UI/CharaterCreateUI.cs @@ -31,7 +31,7 @@ namespace TON { if (string.IsNullOrEmpty(selectedCharacter)) { - Debug.Log("캐릭터를 선택하세요!"); + // 캐릭터 선택되지 않은 상태에서 버튼 동작 되지 않도록 적용 return; } diff --git a/Gameton-06/Assets/Gameton/Scripts/UI/CharaterSelectUI.cs b/Gameton-06/Assets/Gameton/Scripts/UI/CharaterSelectUI.cs index d3e836e3..75fdd68e 100644 --- a/Gameton-06/Assets/Gameton/Scripts/UI/CharaterSelectUI.cs +++ b/Gameton-06/Assets/Gameton/Scripts/UI/CharaterSelectUI.cs @@ -60,6 +60,9 @@ namespace TON PlayerPrefs.SetInt("SelectedPlayerIndex", currentSelectCharacterIndex); Debug.Log(currentSelectCharacterIndex); + UIManager.Hide(UIList.CharaterSelectUI); + + Main.Singleton?.ChangeScene(SceneType.Lobby); } public void OnClickCreateButton()