using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class App : MonoBehaviour
{
private GameMain gameMain;
private void Awake()
{
DontDestroyOnLoad(this.gameObject);
}
private void Start()
{
this.AddEventHandlers();
//비동기 씬로드
AsyncOperation oper = SceneManager.LoadSceneAsync("Game");
oper.completed += (obj) => {
this.gameMain = GameObject.FindAnyObjectByType<GameMain>();
Debug.LogFormat("gameMain: {0}", gameMain);
//gameMain.onReadyToStart = () => {
// Debug.Log("게임 준비가 되었음 게임을 시작 합니다.");
// gameMain.StartGame();
//};
gameMain.Init(100);
};
}
private void AddEventHandlers()
{
EventDispatcher.instance.AddEventHandler((short)GameEnums.eGameEvent.READY_TO_START, (eventType) => {
Debug.Log("게임 준비가 되었음 게임을 시작 합니다.");
});
EventDispatcher.instance.AddEventHandler((short)GameEnums.eGameEvent.GAME_OVER, (eventType) => {
Debug.Log("게임이 종료 되었습니다. 게임정보를 저장 합니다.");
});
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameMain : MonoBehaviour
{
[SerializeField] private GameObject playerPrefab;
private PlayerController playerController;
//public System.Action onReadyToStart;
public void Init(int damage)
{
this.CreatePlayer(damage);
Debug.Log("게임을 준비중....");
//이벤트를 발생
EventDispatcher.instance.SendEvent((short)GameEnums.eGameEvent.READY_TO_START);
//this.onReadyToStart();
}
private void CreatePlayer(int damage)
{
Debug.Log("플레이어를 생성합니다.");
var go = Instantiate<GameObject>(this.playerPrefab);
this.playerController = go.GetComponent<PlayerController>();
this.playerController.Init(damage);
}
public void StartGame()
{
Debug.Log("게임을 시작 합니다.");
}
}
'게임프로젝트 > 슈팅게임' 카테고리의 다른 글
팀프로젝트 (2) 플레이어 조이스틱 이동 (0) | 2024.03.21 |
---|---|
유니티 에셋을 이용한 오브젝트 풀링 (0) | 2024.03.20 |
ShootingSpace (5) 아이템 획득, 붐 이펙트 (0) | 2024.03.19 |
ShootingSpace (4) UI만들기 (0) | 2024.03.16 |
ShootingSpace (3) 플레이어와 적, 적 총알과 충돌 (0) | 2024.03.12 |