123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using ShadowKit;
- public class BiologyGameController : GameBaseController
- {
- [SerializeField]
- private BloodManager m_bloodManager;//刷怪工具
- [SerializeField]
- private Bowman m_bowman;//抓怪逻辑
- private int score = 0;
- private float gameTime = 0;
- private float MaxTime = 60;//俩分钟
- private bool isRunning = false;
- private void Awake()
- {
- GameStop();
- }
- protected override void Start()
- {
- base.Start();
- MessageCenterController.Instance.Register(GameEnum.MESSAGE_SCORE_ADD, AddScore);
- MessageCenterController.Instance.Register(GameEnum.MESSAGE_SCORE_DEC, DecScore);
- }
- protected override void OnDestroy()
- {
- base.OnDestroy();
- MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_SCORE_ADD, AddScore);
- MessageCenterController.Instance.UnRegister(GameEnum.MESSAGE_SCORE_DEC, DecScore);
- }
- private void OnDisable()
- {
- //被切换出去的时候要重置数据
- Score = 0;//重置分数
- gameTime = MaxTime;//重置游戏时间
- GameStop();
- }
- //游戏开始
- protected override void GameStart()
- {
- base.GameStart();
- if (isRunning)
- {
- return;
- }
- Score = 0;//重置分数
- isRunning = true;
- gameTime = MaxTime;//重置游戏时间
- m_bloodManager.StartCreate(); ;
- m_bowman.gameObject.SetActive(true);
- if(IsInvoking("HeartJump"))
- {
- CDebug.Log("心跳错误");
- return;
- }
- InvokeRepeating("HeartJump", 1, 1);
- }
- protected override void GameQuit()
- {
- base.GameQuit();
- GameStop();
- }
- //private float las
- private void LateUpdate()
- {
-
- }
- //游戏停止
- private void GameStop()
- {
- isRunning = false;
- m_bloodManager.StopCreate();
- m_bowman.gameObject.SetActive(false);
- if (IsInvoking("HeartJump"))
- {
- CDebug.Log("移除心跳");
- CancelInvoke("HeartJump");
- return;
- }
- }
- private void AddScore(System.Object obj = null)
- {
- if (!isRunning)
- {
- return;
- }
- BloodItem item = (BloodItem)obj;
- if (m_bowman.IsGod(item))
- {
- //只有拿了水加分
- if (item.MType.Equals(BloodManager.BloodItemType.Water))
- {
- CDebug.Log("add score");
- Score += 3;
- }
- else
- {
- Score += 10;
- }
- }
- else
- {
- CDebug.Log("拿错扣分");
- Score -= 2;
- }
- UI.RefreshText((int)gameTime, Score);
- }
- public int Score
- {
- get { return score; }
- set {
- score = Mathf.Clamp(value, 0, 100);
- if(score >= 100)
- {
- //满分自动结束
- GameStop();
- SendResult();
- }
- }
- }
- private const int desScoreValue = 3;
- private void DecScore(System.Object obj = null)
- {
- if (!isRunning)
- {
- return;
- }
- BloodItem item = (BloodItem)obj;
- if (m_bowman.IsRecyle(item))
- {
- CDebug.Log("漏掉了" + item.MType.ToString());
- Score -= desScoreValue;
- }
- UI.RefreshText((int)gameTime, Score);
- }
- //心跳倒计时
- private void HeartJump()
- {
- gameTime -= 1;
- UI.RefreshText((int)gameTime, Score);
- if (gameTime <= 0)
- {
-
- GameStop();
- SendResult();
- }
- }
- //游戏结算预留
- private void SendResult()
- {
- UI.RefreshText((int)gameTime, Score);
- SendResultData(Score);
- }
- private BiologyGameUI UI
- {
- get {
- return base.m_UI as BiologyGameUI;
- }
- }
- }
|