| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- using cfg;
- using SimpleJSON;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using TMPro;
- using Sirenix.OdinInspector;
- public enum SoldierType
- {
- [LabelText("飞剑")] sword = 0,
- [LabelText("胖子")] shield = 1,
- [LabelText("林冲")] spear = 2,
- [LabelText("阴灵")] Spirits = 3,
- }
- public enum GameType
- {
- Gaming,
- GameEnd,
- Shop,
- }
- public class GameManager : MonoBehaviour
- {
- public static GameManager instance;
- [FoldoutGroup("组件", order: -1)] public UIHP p1uiHP;
- [FoldoutGroup("组件")] public UIHP p1uiMP;
- [FoldoutGroup("组件")] public Transform p1uiRush;
- [FoldoutGroup("组件")] public GameObject[] demonicNum;
- [FoldoutGroup("组件")] public TextMeshProUGUI text;
- [FoldoutGroup("组件")] public GameObject chapterBG; //当前关卡的原始背景(用于和boss背景做替换)
- [FoldoutGroup("组件")] public GameObject shopButton;
- [FoldoutGroup("组件")] public ShopUI shopUI;
- [FoldoutGroup("组件")] public TextMeshProUGUI moneyText;
- [FoldoutGroup("金币结算", order: -1)][LabelText("限制时间")] public int rewardTime;
- [FoldoutGroup("金币结算")][LabelText("金币奖励")] public int totalMoney;
- [FoldoutGroup("金币结算")][LabelText("额外金币奖励")] public int extraMoney;
- [FoldoutGroup("金币结算")][LabelText("惩罚时间间隔")] public int deductMoneyTime;
- [FoldoutGroup("金币结算")][LabelText("每次惩罚扣除金币数量")] public int deductMoney;
- public LeveType leveType;
- [LabelText("下一关倍率增幅")] public List<float> ratioIncrease = new List<float> { 0.4f, 1.6f, -0.8f };
- public int money;
- public float gameTime;
- public float totalGameTime;
- public Tables allCfgData;
- static public SoldierType[] curSoldiers; //本局游戏选择的三个士兵
- public List<CreateEnemyConfig> createEnemyConfigs;
- [DisplayOnly] public GameType gameType;
- [DisplayOnly] public float levelRatio = 1;
- private JSONNode Loader(string fileName)
- {
- return JSON.Parse(File.ReadAllText("GenerateDatas/json/" + fileName + ".json"));
- }
- public void GetAllExcel()
- {
- allCfgData = new Tables(Loader);
- }
- public void ReloadCfgCreateEnemyData()
- {
- createEnemyConfigs = new List<CreateEnemyConfig>(); ;
- for (int i = 0; i < 9; i++)
- {
- JSONNode keyValuePairs = JSON.Parse(File.ReadAllText($"GenerateDatas/json/CfgCreateEnemy{i}.json"));
- CreateEnemyConfig createEnemyConfig = new CreateEnemyConfig(keyValuePairs);
- createEnemyConfigs.Add(createEnemyConfig);
- }
- }
- private void Awake()
- {
- //选定本局游戏有哪些士兵,后面兵多了这里要改
- curSoldiers = new SoldierType[3];
- curSoldiers[0] = SoldierType.sword;
- curSoldiers[1] = SoldierType.shield;
- curSoldiers[2] = SoldierType.spear;
- if (!instance)
- {
- instance = this;
- GetAllExcel();
- ReloadCfgCreateEnemyData();
- }
- else
- {
- DestroyImmediate(gameObject);
- return;
- }
- leveType = LeveType.Introduction;
- }
- private void Start()
- {
- gameTime = 0;
- gameType = GameType.Gaming;
- }
- private void FixedUpdate()
- {
- if (gameType == GameType.Gaming)
- {
- gameTime += Time.deltaTime;
- totalGameTime += Time.deltaTime;
- EnemyCreater.instance.OnGameTimeChange(gameTime);
- int timeText = (int)gameTime;
- //text.text = $"{timeText / 60:D2}:{timeText % 60:D2}({timeText}s)";
- text.text = $"{timeText}";
- }
- }
- //游戏结束
- public void GameEnd()
- {
- gameType = GameType.GameEnd;
- foreach (List<Enemy> objs in EnemyCreater.instance.enemyDic.Values)
- {
- for (int i = 0; i < objs.Count; i++)
- {
- if (objs[i].gameObject.activeSelf)
- {
- objs[i].killer = null;
- objs[i].ChangeState(CharacterState.Die);
- }
- }
- }
- if (leveType == LeveType.Boss)
- {
- return;
- }
- AddMoney();
- shopButton.SetActive(true);
- }
-
- public void AddMoney()
- {
- int addMoney;
- if(gameTime < rewardTime)
- {
- addMoney = totalMoney + extraMoney;
- }
- else
- {
- int extraTime = (int)gameTime - rewardTime;
- addMoney = Mathf.Clamp(totalMoney - (extraTime / deductMoneyTime) * deductMoney, 0, totalMoney);
- }
- money += addMoney;
- moneyText.text = $"{money}";
- }
- //下一关
- public void NextLevel()
- {
- shopButton.SetActive(false);
-
- switch (leveType)
- {
- case LeveType.Introduction:
- EnemyCreater.instance.GetLevelOrientation(0);
- leveType = LeveType.Development;
- levelRatio += ratioIncrease[0];
- break;
- case LeveType.Development:
- EnemyCreater.instance.GetLevelOrientation(1);
- leveType = LeveType.Transition;
- levelRatio += ratioIncrease[1];
- break;
- case LeveType.Transition:
- leveType = LeveType.Conclusion;
- levelRatio += ratioIncrease[2];
- break;
- case LeveType.Conclusion:
- leveType = LeveType.Boss;
- break;
- }
- PlayersInput.instance[0].PlayerRevive();
- foreach(List<GameObject> objs in PoolManager.instance.activeObjs.Values)
- {
- List<GameObject> newObjs = new List<GameObject>(objs);
- for(int i = 0; i < newObjs.Count; i++)
- {
- newObjs[i].gameObject.SetActive(false);
- }
- }
- EnemyCreater.instance.Init();
- LevelSelect.instance.ChangeText();
- gameTime = 0;
- gameType = GameType.Gaming;
- }
- public void ShowShop()
- {
- gameType = GameType.Shop;
- shopUI.gameObject.SetActive(true);
- }
- }
|