캐릭터 데이터 불러오기 및 캐릭터 선택 / 생성 화면 간의 이동 로직 적용
This commit is contained in:
62
Gameton-06/Assets/Gameton/Scripts/UI/CharaterSelectUI.cs
Normal file
62
Gameton-06/Assets/Gameton/Scripts/UI/CharaterSelectUI.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class CharaterSelectUI : UIBase
|
||||
{
|
||||
|
||||
[SerializeField] private Button createButton; // Create 버튼 참조
|
||||
[SerializeField] private Button playButton; // Play 버튼 참조
|
||||
|
||||
[SerializeField] private List<PlayerData> playerDatas;
|
||||
|
||||
public List<CharaterSelectUI_SlotItem> CharacterSlots = new List<CharaterSelectUI_SlotItem>();
|
||||
|
||||
public SerializableDictionary<string, Sprite> CharacterSpriteDict = new SerializableDictionary<string, Sprite>();
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// 캐릭터를 선택한 이후에 버튼 활성화 할 수 있도록 초기 비활성화 적용
|
||||
playButton.interactable = false;
|
||||
|
||||
if (playerDatas.Count >= 5)
|
||||
{
|
||||
// 캐릭터 슬롯을 모두 사용하고 있다면 버튼 비활성화 적용
|
||||
createButton.interactable = false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < playerDatas.Count; i++)
|
||||
{
|
||||
CharacterSpriteDict.TryGetValue(playerDatas[i].type, out Sprite sprite);
|
||||
string name = playerDatas[0].name != null ? playerDatas[0].name : "";
|
||||
|
||||
if (sprite)
|
||||
{
|
||||
CharacterSlots[i].SetCharaterData(sprite, name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void SetPlayerDatas(List<PlayerData> datas)
|
||||
{
|
||||
playerDatas = datas;
|
||||
}
|
||||
|
||||
public void OnClickPlayButton()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnClickCreateButton()
|
||||
{
|
||||
UIManager.Show<CharaterCreateUI>(UIList.CharaterCreateUI);
|
||||
UIManager.Hide<CharaterSelectUI>(UIList.CharaterSelectUI);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d8fff7f63166be4b89de078e1595642
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class CharaterSelectUI_SlotItem : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Image character_image;
|
||||
[SerializeField] private TextMeshProUGUI charater_name;
|
||||
|
||||
public void SetCharaterData(Sprite image, string name)
|
||||
{
|
||||
character_image.sprite = image;
|
||||
charater_name.text = name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 349f3b01eba66bc4c9c86ef4754ab095
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -6,16 +6,29 @@ namespace TON
|
||||
{
|
||||
public class TitleUI : UIBase
|
||||
{
|
||||
public CharaterSelectUI charaterSelectUI;
|
||||
|
||||
public void OnClickStartButton()
|
||||
{
|
||||
// Main.Singleton?.ChangeScene(SceneType.Ingame);
|
||||
UIManager.Hide<TitleUI>(UIList.TitleUI);
|
||||
|
||||
// TODO: 현재 가지고 있는 캐릭터가 없다면 CharaterCreateUI 를 보여주고
|
||||
UIManager.Show<CharaterCreateUI>(UIList.CharaterCreateUI);
|
||||
// TODO: 캐릭터가 있다면 내 캐릭터 목록에서 선택할 수 있도록 함
|
||||
List<PlayerData> players = JSONLoader.LoadFromResources<List<PlayerData>>("Player");
|
||||
|
||||
if (players == null)
|
||||
{
|
||||
// 현재 가지고 있는 캐릭터가 없다면 CharaterCreateUI 를 보여주고
|
||||
UIManager.Show<CharaterCreateUI>(UIList.CharaterCreateUI);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 캐릭터가 있다면 내 캐릭터 목록에서 선택할 수 있도록 함
|
||||
charaterSelectUI.SetPlayerDatas(players);
|
||||
UIManager.Show<CharaterSelectUI>(UIList.CharaterSelectUI);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void OnClickExitButton()
|
||||
{
|
||||
Main.Singleton?.SystemQuit();
|
||||
|
||||
Reference in New Issue
Block a user