| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- using ShotSimulator.Screen;
- using ShotSimulator.Target;
- using ShotSimulator.Tool;
- using ShotSimulator.Train.Info;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Random = UnityEngine.Random;
- namespace ShotSimulator.Train
- {
- public class HorizontalMotionTargetTrackTrainHandle : BaseTrainHandle
- {
- private SphereShotTarget curTarget;
- private HorizontalMotionTargetTrackTrainDifficultyData m_DifficultyData;
- private HorizontalMotionTargetTrackTrainScoreData m_ScoreData;
- private bool firstScore;
- private double punitiveTime;
- private double m_TotalHoverTime;
- private double TotalHoverTime
- {
- get { return m_TotalHoverTime; }
- set
- {
- m_TotalHoverTime = value;
- UpdatePrecision();
- }
- }
- private double m_TotalMissTime;
- private double TotalMissTime
- {
- get { return m_TotalMissTime; }
- set
- {
- m_TotalMissTime = value;
- UpdatePrecision();
- }
- }
- public HorizontalMotionTargetTrackTrainHandle(BaseTrainCallBack callBack, BaseTrainInfo info, DifficultyType difficultyType) : base(callBack, info, difficultyType)
- {
- SetShotTargetInteractiveEvent(ShotTargetInteractiveType.OnHovering, OnHoveringTargetEvent);
- SetShotTargetInteractiveEvent(ShotTargetInteractiveType.OnNotEntering, OnNotHoveringEvent);
- m_DifficultyData = info.GetDifficultyData<HorizontalMotionTargetTrackTrainDifficultyData>(m_DifficultyType);
- m_ScoreData = info.GetScoreData<HorizontalMotionTargetTrackTrainScoreData>(m_DifficultyType);
- }
- private void GenerateShotTargets()
- {
- GameObject obj = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Prefabs/SphereTarget"));
- curTarget = obj.GetComponent<SphereShotTarget>();
- curTarget.IsRunning = true;
- List<Vector3> pos = new List<Vector3>();
- float distance = Random.Range(5f, 20f);
- Vector2 widthLimt = new Vector2(-8, 8);
- Vector2 heightLimt = new Vector2(-1.5f, 5f);
- pos.Add(ExtraTool.GetScreenOffsetPosition(new Vector2(0.5f - (m_DifficultyData.horizontalMotionDistance / 2), 0.5f), distance, widthLimt, heightLimt));
- pos.Add(ExtraTool.GetScreenOffsetPosition(new Vector2(0.5f + (m_DifficultyData.horizontalMotionDistance / 2), 0.5f), distance, widthLimt, heightLimt));
- if (ExtraTool.IsProbabolityInclusive(0.5f))
- {
- Vector3 temp = pos[0];
- pos[0] = pos[1];
- pos[1] = temp;
- }
- curTarget.onClickCanChangeColor = false;
- curTarget.onHoveringCanChangeColor = true;
- curTarget.defaultColor = ScreenEffectManager.GetInstance().GetTargetColor();
- curTarget.onHoveringColor = Color.green;
- curTarget.Init(2f, ReduceHealthTriggerType.OnHovering, true, ReduceHealthType.Time, MotionType.Foreach, ExtraTool.GetScreenOffsetPosition(new Vector2(0.5f, 0.5f), distance), pos, 2f);
- firstScore = false;
- }
- private void DestroyShootTarget(SphereShotTarget target)
- {
- if (target != null)
- {
- target.IsRunning = false;
- GameObject.Destroy(target.gameObject);
- }
- }
- private void ResetTarget()
- {
- if (curTarget != null)
- {
- GameObject.Destroy(curTarget.gameObject);
- curTarget = null;
- }
- }
- #region Train
- protected override void ResetTrain()
- {
- ResetTarget();
- punitiveTime = 0;
- firstScore = false;
- m_TotalHoverTime = 0;
- m_TotalMissTime = 0;
- }
- public override void StartTrain()
- {
- base.StartTrain();
- GenerateShotTargets();
- }
- public override void PauseTrain()
- {
- base.PauseTrain();
- curTarget.IsRunning = false;
- }
- public override void ContinueTrain()
- {
- base.ContinueTrain();
- curTarget.IsRunning = true;
- }
- public override void CalculateTrainResult()
- {
- SetResultMetricsDataValue(MetricsType.Precision, Math.Round(TotalHoverTime / (TotalHoverTime + TotalMissTime), 2));
- SetResultMetricsDataValue(MetricsType.AverageTimeOnTarget, Math.Round(TotalHoverTime, 2));
- }
- #endregion
- private void UpdatePrecision()
- {
- SetResultMetricsDataValue(MetricsType.Precision, Math.Round(TotalHoverTime / (TotalHoverTime + TotalMissTime), 2));
- }
- #region ShotTarget
- private void OnHoveringTargetEvent(BaseShotTarget target)
- {
- if (target != null)
- {
- SphereShotTarget t = target as SphereShotTarget;
- if (t != null)
- {
- if (t.CurHealth <= 0)
- {
- int comboS = Mathf.CeilToInt(m_ScoreData.secondBaseScore * comboNums * m_ScoreData.comboMul);
- IncreaseScore(m_ScoreData.secondBaseScore + comboS);
- DestroyShootTarget(t);
- GenerateShotTargets();
- comboNums++;
- }
- else if (t.CurHealth <= 1)
- {
- if (!firstScore)
- {
- firstScore = true;
- int comboS = Mathf.CeilToInt(m_ScoreData.firstBaseScore * comboNums * m_ScoreData.comboMul);
- IncreaseScore(m_ScoreData.firstBaseScore + comboS);
- }
- }
- }
- TotalHoverTime += Time.deltaTime;
- }
- }
- private void OnNotHoveringEvent(BaseShotTarget target)
- {
- punitiveTime += Time.deltaTime;
- if (punitiveTime >= 1)
- {
- comboNums = 0;
- punitiveTime = 0;
- int missPunitiveS = Mathf.CeilToInt(m_ScoreData.firstBaseScore * m_ScoreData.missPunitiveMul);
- IncreaseScore(missPunitiveS * -1);
- }
- TotalMissTime += Time.deltaTime;
- }
- #endregion
- }
- }
|