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

96 lines
2.4 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Configuration;
using UnityEngine;
namespace Game
{
public enum E_MOTION_TYPE
{
None,
Attack_1,
Attack_2,
}
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;
public void Init()
{
ClearHistoryMotion();
}
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();
}
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;
}
}
}