물체 생성 및 점수 세팅 추가
- 테이블에 해당하는 데이터 세팅 및 점수획득 로직 추가
This commit is contained in:
parent
4df1f6522f
commit
75e715340f
|
@ -12526,6 +12526,11 @@ PrefabInstance:
|
|||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 9161262214850749213, guid: 00e97690e9831f84e85295dd8972cd3e,
|
||||
type: 3}
|
||||
propertyPath: m_Enabled
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 9215673432559229180, guid: 00e97690e9831f84e85295dd8972cd3e,
|
||||
type: 3}
|
||||
propertyPath: m_Name
|
||||
|
|
|
@ -3,4 +3,25 @@ public enum E_TEAM
|
|||
None,
|
||||
Red,
|
||||
Blue,
|
||||
}
|
||||
}
|
||||
|
||||
public enum E_STAGE_TYPE
|
||||
{
|
||||
Single_Adventure,
|
||||
Single_TimeAttack,
|
||||
}
|
||||
|
||||
public enum E_STAGE_STATE
|
||||
{
|
||||
Ready,
|
||||
Playing,
|
||||
Pause,
|
||||
End,
|
||||
}
|
||||
|
||||
#region Table
|
||||
public enum E_TABLE
|
||||
{
|
||||
JPropInfo,
|
||||
}
|
||||
#endregion Table
|
|
@ -5,31 +5,35 @@ using UnityEngine;
|
|||
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] private MinigameController _minigameController;
|
||||
|
||||
|
||||
[SerializeField] private Renderer _characterRenderer;
|
||||
private bool _isPushed = false;
|
||||
|
||||
//Move values
|
||||
|
||||
|
||||
//private Rigidbody _rigidBody;
|
||||
|
||||
private PlayerMove _playerMove;
|
||||
|
||||
|
||||
|
||||
private E_TEAM _currentTeam = E_TEAM.None;
|
||||
private PlayerInfo _tableData;
|
||||
public bool IsBlock { get; private set; }
|
||||
|
||||
void Start()
|
||||
private void Start()
|
||||
{
|
||||
_playerMove = GetComponent<PlayerMove>();
|
||||
EventBus.Instance.Subscribe<EventSendMinigamePoint>(OnGetMinigamePoint);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
EventBus.Instance.Unsubscribe<EventSendMinigamePoint>(OnGetMinigamePoint);
|
||||
}
|
||||
|
||||
public void SetData()
|
||||
{
|
||||
_currentTeam = E_TEAM.Red;
|
||||
_tableData = new PlayerInfo();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
private void Update()
|
||||
{
|
||||
if(IsBlock)
|
||||
{
|
||||
|
@ -79,7 +83,7 @@ public class PlayerController : MonoBehaviour
|
|||
var prop = collider.GetComponent<PropController>();
|
||||
if(prop != null)
|
||||
{
|
||||
prop.Explode(new PlayerInfo(), transform.position, E_TEAM.Blue);
|
||||
prop.Explode(_tableData, transform.position, _currentTeam);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,14 +97,26 @@ public class PlayerController : MonoBehaviour
|
|||
Push(e.MinigamePoint);
|
||||
}
|
||||
|
||||
public void Respawn()
|
||||
{
|
||||
IsBlock = false;
|
||||
_characterRenderer.enabled = true;
|
||||
}
|
||||
|
||||
public void Block()
|
||||
{
|
||||
_characterRenderer.enabled = false;
|
||||
IsBlock = true;
|
||||
}
|
||||
|
||||
#region Collision
|
||||
|
||||
private void OnCollisionExit(Collision collision)
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
if(collision.gameObject.layer == LayerMask.NameToLayer("Remove"))
|
||||
if (other.gameObject.layer == LayerMask.NameToLayer("Remove"))
|
||||
{
|
||||
Block();
|
||||
StageManager.Instance.PlayerFall(this);
|
||||
IsBlock = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using FirstVillain.Entities;
|
||||
using FirstVillain.EventBus;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
@ -8,17 +9,28 @@ public class PropController : MonoBehaviour
|
|||
//»ý¼º ½Ã FX
|
||||
private E_TEAM _hitTeam = E_TEAM.None;
|
||||
|
||||
private CharacterController _controller;
|
||||
|
||||
private Rigidbody _rigidBody;
|
||||
|
||||
private JPropInfoData _data;
|
||||
private void Start()
|
||||
{
|
||||
_rigidBody = GetComponent<Rigidbody>();
|
||||
|
||||
}
|
||||
|
||||
public void SetData()
|
||||
public void SetData(JPropInfoData data, Bounds bound)
|
||||
{
|
||||
//몇점인지.. 테이블이 낫겠지?
|
||||
_rigidBody = GetComponent<Rigidbody>();
|
||||
|
||||
_data = data;
|
||||
|
||||
_rigidBody.mass = _data.Mass;
|
||||
|
||||
var randomPos = new Vector3(
|
||||
Random.Range(bound.min.x, bound.max.y),
|
||||
Random.Range(bound.min.y, bound.max.z),
|
||||
Random.Range(bound.min.z, bound.max.z));
|
||||
|
||||
transform.position = randomPos;
|
||||
}
|
||||
|
||||
public void Explode(PlayerInfo info, Vector3 position, E_TEAM team)
|
||||
|
@ -30,19 +42,18 @@ public class PropController : MonoBehaviour
|
|||
_rigidBody.AddExplosionForce(power, position, range);
|
||||
|
||||
_hitTeam = team;
|
||||
|
||||
//추락 음... 바닥에 콜라이더를 둘까
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (other.gameObject.layer == LayerMask.NameToLayer("Remove"))
|
||||
{
|
||||
//StageManager에 팀 보내서 점수 획득 요청
|
||||
Debug.Log("점수 획득");
|
||||
EventBus.Instance.Publish(new EventPropRemoved());
|
||||
AddressableManager.Instance.Release(gameObject);
|
||||
//제거
|
||||
if(_hitTeam != E_TEAM.None)
|
||||
{
|
||||
StageManager.Instance.UpdateScore(_hitTeam, _data.Point);
|
||||
EventBus.Instance.Publish(new EventPropRemoved());
|
||||
AddressableManager.Instance.Release(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using FirstVillain.Entities;
|
||||
using FirstVillain.EventBus;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
@ -12,8 +13,11 @@ public class SpawnController : MonoBehaviour
|
|||
private int _maxPropCount = 50;
|
||||
private int _curPropCount = 0;
|
||||
|
||||
private List<JPropInfoData> _PropDataList = new();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
||||
EventBus.Instance.Subscribe<EventPropRemoved>(OnPropRemoved);
|
||||
}
|
||||
|
||||
|
@ -21,65 +25,87 @@ public class SpawnController : MonoBehaviour
|
|||
{
|
||||
EventBus.Instance.Unsubscribe<EventPropRemoved>(OnPropRemoved);
|
||||
}
|
||||
|
||||
//최초 플레이어 프리팹 로드 및 생성
|
||||
public PlayerController SpawnPlayer()
|
||||
//TODO : 씬 외부에서 선택된 플레이어 정보를 넘겨주고 해당 데이터를 받아 생성한다.
|
||||
public void SpawnPlayer(string prefab/*추후 데이터로 교체*/, System.Action<PlayerController> result)
|
||||
{
|
||||
//프리팹 로드
|
||||
|
||||
//Instantiate
|
||||
|
||||
//위치 조정
|
||||
return new PlayerController();
|
||||
TableManager.Instance.GetPropInfoList(E_TABLE.JPropInfo, propList =>
|
||||
{
|
||||
_PropDataList = propList;
|
||||
AddressableManager.Instance.Spawn(prefab, null, onComplete =>
|
||||
{
|
||||
var controller = onComplete.GetComponent<PlayerController>();
|
||||
controller.SetData();
|
||||
controller.Block();
|
||||
RespawnPlayer(controller);
|
||||
result(controller);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public void RespawnPlayer(PlayerController player)
|
||||
{
|
||||
player.transform.position = _playerSpawnPos.position;
|
||||
player.transform.rotation = _playerSpawnPos.rotation;
|
||||
|
||||
StartCoroutine(RespawnDelay(player));
|
||||
}
|
||||
|
||||
//타입별로 만들어야 할까..?
|
||||
public void SpawnProp()
|
||||
public void StartSpawnProp()
|
||||
{
|
||||
StartCoroutine(StartSpawnProps());
|
||||
StartCoroutine(SpawnPropsCoroutine());
|
||||
}
|
||||
|
||||
private IEnumerator StartSpawnProps()
|
||||
private IEnumerator SpawnPropsCoroutine()
|
||||
{
|
||||
//TODO : 게임 플레이 중으로 변경필요
|
||||
while(true)
|
||||
//TODO : 일시 정지 상태가 있으면 변경필요
|
||||
while(StageManager.Instance.IsPlaying)
|
||||
{
|
||||
yield return new WaitForSeconds(1f);
|
||||
if (_curPropCount < _maxPropCount)
|
||||
{
|
||||
AddressableManager.Instance.Spawn("Crate_01", null, OnSpawnedProp);
|
||||
_curPropCount++;
|
||||
SelectProp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSpawnedProp(GameObject obj)
|
||||
private void SelectProp()
|
||||
{
|
||||
int rnd = Random.Range(0, _propGenerateArea.Count);
|
||||
var bound = _propGenerateArea[rnd];
|
||||
var randomPos = new Vector3(
|
||||
Random.Range(bound.min.x, bound.max.y),
|
||||
Random.Range(bound.min.y, bound.max.z),
|
||||
Random.Range(bound.min.z, bound.max.z));
|
||||
//확률로?
|
||||
//고정?
|
||||
//우선 해당 테이블을 가져와서 고르는 형태
|
||||
var targetProp = _PropDataList.Find(arg => arg.PrefabName == "Crate_01");
|
||||
|
||||
obj.transform.position = randomPos;
|
||||
//우선 확률로 가져왔다고 가정
|
||||
GenerateProp(targetProp);
|
||||
}
|
||||
|
||||
private void GenerateProp(JPropInfoData data)
|
||||
{
|
||||
AddressableManager.Instance.Spawn(data.PrefabName, null, prop =>
|
||||
{
|
||||
var controller = prop.GetComponent<PropController>();
|
||||
|
||||
int rnd = Random.Range(0, _propGenerateArea.Count);
|
||||
var bound = _propGenerateArea[rnd];
|
||||
controller.SetData(data, bound);
|
||||
|
||||
_curPropCount++;
|
||||
});
|
||||
}
|
||||
|
||||
private void OnPropRemoved(EventPropRemoved e)
|
||||
{
|
||||
_curPropCount--;
|
||||
}
|
||||
//캐릭터 낙하 시 재생성
|
||||
|
||||
private IEnumerator RespawnDelay(PlayerController controller)
|
||||
{
|
||||
//TODO : UI에 재생성 시간 표기
|
||||
yield return new WaitForSeconds(3f);
|
||||
|
||||
//아이템 재생성(30초마다 없는 곳에 생성)
|
||||
|
||||
//물체 최초 여기서 생성
|
||||
//테이블 데이터에 맞게 고정생성?
|
||||
//생성 데이터 어디서 관리할지?
|
||||
controller.Respawn();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,20 @@
|
|||
using FirstVillain.Entities;
|
||||
using FirstVillain.Singleton;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
[Serializable]
|
||||
public class Wrapper<T>
|
||||
{
|
||||
public List<T> list;
|
||||
}
|
||||
|
||||
public class StageManager : UnitySingletonOnce<StageManager>
|
||||
{
|
||||
[SerializeField] private SpawnController _spawnController;
|
||||
|
@ -13,28 +22,67 @@ public class StageManager : UnitySingletonOnce<StageManager>
|
|||
private PlayerController _currentPlayer;
|
||||
private Dictionary<E_TEAM, int> _teamScoreDict = new();
|
||||
|
||||
private E_STAGE_TYPE _currentStageType;
|
||||
private E_STAGE_STATE _state;
|
||||
|
||||
public bool IsPlaying { get { return _state == E_STAGE_STATE.Playing; } }
|
||||
|
||||
private void Start()
|
||||
{
|
||||
//AddressableManager.Instance.Spawn("Crate_02", null, OnCompleteLoad);
|
||||
_spawnController.SpawnProp();
|
||||
//임시 호출
|
||||
Init(E_STAGE_TYPE.Single_TimeAttack, "Player_Cop");
|
||||
}
|
||||
|
||||
private void Init(E_STAGE_TYPE type, string prefab/*추후 테이블*/)
|
||||
{
|
||||
_currentStageType = type;
|
||||
_state = E_STAGE_STATE.Ready;
|
||||
InitScore();
|
||||
//TODO : UI초기화
|
||||
_spawnController.SpawnPlayer(prefab, result =>
|
||||
{
|
||||
//시작 시간표기?
|
||||
StartGame();
|
||||
});
|
||||
}
|
||||
|
||||
private void InitScore()
|
||||
{
|
||||
switch(_currentStageType)
|
||||
{
|
||||
case E_STAGE_TYPE.Single_Adventure:
|
||||
case E_STAGE_TYPE.Single_TimeAttack:
|
||||
_teamScoreDict.Add(E_TEAM.Red, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void StartGame()
|
||||
{
|
||||
_state = E_STAGE_STATE.Playing;
|
||||
StartCoroutine(PlayTimer(Constants.PLAY_TIME));
|
||||
_spawnController.StartSpawnProp();
|
||||
}
|
||||
|
||||
public void UpdateScore(E_TEAM team, int score)
|
||||
{
|
||||
if (_teamScoreDict.ContainsKey(team))
|
||||
{
|
||||
_teamScoreDict[team] += score;
|
||||
//TODO : UI 표기
|
||||
Debug.Log($"Current Score : {_teamScoreDict[team]}");
|
||||
}
|
||||
}
|
||||
|
||||
//낙하했을 때
|
||||
public void PlayerFall(PlayerController player)
|
||||
{
|
||||
player.gameObject.SetActive(false);
|
||||
_spawnController.RespawnPlayer(player);
|
||||
//<2F><>...
|
||||
//_spawnController.RespawnPlayer(_currentPlayer);
|
||||
}
|
||||
|
||||
public void GameOver()
|
||||
{
|
||||
_state = E_STAGE_STATE.End;
|
||||
//게임 종료 UI 호출
|
||||
}
|
||||
|
||||
|
@ -42,9 +90,16 @@ public class StageManager : UnitySingletonOnce<StageManager>
|
|||
private IEnumerator PlayTimer(float time)
|
||||
{
|
||||
float timer = 0;
|
||||
float secTimer = 0;
|
||||
while(timer < time)
|
||||
{
|
||||
timer += Time.deltaTime;
|
||||
secTimer += Time.deltaTime;
|
||||
if(secTimer >= 1f)
|
||||
{
|
||||
secTimer = 0;
|
||||
//UI에 표기 시간 감소(초)
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user