AkiraPixelWind/Assets/Scripts/Main/Definition/DataStruct/Input/InputMotionData.cs

156 lines
4.2 KiB
C#
Raw Normal View History

using Axibug;
using Axibug.Event;
using System;
using System.Collections.Generic;
using System.Configuration;
using UnityEngine;
namespace Game
{
public enum E_MOTION_TYPE
{
None,
Attack_1,
Attack_2,
Attack_3,
}
public class MontionkeyClass
{
public int Frame;
public E_MOTION_TYPE MontionType;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҽ<EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public class InputMotionData
{
/// <summary>
/// <20>ͷų<CDB7><C5B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ʷ
/// </summary>
List<MontionkeyClass> KeyHistory = new List<MontionkeyClass>();
static Queue<MontionkeyClass> tempHistoryQueue = new Queue<MontionkeyClass>();
const int MontionHistoryLimit = 10;
bool mNeedClear = false;
const float ClearCD = 0.3f;
//ʣ<><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
float flagTime = 0;
bool NeedClear { get { return mNeedClear; }
set {
if (value)
{
flagTime = ClearCD;
}
else
{
flagTime = 0;
}
mNeedClear = value;
}
}
public void Init()
{
ClearHistoryMotion();
}
public void OnEnable()
{
AppEntry.Event.Subscribe(MainPlayerOnceAttackEventArgs.EventId, OnMainPlayerInAttackEventArgs);
}
public void OnDestory()
{
AppEntry.Event.Unsubscribe(MainPlayerOnceAttackEventArgs.EventId, OnMainPlayerInAttackEventArgs);
}
private void OnMainPlayerInAttackEventArgs(object sender, LogicEventArgs e)
{
MainPlayerOnceAttackEventArgs msg = (MainPlayerOnceAttackEventArgs)e;
if (msg == null) throw new GameException("MainPlayerOnceAttackEventArgs is null");
if (msg.RoleID == GamePlayEntry.MainPlayer.Player.RoleID)
{
if (msg.Step == E_ONCEATTACK_STEP.InAttack)
NeedClear = false;
else if(msg.Step == E_ONCEATTACK_STEP.None)
NeedClear = true;
}
}
MontionkeyClass EnqueueOneMotionHistory()
{
if (tempHistoryQueue.Count > 0)
return tempHistoryQueue.Dequeue();
return new MontionkeyClass();
}
public void AddMontionKey(E_MOTION_TYPE type)
{
while (KeyHistory.Count > MontionHistoryLimit)
{
tempHistoryQueue.Enqueue(KeyHistory[0]);
KeyHistory.RemoveAt(0);
}
MontionkeyClass motion = EnqueueOneMotionHistory();
motion.Frame = Time.frameCount;
motion.MontionType = type;
KeyHistory.Add(motion);
}
public void ClearHistoryMotion()
{
for (int i = 0; i < KeyHistory.Count; i++)
{
tempHistoryQueue.Enqueue(KeyHistory[i]);
}
KeyHistory.Clear();
NeedClear = false;
AxibugLog.Debug("<22><><EFBFBD><EFBFBD>MotionHistory");
}
public bool CheckHistoryLastMotion(E_MOTION_TYPE type)
{
if (KeyHistory.Count == 0)
return false;
return KeyHistory[KeyHistory.Count - 1].MontionType == type;
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>Ƿ<EFBFBD>ƥ<EFBFBD><C6A5>
/// </summary>
/// <param name="types"></param>
/// <returns></returns>
public bool CheckHistoryLastMotion(E_MOTION_TYPE[] types)
{
if (KeyHistory.Count < types.Length)
return false;
for (int i = 0; i < types.Length; i++)
{
if (KeyHistory[KeyHistory.Count - i - 1].MontionType != types[types.Length - i - 1])
{
return false;
}
}
return true;
}
public void Update_Logic()
{
if (NeedClear)
{
flagTime -= Time.deltaTime;
if (flagTime <= 0)
{
ClearHistoryMotion();
NeedClear = false;
}
}
}
}
}