Genesis Game Client Project Setup
This commit is contained in:
8
Assets/02_Scripts/Managers/Global.meta
Normal file
8
Assets/02_Scripts/Managers/Global.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 841d969ef23f1f544811aad5c3f6fcf6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
90
Assets/02_Scripts/Managers/Global/DataManager.cs
Normal file
90
Assets/02_Scripts/Managers/Global/DataManager.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using Game.Network.DTO;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TextCore.Text;
|
||||
|
||||
public class DataManager : MonoBehaviour
|
||||
{
|
||||
public static DataManager Instance;
|
||||
|
||||
//내 캐릭터들
|
||||
public List<UserCharacter> MyCharacters = new List<UserCharacter>();
|
||||
|
||||
//모든 캐릭터들 데이터(적,NPC,플레이어블)
|
||||
|
||||
public Dictionary<string, PlayableCharacter> PlayableCharacterData = new Dictionary<string, PlayableCharacter>();
|
||||
public Dictionary<string, EnemyCharacter> EnemyCharacterData = new Dictionary<string, EnemyCharacter>();
|
||||
public Dictionary<string, NpcCharacter> NpcCharacterData = new Dictionary<string, NpcCharacter>();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this; //만들어진 자신을 인스턴스로 설정
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject); //이미 인스턴스가 있으면 자신을 파괴
|
||||
}
|
||||
}
|
||||
|
||||
private async Awaitable Start()
|
||||
{
|
||||
await LoadUserCharacters(1);
|
||||
await LoadPlayableCharacters();
|
||||
}
|
||||
|
||||
public async Awaitable LoadUserCharacters(int userNo)
|
||||
{
|
||||
UserCharacterDTO[] characterDTOs = await NetworkManager.Instance.GetDatabaseData<UserCharacterDTO[]>($"userCharacters/{userNo}");
|
||||
|
||||
if (characterDTOs != null)
|
||||
{
|
||||
MyCharacters.Clear();
|
||||
|
||||
foreach ( UserCharacterDTO characterDTO in characterDTOs )
|
||||
{
|
||||
UserCharacter uc = new UserCharacter();
|
||||
uc.UserCharacterNo = characterDTO.userCharacterNo;
|
||||
uc.UserNo = characterDTO.userNo;
|
||||
uc.CharacterCode = characterDTO.characterCode;
|
||||
uc.Lv = characterDTO.lv;
|
||||
uc.StrStat = characterDTO.strStat;
|
||||
uc.IntStat = characterDTO.intStat;
|
||||
uc.MaxHp = characterDTO.maxHp;
|
||||
uc.MaxMp = characterDTO.maxMp;
|
||||
uc.DefaultControl = characterDTO.defaultControl;
|
||||
|
||||
MyCharacters.Add(uc);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("캐릭터 데이터를 불러오지 못했습니다.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Awaitable LoadPlayableCharacters()
|
||||
{
|
||||
PlayableCharacterDTO[] characterDTOs = await NetworkManager.Instance.GetDatabaseData<PlayableCharacterDTO[]>($"playableCharacters");
|
||||
|
||||
if (characterDTOs != null)
|
||||
{
|
||||
PlayableCharacterData.Clear();
|
||||
|
||||
foreach (PlayableCharacterDTO characterDTO in characterDTOs)
|
||||
{
|
||||
PlayableCharacter c = new PlayableCharacter();
|
||||
c.CharacterCode = characterDTO.characterCode;
|
||||
c.CharacterType = characterDTO.characterType;
|
||||
|
||||
PlayableCharacterData.TryAdd(c.CharacterCode, c);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("캐릭터 데이터를 불러오지 못했습니다.");
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/Managers/Global/DataManager.cs.meta
Normal file
2
Assets/02_Scripts/Managers/Global/DataManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c9262ba3475f9d4482097685346b7e5
|
||||
93
Assets/02_Scripts/Managers/Global/GameManager.cs
Normal file
93
Assets/02_Scripts/Managers/Global/GameManager.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
public static GameManager Instance;
|
||||
|
||||
public LevelManager Level { get; private set; }
|
||||
public CameraManager Camera { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this; //만들어진 자신을 인스턴스로 설정
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject); //이미 인스턴스가 있으면 자신을 파괴
|
||||
}
|
||||
|
||||
SceneManager.sceneLoaded += OnSceneLoaded;
|
||||
}
|
||||
|
||||
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||
{
|
||||
// 씬이 로드될 때마다 해당 씬에 있는 Manager들을 찾아서 갱신
|
||||
// 없으면 자동으로 null이 들어감
|
||||
Level = FindFirstObjectByType<LevelManager>();
|
||||
Camera = FindFirstObjectByType<CameraManager>();
|
||||
|
||||
if(Level != null) Level.OnSceneLoaded(scene, mode);
|
||||
if(Camera != null) Camera.OnSceneLoaded(scene, mode);
|
||||
|
||||
InputManager.Instance.PlayerInputEnable(true);
|
||||
GlobalUIManager.Instance.SetSceneLoadingActive(false);
|
||||
|
||||
}
|
||||
|
||||
public void RequestSceneChange(string sceneName)
|
||||
{
|
||||
_ = SceneChange(sceneName);
|
||||
}
|
||||
|
||||
private async Awaitable SceneChange(string sceneName)
|
||||
{
|
||||
try
|
||||
{
|
||||
GlobalUIManager.Instance.SetSceneLoadingActive(true);
|
||||
|
||||
AsyncOperation op = SceneManager.LoadSceneAsync(sceneName);
|
||||
|
||||
//자동 전환을 하고 싶지 않을 경우 해당값을 false로 두었다가 true로 바꾸면 그 때 전환됨
|
||||
op.allowSceneActivation = false;
|
||||
|
||||
//화면에 보여줄 로딩 수치
|
||||
float displayProgress = 0f;
|
||||
|
||||
//op.progress 0.9가 데이터 로딩이 끝난 기준 allowSceneActivation이 트루면 바로 다음으로 넘어가면서 op.isDone이 true가 된다.
|
||||
while (op.progress < 0.9f)
|
||||
{
|
||||
//실제 로딩 수치
|
||||
float realProgress = Mathf.Clamp01(op.progress / 0.9f);
|
||||
|
||||
//보여줄 값을 실제값을 향해 부드럽게 이동
|
||||
displayProgress = Mathf.MoveTowards(displayProgress, realProgress, Time.deltaTime * 0.5f);
|
||||
|
||||
// UI에 적용
|
||||
GlobalUIManager.Instance.SetSceneLoadingProgressValue(displayProgress);
|
||||
|
||||
await Awaitable.NextFrameAsync(this.destroyCancellationToken); //자기자신이 파괴될때 토큰에 취소요청을 보냄
|
||||
}
|
||||
|
||||
GlobalUIManager.Instance.SetSceneLoadingProgressValue(1);
|
||||
|
||||
// 잠시 대기했다가 전환
|
||||
await Awaitable.WaitForSecondsAsync(2.0f, this.destroyCancellationToken);
|
||||
|
||||
op.allowSceneActivation = true;
|
||||
|
||||
Debug.Log("씬 전환됨");
|
||||
|
||||
InputManager.Instance.UnPairDevices();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
Debug.Log("씬 전환 작업이 취소됨");
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/Managers/Global/GameManager.cs.meta
Normal file
2
Assets/02_Scripts/Managers/Global/GameManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e694f93c42d3334cb7ea4ac25d87b5d
|
||||
205
Assets/02_Scripts/Managers/Global/InputManager.cs
Normal file
205
Assets/02_Scripts/Managers/Global/InputManager.cs
Normal file
@@ -0,0 +1,205 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.Windows;
|
||||
|
||||
public enum InputState { Started, Performing, Canceled }
|
||||
|
||||
public class InputManager : MonoBehaviour
|
||||
{
|
||||
public static InputManager Instance;
|
||||
|
||||
private PlayerInput _playerInput;
|
||||
private InputActionMap _globalInputActionMap;
|
||||
private InputActionMap _uiInputActionMap;
|
||||
private InputActionMap _characterInputActionMap;
|
||||
|
||||
//콜백 이벤트들
|
||||
//캐릭터 조작관련은 따로 분류
|
||||
public event Action<float> OnMouseScrollEvent;
|
||||
public event Action<Vector2> OnMoveEvent;
|
||||
public event Action<InputState> OnSprintEvent;
|
||||
public event Action<InputState> OnJumpEvent;
|
||||
public event Action OnNormalAttackEvent;
|
||||
public event Action OnHeavyAttackEvent;
|
||||
|
||||
//키조작
|
||||
public event Action OnKeyDown_UpArrowEvent;
|
||||
public event Action OnKeyDown_DownArrowEvent;
|
||||
public event Action OnKeyDown_EnterEvent;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this; //만들어진 자신을 인스턴스로 설정
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject); //이미 인스턴스가 있으면 자신을 파괴
|
||||
}
|
||||
|
||||
_playerInput = GetComponent<PlayerInput>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SetGlobalInputMap("Global");
|
||||
}
|
||||
|
||||
public void UnPairDevices()
|
||||
{
|
||||
if(_playerInput != null)
|
||||
{
|
||||
_playerInput.user.UnpairDevices();
|
||||
PlayerInputEnable(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayerInputEnable(bool flag)
|
||||
{
|
||||
_playerInput.enabled = flag;
|
||||
}
|
||||
|
||||
private void SetGlobalInputMap(string mapName)
|
||||
{
|
||||
_globalInputActionMap = _playerInput?.actions?.FindActionMap(mapName);
|
||||
}
|
||||
|
||||
public void SetUIInputMap(string mapName)
|
||||
{
|
||||
_uiInputActionMap = _playerInput?.actions?.FindActionMap(mapName);
|
||||
if (_uiInputActionMap == null) return;
|
||||
|
||||
// 맵 활성화
|
||||
_uiInputActionMap.Enable();
|
||||
|
||||
//바인딩
|
||||
BindActionUI("OnKeyDown_UpArrow", OnKeyDown_UpArrow);
|
||||
BindActionUI("OnKeyDown_DownArrow", OnKeyDown_DownArrow);
|
||||
BindActionUI("OnKeyDown_Enter", OnKeyDown_Enter);
|
||||
|
||||
}
|
||||
|
||||
public void SetCharacterInputMap(string mapName)
|
||||
{
|
||||
_characterInputActionMap = _playerInput?.actions?.FindActionMap(mapName);
|
||||
if (_characterInputActionMap == null) return;
|
||||
|
||||
// 맵 활성화
|
||||
_characterInputActionMap.Enable();
|
||||
|
||||
//바인딩
|
||||
BindActionCharacter("Scroll", OnMouseScroll);
|
||||
BindActionCharacter("Move", OnMove);
|
||||
BindActionCharacter("Sprint", OnSprint);
|
||||
BindActionCharacter("Jump", OnJump);
|
||||
BindActionCharacter("NormalAttack", OnNormalAttack);
|
||||
BindActionCharacter("HeavyAttack", OnHeavyAttack);
|
||||
}
|
||||
|
||||
//매핑용 함수
|
||||
private void BindActionUI(string actionName, Action<InputAction.CallbackContext> callback)
|
||||
{
|
||||
InputAction action = _uiInputActionMap.FindAction(actionName);
|
||||
if (action != null)
|
||||
{
|
||||
action.performed -= callback;
|
||||
action.canceled -= callback;
|
||||
action.started -= callback;
|
||||
|
||||
action.performed += callback;
|
||||
action.canceled += callback;
|
||||
action.started += callback;
|
||||
|
||||
action.Enable();
|
||||
}
|
||||
}
|
||||
private void BindActionCharacter(string actionName, Action<InputAction.CallbackContext> callback)
|
||||
{
|
||||
InputAction action = _characterInputActionMap.FindAction(actionName);
|
||||
if (action != null)
|
||||
{
|
||||
action.performed -= callback;
|
||||
action.canceled -= callback;
|
||||
action.started -= callback;
|
||||
|
||||
action.performed += callback;
|
||||
action.canceled += callback;
|
||||
action.started += callback;
|
||||
|
||||
action.Enable();
|
||||
}
|
||||
}
|
||||
|
||||
#region 캐릭터 조작
|
||||
private void OnMouseScroll(InputAction.CallbackContext ctx)
|
||||
{
|
||||
Vector2 scroll = ctx.ReadValue<Vector2>();
|
||||
OnMouseScrollEvent?.Invoke(scroll.y);
|
||||
}
|
||||
|
||||
private void OnMove(InputAction.CallbackContext ctx)
|
||||
{
|
||||
Vector2 move = ctx.ReadValue<Vector2>();
|
||||
OnMoveEvent?.Invoke(move);
|
||||
}
|
||||
|
||||
private void OnSprint(InputAction.CallbackContext ctx)
|
||||
{
|
||||
if(ctx.performed)
|
||||
{
|
||||
OnSprintEvent?.Invoke(InputState.Performing);
|
||||
}
|
||||
|
||||
if(ctx.canceled)
|
||||
{
|
||||
OnSprintEvent?.Invoke(InputState.Canceled);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnJump(InputAction.CallbackContext ctx)
|
||||
{
|
||||
if(ctx.started)
|
||||
{
|
||||
OnJumpEvent?.Invoke(InputState.Started);
|
||||
}
|
||||
|
||||
if (ctx.canceled)
|
||||
{
|
||||
OnJumpEvent?.Invoke(InputState.Canceled);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnNormalAttack(InputAction.CallbackContext ctx)
|
||||
{
|
||||
OnNormalAttackEvent?.Invoke();
|
||||
}
|
||||
|
||||
private void OnHeavyAttack(InputAction.CallbackContext ctx)
|
||||
{
|
||||
OnHeavyAttackEvent?.Invoke();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 키별 조작
|
||||
private void OnKeyDown_UpArrow(InputAction.CallbackContext ctx)
|
||||
{
|
||||
if(ctx.started)
|
||||
OnKeyDown_UpArrowEvent?.Invoke();
|
||||
}
|
||||
|
||||
private void OnKeyDown_DownArrow(InputAction.CallbackContext ctx)
|
||||
{
|
||||
if (ctx.started)
|
||||
OnKeyDown_UpArrowEvent?.Invoke();
|
||||
}
|
||||
|
||||
private void OnKeyDown_Enter(InputAction.CallbackContext ctx)
|
||||
{
|
||||
if (ctx.started)
|
||||
OnKeyDown_EnterEvent?.Invoke();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
2
Assets/02_Scripts/Managers/Global/InputManager.cs.meta
Normal file
2
Assets/02_Scripts/Managers/Global/InputManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bee5878dce649df468827634987718b7
|
||||
53
Assets/02_Scripts/Managers/Global/NetworkManager.cs
Normal file
53
Assets/02_Scripts/Managers/Global/NetworkManager.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Game.Network;
|
||||
using Game.Network.DTO;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
public class NetworkManager : MonoBehaviour
|
||||
{
|
||||
public static NetworkManager Instance;
|
||||
|
||||
private string _baseGameDBUrl = "https://localhost:7134/myGame";
|
||||
//private string _baseGameDBUrlHttp = "http://localhost:5281/myGame";
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this; //만들어진 자신을 인스턴스로 설정
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject); //이미 인스턴스가 있으면 자신을 파괴
|
||||
}
|
||||
}
|
||||
|
||||
public async Awaitable<T> GetDatabaseData<T>(string endPoint)
|
||||
{
|
||||
string url = $"{_baseGameDBUrl}/{endPoint}";
|
||||
using UnityWebRequest request = UnityWebRequest.Get(url); //앞의 using은 사용이 끝난(메서드 종료) 외부 리소스 객체들을 알아서 지워주도록 설정하는 예약어이다
|
||||
request.certificateHandler = new BypassCertificate();
|
||||
|
||||
try
|
||||
{
|
||||
await request.SendWebRequest();
|
||||
|
||||
if (request.result == UnityWebRequest.Result.Success)
|
||||
{
|
||||
string json = request.downloadHandler.text;
|
||||
|
||||
ApiResponse<T> container = JsonConvert.DeserializeObject<ApiResponse<T>>(json);
|
||||
Debug.Log($"응답 : data = {container.data}, count = {container.count}, message = {container.message}");
|
||||
|
||||
return container.data;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
return default;
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/Managers/Global/NetworkManager.cs.meta
Normal file
2
Assets/02_Scripts/Managers/Global/NetworkManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 603b990f633737340b3c056ba1cbf300
|
||||
17
Assets/02_Scripts/Managers/Global/SoundManager.cs
Normal file
17
Assets/02_Scripts/Managers/Global/SoundManager.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class SoundManager : MonoBehaviour
|
||||
{
|
||||
public static SoundManager Instance;
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this; //만들어진 자신을 인스턴스로 설정
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject); //이미 인스턴스가 있으면 자신을 파괴
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/Managers/Global/SoundManager.cs.meta
Normal file
2
Assets/02_Scripts/Managers/Global/SoundManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 571d986dc1fe8bd4aa48335d392008a4
|
||||
8
Assets/02_Scripts/Managers/Local.meta
Normal file
8
Assets/02_Scripts/Managers/Local.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e25b823a96cca74eaec7a268a6f821c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
37
Assets/02_Scripts/Managers/Local/CameraManager.cs
Normal file
37
Assets/02_Scripts/Managers/Local/CameraManager.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using UnityEditor.Rendering;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class CameraManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private PlayerCameraRig _currentCameraRig; //현재 활성화된 플레이어의 카메라 묶음 조종객체
|
||||
|
||||
private float minFOV = 40f;
|
||||
private float maxFOV = 100f;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void SetCameraRig(PlayerCameraRig cameraRig)
|
||||
{
|
||||
_currentCameraRig = cameraRig;
|
||||
}
|
||||
|
||||
public void ZoomCamera(float offset)
|
||||
{
|
||||
_currentCameraRig.CurrentFOV = Mathf.Clamp(_currentCameraRig.CurrentFOV - offset, minFOV,maxFOV);
|
||||
}
|
||||
|
||||
public Vector3 GetViewportPointToRayEndPoint(Vector3 vpPoint,float rayLength)
|
||||
{
|
||||
Ray ray = Camera.main.ViewportPointToRay(vpPoint);
|
||||
return ray.GetPoint(rayLength);
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/Managers/Local/CameraManager.cs.meta
Normal file
2
Assets/02_Scripts/Managers/Local/CameraManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f58134c47759c0c42806560eaa79d716
|
||||
146
Assets/02_Scripts/Managers/Local/LevelManager.cs
Normal file
146
Assets/02_Scripts/Managers/Local/LevelManager.cs
Normal file
@@ -0,0 +1,146 @@
|
||||
|
||||
using Game.Network.DTO;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
|
||||
public class LevelManager : MonoBehaviour
|
||||
{
|
||||
#region 플레이어 관련
|
||||
[SerializeField] private GameObject[] _playableCharacterPrefabs; //플레이어가 될수 있는 캐릭터들 프리팹 할당
|
||||
public GameObject[] PlayableCharacterPrefabs { get { return _playableCharacterPrefabs; } private set { _playableCharacterPrefabs = value; } }
|
||||
public GameObject CurrentCharacter { get; private set; } // 현재 캐릭터
|
||||
public PlayerCharacterController CurrentCharacterController { get { return CurrentCharacter?.GetComponent<PlayerCharacterController>(); } } // 현재 캐릭터의 컨트롤러
|
||||
public int CurrentCharacterIdx { get; private set; } //현재캐릭터 인덱스
|
||||
#endregion
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||
{
|
||||
if (scene.name == "GameStartScene")
|
||||
{
|
||||
InputManager.Instance.SetUIInputMap("IntroUI");
|
||||
}
|
||||
|
||||
if (scene.name == "GameScene")
|
||||
{
|
||||
|
||||
List<UserCharacter> myCharacters = DataManager.Instance.MyCharacters;
|
||||
|
||||
if (myCharacters != null && myCharacters.Count > 0 && PlayableCharacterPrefabs != null && PlayableCharacterPrefabs.Length > 0)
|
||||
{
|
||||
|
||||
Dictionary<string, PlayerCharacterController> playableCharacterPrefabsDic = PlayableCharacterPrefabs
|
||||
.Select(p => p.GetComponent<PlayerCharacterController>())
|
||||
.Where(pcc => pcc != null && pcc.PlayerCharacterIdentity != null)
|
||||
.ToDictionary(pcc => pcc.PlayerCharacterIdentity.CharacterCode, pcc => pcc);
|
||||
|
||||
foreach (UserCharacter uc in myCharacters)
|
||||
{
|
||||
//내가 가진 캐릭터 코드와 일치하는 플레이어블 캐릭터 프리팹 객체들
|
||||
if (playableCharacterPrefabsDic.TryGetValue(uc.CharacterCode, out PlayerCharacterController pcc))
|
||||
{
|
||||
ApplyCharacterInfo(pcc, uc);
|
||||
}
|
||||
}
|
||||
|
||||
bool defaultCharacterFlag = false;
|
||||
|
||||
for (int i = 0; i < PlayableCharacterPrefabs.Length; i++)
|
||||
{
|
||||
|
||||
GameObject pc = PlayableCharacterPrefabs[i];
|
||||
if (pc.TryGetComponent<PlayerCharacterController>(out PlayerCharacterController pcc) && pcc.PlayerCharacterIdentity.IsDefaultControl)
|
||||
{
|
||||
CurrentCharacter = PlayableCharacterPrefabs[i];
|
||||
CurrentCharacterIdx = i;
|
||||
CurrentCharacterController.PlayerCharacterIdentity.SynchronizeControll();
|
||||
defaultCharacterFlag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!defaultCharacterFlag)
|
||||
{
|
||||
//0번 캐릭터를 현재캐릭터로 설정
|
||||
if (PlayableCharacterPrefabs != null && PlayableCharacterPrefabs.Length > 0)
|
||||
{
|
||||
CurrentCharacter = PlayableCharacterPrefabs[0];
|
||||
CurrentCharacterIdx = 0;
|
||||
CurrentCharacterController.PlayerCharacterIdentity.SynchronizeControll();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//0번 캐릭터를 현재캐릭터로 설정
|
||||
if (PlayableCharacterPrefabs != null && PlayableCharacterPrefabs.Length > 0)
|
||||
{
|
||||
CurrentCharacter = PlayableCharacterPrefabs[0];
|
||||
CurrentCharacterIdx = 0;
|
||||
CurrentCharacterController.PlayerCharacterIdentity.SynchronizeControll();
|
||||
}
|
||||
}
|
||||
|
||||
InputManager.Instance.SetUIInputMap("InGameUI");
|
||||
InputManager.Instance.SetCharacterInputMap("Character");
|
||||
|
||||
//카메라 줌 매핑
|
||||
InputManager.Instance.OnMouseScrollEvent += GameManager.Instance.Camera.ZoomCamera;
|
||||
|
||||
//이동 매핑
|
||||
InputManager.Instance.OnMoveEvent += CurrentCharacterController.MoveInput;
|
||||
InputManager.Instance.OnSprintEvent += CurrentCharacterController.SprintInput;
|
||||
InputManager.Instance.OnJumpEvent += CurrentCharacterController.JumpInput;
|
||||
//InputManager.Instance.OnNormalAttackEvent;
|
||||
//InputManager.Instance.OnHeavyAttackEvent;
|
||||
|
||||
//화면 켜기
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ApplyCharacterInfo(PlayerCharacterController pcc, UserCharacter uc)
|
||||
{
|
||||
pcc.PlayerCharacterStat.MaxHp = uc.MaxHp;
|
||||
pcc.PlayerCharacterStat.MaxMp = uc.MaxMp;
|
||||
pcc.PlayerCharacterStat.Lv = uc.Lv;
|
||||
pcc.PlayerCharacterStat.StrStat = uc.StrStat;
|
||||
pcc.PlayerCharacterStat.IntStat = uc.IntStat;
|
||||
pcc.PlayerCharacterIdentity.IsDefaultControl = uc.DefaultControl;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if(InputManager.Instance != null)
|
||||
{
|
||||
|
||||
//카메라 줌 매핑 해제
|
||||
if (GameManager.Instance != null && GameManager.Instance.Camera != null)
|
||||
{
|
||||
InputManager.Instance.OnMouseScrollEvent -= GameManager.Instance.Camera.ZoomCamera;
|
||||
}
|
||||
|
||||
|
||||
if(CurrentCharacterController != null)
|
||||
{
|
||||
//이동 매핑 해제
|
||||
InputManager.Instance.OnMoveEvent -= CurrentCharacterController.MoveInput;
|
||||
InputManager.Instance.OnSprintEvent -= CurrentCharacterController.SprintInput;
|
||||
InputManager.Instance.OnJumpEvent -= CurrentCharacterController.JumpInput;
|
||||
//InputManager.Instance.OnNormalAttackEvent;
|
||||
//InputManager.Instance.OnHeavyAttackEvent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/Managers/Local/LevelManager.cs.meta
Normal file
2
Assets/02_Scripts/Managers/Local/LevelManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4e261223cd434d49af1414087ba5871
|
||||
8
Assets/02_Scripts/Managers/UI.meta
Normal file
8
Assets/02_Scripts/Managers/UI.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2ce3199cf34c8e4c90dbda71f1db34e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
Assets/02_Scripts/Managers/UI/BaseUIManager.cs
Normal file
16
Assets/02_Scripts/Managers/UI/BaseUIManager.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class BaseUIManager : MonoBehaviour
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/Managers/UI/BaseUIManager.cs.meta
Normal file
2
Assets/02_Scripts/Managers/UI/BaseUIManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a8f2efec4f0f78418e3d00cd85fc18f
|
||||
43
Assets/02_Scripts/Managers/UI/GlobalUIManager.cs
Normal file
43
Assets/02_Scripts/Managers/UI/GlobalUIManager.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class GlobalUIManager : BaseUIManager
|
||||
{
|
||||
public static GlobalUIManager Instance;
|
||||
|
||||
[SerializeField] private Loading _sceneLoading;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this; //만들어진 자신을 인스턴스로 설정
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject); //이미 인스턴스가 있으면 자신을 파괴
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SetSceneLoadingActive(false);
|
||||
}
|
||||
|
||||
public void SetSceneLoadingActive(bool flag)
|
||||
{
|
||||
_sceneLoading.gameObject.SetActive(flag);
|
||||
}
|
||||
|
||||
public void SetSceneLoadingProgressValue(float value)
|
||||
{
|
||||
_sceneLoading.LoadingImage.fillAmount = value;
|
||||
_sceneLoading.LoadingTextMeshProUGUI.text = $"{(value * 100):F0}% 로딩 중...";
|
||||
}
|
||||
public void SetSceneLoadingProgressValue(float value,string loadingText)
|
||||
{
|
||||
_sceneLoading.LoadingImage.fillAmount = value;
|
||||
_sceneLoading.LoadingTextMeshProUGUI.text = loadingText;
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/Managers/UI/GlobalUIManager.cs.meta
Normal file
2
Assets/02_Scripts/Managers/UI/GlobalUIManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b66ac6fc047ff644bac21bdf5b298a9c
|
||||
16
Assets/02_Scripts/Managers/UI/InGameUIManager.cs
Normal file
16
Assets/02_Scripts/Managers/UI/InGameUIManager.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class InGameUIManager : BaseUIManager
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/Managers/UI/InGameUIManager.cs.meta
Normal file
2
Assets/02_Scripts/Managers/UI/InGameUIManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f347da8e055eeb04bbf40bbcd5d2002f
|
||||
51
Assets/02_Scripts/Managers/UI/IntroUIManager.cs
Normal file
51
Assets/02_Scripts/Managers/UI/IntroUIManager.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class IntroUIManager : MonoBehaviour
|
||||
{
|
||||
[Header("Menu Settings")]
|
||||
public List<MenuButton> MenuButtons; // 인스펙터에서 버튼들을 등록함
|
||||
|
||||
private MenuLogic _menu; // 내부적으로 로직 객체를 들고 있음
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
private void Start()
|
||||
{
|
||||
SetMenuLogic(new MenuLogic(MenuButtons));
|
||||
|
||||
InputManager.Instance.SetUIInputMap("IntroUI");
|
||||
}
|
||||
|
||||
private void SetMenuLogic(MenuLogic menuLogic)
|
||||
{
|
||||
//혹시라도 나중에 이벤트를 재할당할 일이 있다면 반드시 기존 이벤트는 해제하고 연결해야함
|
||||
if(_menu != null)
|
||||
{
|
||||
InputManager.Instance.OnKeyDown_UpArrowEvent -= _menu.MenuMoveUp;
|
||||
InputManager.Instance.OnKeyDown_DownArrowEvent -= _menu.MenuMoveDown;
|
||||
InputManager.Instance.OnKeyDown_EnterEvent -= _menu.MenuConfirm;
|
||||
}
|
||||
|
||||
_menu = menuLogic;
|
||||
|
||||
InputManager.Instance.OnKeyDown_UpArrowEvent += _menu.MenuMoveUp;
|
||||
InputManager.Instance.OnKeyDown_DownArrowEvent += _menu.MenuMoveDown;
|
||||
InputManager.Instance.OnKeyDown_EnterEvent += _menu.MenuConfirm;
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
InputManager.Instance.OnKeyDown_UpArrowEvent -= _menu.MenuMoveUp;
|
||||
InputManager.Instance.OnKeyDown_DownArrowEvent -= _menu.MenuMoveDown;
|
||||
InputManager.Instance.OnKeyDown_EnterEvent -= _menu.MenuConfirm;
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/Managers/UI/IntroUIManager.cs.meta
Normal file
2
Assets/02_Scripts/Managers/UI/IntroUIManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9184a794080be324daa38d05d5f448da
|
||||
Reference in New Issue
Block a user