물체 생성 임시코드 구현

This commit is contained in:
villaingames 2023-10-07 18:09:24 +09:00
parent c8d193ab47
commit 158f96bd77
5 changed files with 74 additions and 13 deletions

View File

@ -5,4 +5,11 @@ using UnityEngine;
public static class Constants public static class Constants
{ {
public static readonly float PLAY_TIME = 60; public static readonly float PLAY_TIME = 60;
//TODO : 마우스 감도 조절 등에 변경 가능한지 확인 필요
public static readonly float CAM_TURN_SPEED = 40;
//TODO : 캐릭터 데이터 완료되면 데이터 값으로 사용해야함
public static readonly float MOVE_SPEED = 3;
public static readonly float JUMP_FORCE = 3f;
} }

View File

@ -1,3 +1,4 @@
using FirstVillain.EventBus;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
@ -7,6 +8,8 @@ public class PropController : MonoBehaviour
//생성 시 FX //생성 시 FX
private E_TEAM _hitTeam = E_TEAM.None; private E_TEAM _hitTeam = E_TEAM.None;
private CharacterController _controller;
private Rigidbody _rigidBody; private Rigidbody _rigidBody;
private void Start() private void Start()
{ {
@ -37,6 +40,7 @@ public class PropController : MonoBehaviour
{ {
//StageManager에 팀 보내서 점수 획득 요청 //StageManager에 팀 보내서 점수 획득 요청
Debug.Log("점수 획득"); Debug.Log("점수 획득");
EventBus.Instance.Publish(new EventPropRemoved());
AddressableManager.Instance.Release(gameObject); AddressableManager.Instance.Release(gameObject);
//제거 //제거
} }

View File

@ -1,3 +1,4 @@
using FirstVillain.EventBus;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
@ -6,7 +7,20 @@ public class SpawnController : MonoBehaviour
{ {
[SerializeField] private List<Transform> _itemSpawnPosList; [SerializeField] private List<Transform> _itemSpawnPosList;
[SerializeField] private Transform _playerSpawnPos; [SerializeField] private Transform _playerSpawnPos;
[SerializeField] private List<Bounds> _propGenerateArea;
private int _maxPropCount = 50;
private int _curPropCount = 0;
private void Start()
{
EventBus.Instance.Subscribe<EventPropRemoved>(OnPropRemoved);
}
private void OnDestroy()
{
EventBus.Instance.Unsubscribe<EventPropRemoved>(OnPropRemoved);
}
//최초 플레이어 프리팹 로드 및 생성 //최초 플레이어 프리팹 로드 및 생성
public PlayerController SpawnPlayer() public PlayerController SpawnPlayer()
{ {
@ -23,6 +37,45 @@ public class SpawnController : MonoBehaviour
player.transform.position = _playerSpawnPos.position; player.transform.position = _playerSpawnPos.position;
player.transform.rotation = _playerSpawnPos.rotation; player.transform.rotation = _playerSpawnPos.rotation;
} }
//타입별로 만들어야 할까..?
public void SpawnProp()
{
StartCoroutine(StartSpawnProps());
}
private IEnumerator StartSpawnProps()
{
//TODO : 게임 플레이 중으로 변경필요
while(true)
{
yield return new WaitForSeconds(1f);
if (_curPropCount < _maxPropCount)
{
AddressableManager.Instance.Spawn("Crate_01", null, OnSpawnedProp);
_curPropCount++;
}
}
yield break;
}
public void OnSpawnedProp(GameObject obj)
{
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));
obj.transform.position = randomPos;
}
private void OnPropRemoved(EventPropRemoved e)
{
_curPropCount--;
}
//캐릭터 낙하 시 재생성 //캐릭터 낙하 시 재생성

View File

@ -14,3 +14,8 @@ public class EventSendMinigamePoint : EventBase
MinigamePoint = point; MinigamePoint = point;
} }
} }
public class EventPropRemoved : EventBase
{
}

View File

@ -13,30 +13,22 @@ public class StageManager : UnitySingletonOnce<StageManager>
private PlayerController _currentPlayer; private PlayerController _currentPlayer;
private Dictionary<E_TEAM, int> _teamScoreDict = new(); private Dictionary<E_TEAM, int> _teamScoreDict = new();
//1. 물체를 맵에 미리 생성한다.
//2. 물체를 전부 리스트에 넣어놓고 다 없어질 경우 게임 종료
//3. 타이머 존재(5분) - 타이머 종료 시 게임 종료
//4. 게임 종료 시 다 없앤 시간(기록), 떨군 물체 개수 표기(x 점수),
//5. 총 점수에 따라 코인 획득
private void Start() private void Start()
{ {
AddressableManager.Instance.Spawn("Crate_02", null, OnCompleteLoad); //AddressableManager.Instance.Spawn("Crate_02", null, OnCompleteLoad);
_spawnController.SpawnProp();
} }
public void StartGame() public void StartGame()
{ {
StartCoroutine(PlayTimer(Constants.PLAY_TIME)); StartCoroutine(PlayTimer(Constants.PLAY_TIME));
} }
private void OnCompleteLoad(GameObject obj)
{
Debug.Log("생성 완료");
obj.name = "Test";
}
//낙하했을 때 //낙하했을 때
public void PlayerFall(PlayerController controller) public void PlayerFall(PlayerController player)
{ {
player.gameObject.SetActive(false);
_spawnController.RespawnPlayer(player);
//음... //음...
//_spawnController.RespawnPlayer(_currentPlayer); //_spawnController.RespawnPlayer(_currentPlayer);
} }