159 lines
4.3 KiB
C#
159 lines
4.3 KiB
C#
|
using Game;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
|
|||
|
public class PlayRoleSnapshotClass
|
|||
|
{
|
|||
|
public float time;
|
|||
|
public Sprite mSprite;
|
|||
|
public Vector3 BridgeDir;
|
|||
|
public Vector3 Pos;
|
|||
|
public void Reset()
|
|||
|
{
|
|||
|
time = 0;
|
|||
|
mSprite = null;
|
|||
|
BridgeDir = Vector3.zero;
|
|||
|
Pos = Vector3.zero;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public class RoleFastShadow : MonoBehaviour
|
|||
|
{
|
|||
|
protected Transform mBridgeTransfrom;
|
|||
|
protected Transform mModelTransfrom;
|
|||
|
protected SpriteRenderer mSpriteRenderer;
|
|||
|
Vector3 offset = new Vector3(0, 0, 0.1f);
|
|||
|
|
|||
|
public int CurrPlayIndex = -1;
|
|||
|
public float NextPlayTime = 0;
|
|||
|
public bool bCanPlay = false;
|
|||
|
public float StartPlayTime;
|
|||
|
|
|||
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
static Queue<PlayRoleSnapshotClass> tempHistoryQueue = new Queue<PlayRoleSnapshotClass>();
|
|||
|
List<PlayRoleSnapshotClass> KeyHistory = new List<PlayRoleSnapshotClass>();
|
|||
|
const int HistoryLimit = 30;
|
|||
|
|
|||
|
static PlayRoleSnapshotClass EnqueueOneHistory()
|
|||
|
{
|
|||
|
if (tempHistoryQueue.Count > 0)
|
|||
|
return tempHistoryQueue.Dequeue();
|
|||
|
|
|||
|
return new PlayRoleSnapshotClass();
|
|||
|
}
|
|||
|
|
|||
|
public void AddSnap(float _time,Sprite sprite, Vector3 bridgeDir, Vector3 pos)
|
|||
|
{
|
|||
|
while (KeyHistory.Count > HistoryLimit)
|
|||
|
{
|
|||
|
KeyHistory[0].Reset();
|
|||
|
tempHistoryQueue.Enqueue(KeyHistory[0]);
|
|||
|
KeyHistory.RemoveAt(0);
|
|||
|
}
|
|||
|
|
|||
|
PlayRoleSnapshotClass snap = EnqueueOneHistory();
|
|||
|
snap.time = _time;
|
|||
|
snap.mSprite = sprite;
|
|||
|
snap.BridgeDir = bridgeDir;
|
|||
|
snap.Pos = pos;
|
|||
|
KeyHistory.Add(snap);
|
|||
|
}
|
|||
|
|
|||
|
public void ClearHistory()
|
|||
|
{
|
|||
|
for (int i = 0; i < KeyHistory.Count; i++)
|
|||
|
{
|
|||
|
KeyHistory[i].Reset();
|
|||
|
tempHistoryQueue.Enqueue(KeyHistory[i]);
|
|||
|
}
|
|||
|
KeyHistory.Clear();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
void OnEnable()
|
|||
|
{
|
|||
|
mBridgeTransfrom = transform.Find("Bridge");
|
|||
|
mModelTransfrom = mBridgeTransfrom.Find("Model");
|
|||
|
mSpriteRenderer = mModelTransfrom.GetComponent<SpriteRenderer>();
|
|||
|
mBridgeTransfrom.gameObject.SetActive(false);
|
|||
|
LoadData();
|
|||
|
}
|
|||
|
|
|||
|
public void LoadData()
|
|||
|
{
|
|||
|
RoleSnapshotClass[] srcData = GamePlayEntry.MainPlayer.Player.mRoleSnapshot.GetHistoryArray();
|
|||
|
float time = 0;
|
|||
|
Vector3 pos;
|
|||
|
Vector3 dir = Vector3.zero;
|
|||
|
for (int i = 0; i < srcData.Length; i++)
|
|||
|
{
|
|||
|
if (i > 0)
|
|||
|
{
|
|||
|
time = srcData[i].time - srcData[0].time;
|
|||
|
time = time / 2f;
|
|||
|
dir = srcData[i].Pos - srcData[i - 1].Pos;
|
|||
|
//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
|||
|
pos = srcData[i].Pos + (dir * 4f);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
pos = srcData[i].Pos;
|
|||
|
}
|
|||
|
AddSnap(time, srcData[i].mSprite, srcData[i].BridgeDir, pos);
|
|||
|
}
|
|||
|
|
|||
|
if (KeyHistory.Count > 0)
|
|||
|
{
|
|||
|
bCanPlay = true;
|
|||
|
StartPlayTime = 0;
|
|||
|
CurrPlayIndex = -1;
|
|||
|
NextPlayTime = 0;
|
|||
|
StartPlayTime = Time.time;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void Update()
|
|||
|
{
|
|||
|
//δ<><CEB4><EFBFBD>ﲥ<EFBFBD><EFB2A5><EFBFBD><EFBFBD>һ֡<D2BB><D6A1><EFBFBD>¼<EFBFBD>
|
|||
|
if (!bCanPlay || Time.time < NextPlayTime)
|
|||
|
return;
|
|||
|
|
|||
|
CurrPlayIndex++;
|
|||
|
|
|||
|
PlayRoleSnapshotClass snap = KeyHistory[CurrPlayIndex];
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>
|
|||
|
mBridgeTransfrom.gameObject.SetActive(true);
|
|||
|
mSpriteRenderer.sprite = snap.mSprite;
|
|||
|
mBridgeTransfrom.localEulerAngles = snap.BridgeDir;
|
|||
|
transform.position = snap.Pos + offset;
|
|||
|
|
|||
|
//û<>к<EFBFBD><D0BA><EFBFBD>֡<EFBFBD><D6A1>
|
|||
|
if (KeyHistory.Count < CurrPlayIndex + 2)
|
|||
|
{
|
|||
|
bCanPlay = false;
|
|||
|
Invoke("EndEff", 0.05f);
|
|||
|
}
|
|||
|
else//<2F><><EFBFBD><EFBFBD>֡
|
|||
|
{
|
|||
|
NextPlayTime = StartPlayTime + KeyHistory[CurrPlayIndex + 1].time;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//public void SetData(Sprite sprite, Vector3 BridgelocalEulerAngles, Vector3 targetWorldPos)
|
|||
|
//{
|
|||
|
// mBridgeTransfrom.gameObject.SetActive(true);
|
|||
|
// mSpriteRenderer.sprite = sprite;
|
|||
|
// mBridgeTransfrom.localEulerAngles = BridgelocalEulerAngles;
|
|||
|
// transform.position = targetWorldPos + offset;
|
|||
|
// Invoke("EndEff", 0.3f);
|
|||
|
//}
|
|||
|
|
|||
|
public void EndEff()
|
|||
|
{
|
|||
|
this.gameObject.SetActive(false);
|
|||
|
ClearHistory();
|
|||
|
}
|
|||
|
}
|