using System; using System.Collections; using System.Collections.Generic; using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Engines; using Common; using DragonLi.Core; using UnityEngine; using UnityEngine.PlayerLoop; using XPlugin.Data.JsonLiteDB; using static XPlugin.Data.JsonLiteDB.JsonLiteDB; using LitJson; using Pathfinding; using DarkTonic.MasterAudio; using NaughtyAttributes; using UnityEngine.UIElements; /// /// 游戏状态 /// public enum GameState { None = 0, Playing = 1, /// /// 胜利 /// Victory = 2, /// /// 失败 /// Failur = 3, Settle } public class GameManager : MonoBehaviour { public static GameManager Ins { get; private set; } public TaskManager taskManager; public GameState gameState; public float vistEnd = 60 * 10; public GameObject wuHui; //预制体 public GameObject playerPre; public GameObject enemyPre; public GameObject gemKeyPre; public GameObject eggBulletPre; public GameObject eggBulletExPre; public GameObject gameStartDoor; public RightHand playerRightHand; public Enemy enemy; public bool isStartGame = false; void Awake() { Ins = this; } private void Start() { isStartGame = false; wuHui.SetActive(false); } public void GameStart() { isStartGame = true; HUDPanel.Show(); taskManager.bg.SetActive(true); CreateEnemy(new Vector3(0,1,5), new Vector3(0,180,0)); // enemy.SetState(2); // taskManager.curTaskId = 2; // taskManager.StartTask(); // taskManager.curTaskId = 3; // taskManager.StartTask(); // CreateEnemy(new Vector3(0,1,5), new Vector3(0,180,0)); // enemy.SetState(3); // taskManager.curTaskId = 4; // taskManager.StartTask(); } public void LoginGame() { CreatePlayer(); //PlaySound2DRPC("1.25"); PlayBGM(0); CreateGameStartDoor(new Vector3(0,0,2)); } public void PlayBGM(int id) { foreach (var item in GameLocal.Ins.BGM) { item.SetActive(false); } GameLocal.Ins.BGM[id].SetActive(true); } public void GameOver(GameState state) { } /// /// 更新配置表 /// public void UpdateConf() { // string text = Resources.Load("Data").text; // if (text != null) // { // ParseGameJson(text); // } } public void ParseGameJson(string text) { // DB = new JsonLiteDB(); // DB.Load(text); // // TableReader infoReader = DB["EnemysInfo"].GetReader(); // while (infoReader.Read()) // { // EnemyInfo info = new EnemyInfo(infoReader); // // } Debug.Log("游戏数值更新 -> complete"); } public void StopBgm() { } public void PlaySound2DRPC(string sound) { MasterAudio.PlaySound(sound); } public void PlaySound3DRPC(string sound,Transform soundTran,bool isStop=false) { if(isStop) MasterAudio.StopAllSoundsOfTransform(soundTran); MasterAudio.PlaySound3DAtTransform(sound, soundTran); } public void CreateGameStartDoor(Vector3 pos) { var door= Instantiate(gameStartDoor, pos, Quaternion.identity); door.transform.eulerAngles = new Vector3(0, 180, 0); MonoSingleton.Instance.WaitSecondTodo(() => { if (!isStartGame) { door.gameObject.GetComponent().enabled = false; door.gameObject.SetActive(false); Destroy(door.gameObject); if (taskManager.curTaskId != 4) { GameStart(); } else { StartDance(); } } },5); } public void CreatePlayer() { Instantiate(playerPre); } public void CreateEnemy(Vector3 pos,Vector3 eulerAngles) { var curEnemy=Instantiate(enemyPre,pos,Quaternion.identity); curEnemy.transform.eulerAngles = eulerAngles; curEnemy.GetComponent().Init(); enemy = curEnemy.GetComponent(); } public GameObject CreateGemKey(Vector3 pos,Vector3 eulerAngles,Transform box) { var key= Instantiate(gemKeyPre, pos,Quaternion.identity); key.transform.eulerAngles = eulerAngles; key.transform.parent = box; return key; } public void CreateEggBullet(Vector3 pos) { var egg= Instantiate(eggBulletPre, pos,Quaternion.identity); egg.GetComponent().Init(); } public void CreateEggEx(Vector3 pos) { var eggEx= Instantiate(eggBulletExPre, pos,Quaternion.identity); PlaySound2DRPC("1.23"); MonoSingleton.Instance.WaitSecondTodo(() => { Destroy(eggEx); },5f); } public void PlayerHit() { //玩家UI模糊 HUDPanel.Ins.ShowEgg(); Debug.Log("击中玩家"); PlaySound2DRPC("1.50"); } public void EnemyHit(Vector3 pos) { enemy.Hit(); PlaySound3DRPC("1.49",enemy.transform,true); CreateEggEx(pos); } public void EnemyTimeHit() { enemy.isTimeHit = true; } public void StartGameEnd() { //任务结束 PlaySound2DRPC("1.24"); playerRightHand.ChangeHand(); taskManager.OverTask(); isStartGame = false; CreateGameStartDoor(GameLocal.Ins.self.transform.position.ReflectVectorXOZ()+new Vector3(0,0,2)); } public void StartDance() { //开启舞会 Debug.LogError("开启舞会场景"); PlayBGM(1); wuHui.SetActive(true); taskManager.bg.SetActive(false); MonoSingleton.Instance.WaitSecondTodo(() => { WinPanel.Show(); },10f); } private void Update() { if (Input.GetKeyDown(KeyCode.Q)) { CreateEnemy(new Vector3(0,1,5), new Vector3(0,180,0)); enemy.SetState(3); taskManager.curTaskId = 4; taskManager.StartTask(); } } #region 工具 public string GetLessTimeStr() { string res = ""; if (gameState == GameState.Playing) { res = FormatTime((int)(vistEnd - DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalSeconds)); } return res; } public int GetLessTimeSeconds() { return (int)(vistEnd - DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalSeconds); } // 时分秒 public string FormatTime(int totalSeconds) { int hours = totalSeconds / 3600; // string hh = hours < 10 ? "0" + hours : hours.ToString(); int minutes = (totalSeconds - hours * 3600) / 60; string mm = minutes < 10f ? "0" + minutes : minutes.ToString(); int seconds = totalSeconds - hours * 3600 - minutes * 60; string ss = seconds < 10 ? "0" + seconds : seconds.ToString(); return string.Format("{0}:{1}", mm, ss); } #endregion }