Intro 로딩 테이블 로드 개수 연동 추가, 플레이어 테이블 추가

This commit is contained in:
villaingames 2023-10-12 21:40:32 +09:00
parent 99de67444b
commit babf7c2cd4
25 changed files with 389 additions and 1245 deletions

View File

@ -22,6 +22,11 @@ MonoBehaviour:
m_ReadOnly: 0 m_ReadOnly: 0
m_SerializedLabels: [] m_SerializedLabels: []
FlaggedDuringContentUpdateRestriction: 0 FlaggedDuringContentUpdateRestriction: 0
- m_GUID: e5c8e53bdb2364549800184c7cafe645
m_Address: JPlayer
m_ReadOnly: 0
m_SerializedLabels: []
FlaggedDuringContentUpdateRestriction: 0
m_ReadOnly: 0 m_ReadOnly: 0
m_Settings: {fileID: 11400000, guid: a27fd004fb823a34a9ae690bdbfd496e, type: 2} m_Settings: {fileID: 11400000, guid: a27fd004fb823a34a9ae690bdbfd496e, type: 2}
m_SchemaSet: m_SchemaSet:

View File

@ -0,0 +1,32 @@
{
"list": [
{
"Id": 1,
"Str": 2000,
"Range": 2.0,
"Speed": 3.0,
"PrefabName": "Crate_01"
},
{
"Id": 2,
"Str": 2200,
"Range": 2.5,
"Speed": 2.5,
"PrefabName": "Crate_02"
},
{
"Id": 3,
"Str": 1800,
"Range": 2.8,
"Speed": 2.5,
"PrefabName": "Crate_03"
},
{
"Id": 4,
"Str": 1800,
"Range": 2.5,
"Speed": 2.8,
"PrefabName": "Crate_04"
}
]
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e5c8e53bdb2364549800184c7cafe645
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -125,7 +125,7 @@ MonoBehaviour:
m_MinValue: 0 m_MinValue: 0
m_MaxValue: 1 m_MaxValue: 1
m_WholeNumbers: 0 m_WholeNumbers: 0
m_Value: 0.75 m_Value: 0
m_OnValueChanged: m_OnValueChanged:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
@ -194,7 +194,7 @@ MonoBehaviour:
m_OnCullStateChanged: m_OnCullStateChanged:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
m_text: 75% m_text: 0%
m_isRightToLeft: 0 m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 50c12c23294124aa48490c44ac65a9e4, type: 2} m_fontAsset: {fileID: 11400000, guid: 50c12c23294124aa48490c44ac65a9e4, type: 2}
m_sharedMaterial: {fileID: 7746803525459343344, guid: 50c12c23294124aa48490c44ac65a9e4, m_sharedMaterial: {fileID: 7746803525459343344, guid: 50c12c23294124aa48490c44ac65a9e4,
@ -540,3 +540,5 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 8c670cb90c2944c468eb583d02b49571, type: 3} m_Script: {fileID: 11500000, guid: 8c670cb90c2944c468eb583d02b49571, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_loadingSlider: {fileID: 4116304718493178528}
_loadingText: {fileID: 4116304719635805339}

File diff suppressed because it is too large Load Diff

View File

@ -5,6 +5,7 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.AddressableAssets; using UnityEngine.AddressableAssets;
using UnityEngine.Pool; using UnityEngine.Pool;
using UnityEngine.ResourceManagement.AsyncOperations;
public class AddressableManager : UnitySingleton<AddressableManager> public class AddressableManager : UnitySingleton<AddressableManager>
{ {
@ -29,15 +30,28 @@ public class AddressableManager : UnitySingleton<AddressableManager>
}; };
} }
public void InstantiateAsync(string name, Transform parent, Action<GameObject> onComplete) public AsyncOperationHandle LoadTableAssetAsync<T>(string name, Action<T> onComplete) where T : UnityEngine.Object
{ {
var handle = Addressables.InstantiateAsync(name, parent); var handle = Addressables.LoadAssetAsync<T>(name);
handle.Completed += handler => handle.Completed += handler =>
{ {
onComplete(handle.Result); if (handler.Status == UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationStatus.Succeeded)
Addressables.Release(handle); {
}; onComplete(handler.Result);
} }
};
return handle;
}
//public void InstantiateAsync(string name, Transform parent, Action<GameObject> onComplete)
//{
// var handle = Addressables.InstantiateAsync(name, parent);
// handle.Completed += handler =>
// {
// onComplete(handle.Result);
// Addressables.Release(handle);
// };
//}
public void Spawn(string name, Transform parent, Action<GameObject> complete) public void Spawn(string name, Transform parent, Action<GameObject> complete)
{ {

View File

@ -1,11 +1,27 @@
using FirstVillain.Entities;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class PlayerInfo public class PlayerInfo
{ {
public int STR { get; private set; } public int STR { get { return _table.Str; } }
public int RANGE { get; private set; } public float RANGE { get { return _table.Range; } }
public float SPEED { get; private set; } public float SPEED { get { return _table.Speed; } }
public E_TEAM Team { get; private set; }
public string PrefapName { get { return _table.PrefabName; } }
private JPlayerData _table;
public PlayerInfo(JPlayerData data)
{
_table = data;
}
public void SetTeam(E_TEAM team)
{
Team = team;
}
} }

View File

@ -0,0 +1,28 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace FirstVillain.Entities
{
public class JPlayerData
{
public int Id;
public int Str;
public float Range;
public float Speed;
public string PrefabName;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 565ce374e8f8f02449bdee1296a77865
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -41,5 +41,6 @@ public enum E_UI_TYPE
public enum E_TABLE public enum E_TABLE
{ {
JPropInfo, JPropInfo,
JPlayer,
} }
#endregion Table #endregion Table

View File

@ -0,0 +1,18 @@
using FirstVillain.Entities;
using FirstVillain.Singleton;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : UnitySingleton<GameManager>
{
public List<PlayerInfo> PlayerData { get; private set; } = new();
public void SetPlayerData(List<JPlayerData> dataList)
{
foreach (var data in dataList)
{
PlayerData.Add(new PlayerInfo(data));
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d11671a564f4c5d4cb0351d09ae5030e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,11 +1,64 @@
using FirstVillain.Converter;
using FirstVillain.Entities;
using FirstVillain.EventBus;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
public class IntroSceneController : MonoBehaviour public class IntroSceneController : MonoBehaviour
{ {
private int _loadedTableCount = 0;
private void Start() private void Start()
{ {
UIManager.Instance.OpenUI(E_UI_TYPE.UIPanelIntro); UIManager.Instance.OpenUI(E_UI_TYPE.UIPanelIntro);
EventBus.Instance.Subscribe<EventLoadAssets>(OnStartLoadAssets);
//EventBus.Instance.Subscribe<EventLoadTable<JPlayerData>>(OnPlayerDataLoaded);
} }
private void OnDestroy()
{
EventBus.Instance.Unsubscribe<EventLoadAssets>(OnStartLoadAssets);
//EventBus.Instance.Unsubscribe<EventLoadTable<JPlayerData>>(OnPlayerDataLoaded);
}
private void OnStartLoadAssets(EventLoadAssets e)
{
LoadTable();
StartCoroutine(LoadingGauge());
}
private IEnumerator LoadingGauge()
{
float maxGauge = TableManager.Instance.LoadTableCount;
while (_loadedTableCount < maxGauge)
{
EventBus.Instance.Publish(new EventUpdateTableLadingProgress(_loadedTableCount / maxGauge));
yield return null;
}
EventBus.Instance.Publish(new EventUpdateTableLadingProgress(1));
SceneLoadManager.Instance.LoadSceneAsync("Lobby", UnityEngine.SceneManagement.LoadSceneMode.Single, OnCompleteLoad);
}
public void OnCompleteLoad()
{
EventBus.Instance.Publish(new EventStartLobby());
UIManager.Instance.ReleaseUI();
}
private void LoadTable()
{
TableManager.Instance.LoadTable<JPlayerData>(E_TABLE.JPlayer, OnPlayerDataLoaded);
}
private void OnPlayerDataLoaded(Wrapper<JPlayerData> data)
{
//µ¥ÀÌÅÍ ¼¼ÆÃ
GameManager.Instance.SetPlayerData(data.list);
_loadedTableCount++;
}
} }

View File

@ -0,0 +1,22 @@
using FirstVillain.EventBus;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SingleStageSceneController : MonoBehaviour
{
private void Start()
{
EventBus.Instance.Subscribe<EventStartStage>(OnStartStage);
}
private void OnDestroy()
{
EventBus.Instance.Unsubscribe<EventStartStage>(OnStartStage);
}
private void OnStartStage(EventStartStage e)
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 818ef5b96b08601408dc3300b2e1f2f5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,26 +1,41 @@
using FirstVillain.Converter; using FirstVillain.Converter;
using FirstVillain.Entities; using FirstVillain.Entities;
using FirstVillain.EventBus;
using FirstVillain.Singleton; using FirstVillain.Singleton;
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
//규칙 : 테이블을 필요할 때마다 로드해서 사용한다. //규칙 : 테이블을 필요할 때마다 로드해서 사용한다.
public class TableManager : UnitySingleton<TableManager> public class TableManager : UnitySingleton<TableManager>
{ {
private void LoadTable<T>(E_TABLE table, Action<Wrapper<T>> result) public int LoadTableCount { get; private set; } = 0;
public void LoadTable<T>(E_TABLE table, Action<Wrapper<T>> result)
{
LoadTableCount++;
LoadTableAsset(table, result);
}
private void LoadTableAsset<T>(E_TABLE table, Action<Wrapper<T>> result)
{ {
AddressableManager.Instance.LoadAssetAsync<TextAsset>(table.ToString(), asset => { AddressableManager.Instance.LoadAssetAsync<TextAsset>(table.ToString(), asset => {
result(JsonConvert.DeserializeObject<Wrapper<T>>(asset.text)); result(JsonConvert.DeserializeObject<Wrapper<T>>(asset.text));
}); });
} }
#region LoadAssets
#endregion LoadAssets
//테이블별로 테이블 가져오는 함수를 계속 추가해 줘야하는 단점... //테이블별로 테이블 가져오는 함수를 계속 추가해 줘야하는 단점...
#region Prop #region Prop
public void GetPropInfoById(E_TABLE table, int id, Action<JPropInfoData> result) public void GetPropInfoById(E_TABLE table, int id, Action<JPropInfoData> result)
{ {
LoadTable<JPropInfoData>(table, loaded => LoadTableAsset<JPropInfoData>(table, loaded =>
{ {
var list = loaded.list; var list = loaded.list;
result(list.Find(arg => arg.Id == id)); result(list.Find(arg => arg.Id == id));
@ -29,7 +44,7 @@ public class TableManager : UnitySingleton<TableManager>
public void GetPropInfoList(E_TABLE table, Action<List<JPropInfoData>> result) public void GetPropInfoList(E_TABLE table, Action<List<JPropInfoData>> result)
{ {
LoadTable<JPropInfoData>(table, loaded => LoadTableAsset<JPropInfoData>(table, loaded =>
{ {
result(loaded.list); result(loaded.list);
}); });

View File

@ -147,7 +147,7 @@ public class UIManager : UnitySingleton<UIManager>
} }
private IEnumerator DelayCloseLoading() private IEnumerator DelayCloseLoading()
{ {
yield return new WaitForSeconds(1.5f); yield return new WaitForSeconds(0.5f);
_loadingUI.CloseAction(); _loadingUI.CloseAction();
Destroy(_loadingUI.gameObject); Destroy(_loadingUI.gameObject);
_loadingUI = null; _loadingUI = null;

View File

@ -26,10 +26,11 @@ public class PlayerController : MonoBehaviour
EventBus.Instance.Unsubscribe<EventSendMinigamePoint>(OnGetMinigamePoint); EventBus.Instance.Unsubscribe<EventSendMinigamePoint>(OnGetMinigamePoint);
} }
public void SetData() public void SetData(PlayerInfo info)
{ {
_tableData = info;
//_currentTeam = info.Team;
_currentTeam = E_TEAM.Red; _currentTeam = E_TEAM.Red;
_tableData = new PlayerInfo();
} }
// Update is called once per frame // Update is called once per frame

View File

@ -28,15 +28,15 @@ public class SpawnController : MonoBehaviour
//최초 플레이어 프리팹 로드 및 생성 //최초 플레이어 프리팹 로드 및 생성
//TODO : 씬 외부에서 선택된 플레이어 정보를 넘겨주고 해당 데이터를 받아 생성한다. //TODO : 씬 외부에서 선택된 플레이어 정보를 넘겨주고 해당 데이터를 받아 생성한다.
public void SpawnPlayer(string prefab/*추후 데이터로 교체*/, System.Action<PlayerController> result) public void SpawnPlayer(PlayerInfo info, System.Action<PlayerController> result)
{ {
TableManager.Instance.GetPropInfoList(E_TABLE.JPropInfo, propList => TableManager.Instance.GetPropInfoList(E_TABLE.JPropInfo, propList =>
{ {
_PropDataList = propList; _PropDataList = propList;
AddressableManager.Instance.Spawn(prefab, null, onComplete => AddressableManager.Instance.Spawn(info.PrefapName, null, onComplete =>
{ {
var controller = onComplete.GetComponent<PlayerController>(); var controller = onComplete.GetComponent<PlayerController>();
controller.SetData(); controller.SetData(info);
controller.Block(); controller.Block();
RespawnPlayer(controller); RespawnPlayer(controller);
result(controller); result(controller);

View File

@ -0,0 +1,30 @@
using FirstVillain.Converter;
using FirstVillain.EventBus;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EventLoadAssets : EventBase
{
}
public class EventLoadTable<T> : EventBase
{
public List<T> DataList { get; private set; }
public EventLoadTable(Wrapper<T> wrapper)
{
DataList = wrapper.list;
}
}
public class EventUpdateTableLadingProgress : EventBase
{
public float Progress { get; private set; }
public EventUpdateTableLadingProgress(float progress)
{
Progress = progress;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a8adede989e77864fbbac657acc08e3c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,5 +1,17 @@
using FirstVillain.EventBus; using FirstVillain.EventBus;
public class EventStartStage : EventBase
{
public PlayerInfo SelectedPlayer { get; private set; }
public E_STAGE_TYPE StageType { get; private set; }
public EventStartStage(PlayerInfo info, E_STAGE_TYPE stageType)
{
SelectedPlayer= info;
StageType = stageType;
}
}
public class EventMinigameStop : EventBase public class EventMinigameStop : EventBase
{ {

View File

@ -16,19 +16,14 @@ public class StageManager : UnitySingletonOnce<StageManager>
public bool IsPlaying { get { return _state == E_STAGE_STATE.Playing; } } public bool IsPlaying { get { return _state == E_STAGE_STATE.Playing; } }
private void Start() private void Init(PlayerInfo player, E_STAGE_TYPE type)
{ {
//임시 호출
Init(E_STAGE_TYPE.Single_TimeAttack, "Player_Cop");
}
private void Init(E_STAGE_TYPE type, string prefab/*추후 테이블*/)
{
_currentStageType = type; _currentStageType = type;
_state = E_STAGE_STATE.Ready; _state = E_STAGE_STATE.Ready;
InitScore(); InitScore();
//TODO : UI초기화 //TODO : UI초기화
_spawnController.SpawnPlayer(prefab, result => _spawnController.SpawnPlayer(player, result =>
{ {
//시작 시간표기? //시작 시간표기?
StartGame(); StartGame();

View File

@ -16,12 +16,11 @@ public class UIPanelIntro : UIBase
public void OnClickStart() public void OnClickStart()
{ {
SceneLoadManager.Instance.LoadSceneAsync("Lobby", OnCompleteLoad, E_UI_TYPE.UIPanelLoadingIntro); UIManager.Instance.OpenLoadingUI(E_UI_TYPE.UIPanelLoadingIntro, LoadingUIOpened);
} }
public void OnCompleteLoad() private void LoadingUIOpened(UIBase ui)
{ {
EventBus.Instance.Publish(new EventStartLobby()); EventBus.Instance.Publish(new EventLoadAssets());
Close();
} }
} }

View File

@ -1,18 +1,29 @@
using FirstVillain.EventBus;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.UI;
public class UIPanelLoadingIntro : UIBase public class UIPanelLoadingIntro : UIBase
{ {
// Start is called before the first frame update [SerializeField] private Slider _loadingSlider;
void Start() [SerializeField] private TextMeshProUGUI _loadingText;
private void Start()
{ {
_loadingSlider.value = 0;
_loadingText.text = "0%";
EventBus.Instance.Subscribe<EventUpdateTableLadingProgress>(OnUpdateLoadingGauge);
} }
private void OnDestroy()
// Update is called once per frame
void Update()
{ {
EventBus.Instance.Unsubscribe<EventUpdateTableLadingProgress>(OnUpdateLoadingGauge);
}
private void OnUpdateLoadingGauge(EventUpdateTableLadingProgress e)
{
_loadingSlider.value = e.Progress;
_loadingText.text = $"{(int)(e.Progress * 100)}%";
} }
} }