2023-01-09 00:17:20 +08:00
|
|
|
|
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;
|
2023-01-09 14:49:45 +08:00
|
|
|
|
public float SnapStepStartTime = 0;
|
|
|
|
|
public Vector3 SnapStepStartPos = Vector3.zero;
|
|
|
|
|
public Vector3 NextPos = Vector3.zero;
|
2023-01-09 00:17:20 +08:00
|
|
|
|
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()
|
|
|
|
|
{
|
2023-01-09 23:13:17 +08:00
|
|
|
|
ClearHistory();
|
2023-01-09 00:17:20 +08:00
|
|
|
|
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;
|
2023-01-09 14:49:45 +08:00
|
|
|
|
StartPlayTime = Time.time;
|
|
|
|
|
NextPos = Vector3.zero;
|
2023-01-09 23:13:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.transform.position = KeyHistory[0].Pos;
|
2023-01-09 00:17:20 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update()
|
|
|
|
|
{
|
2023-01-09 14:49:45 +08:00
|
|
|
|
if (NextPos != Vector3.zero)
|
|
|
|
|
{
|
|
|
|
|
if (NextPlayTime - SnapStepStartTime <= 0)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸΪ0
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Vector3 stepPr = ( (NextPos - SnapStepStartPos) * (Time.time - SnapStepStartTime) / (NextPlayTime - SnapStepStartTime) );
|
|
|
|
|
transform.position = SnapStepStartPos + stepPr + offset;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-09 00:17:20 +08:00
|
|
|
|
//δ<><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;
|
2023-01-09 14:49:45 +08:00
|
|
|
|
SnapStepStartPos = transform.position;
|
|
|
|
|
SnapStepStartTime = Time.time;
|
2023-01-09 00:17:20 +08:00
|
|
|
|
|
|
|
|
|
//û<>к<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;
|
2023-01-09 14:49:45 +08:00
|
|
|
|
NextPos = KeyHistory[CurrPlayIndex + 1].Pos;
|
2023-01-09 00:17:20 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//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();
|
|
|
|
|
}
|
|
|
|
|
}
|