Files
UltimateFishing/Assets/Scripts/Assembly-CSharp/SmoothSyncMovement.cs
2026-02-21 16:45:37 +08:00

53 lines
1.3 KiB
C#

using Photon;
using UnityEngine;
[RequireComponent(typeof(PhotonView))]
public class SmoothSyncMovement : Photon.MonoBehaviour, IPunObservable
{
public float SmoothingDelay = 5f;
private Vector3 correctPlayerPos = Vector3.zero;
private Quaternion correctPlayerRot = Quaternion.identity;
public void Awake()
{
bool flag = false;
foreach (Component observedComponent in base.photonView.ObservedComponents)
{
if (observedComponent == this)
{
flag = true;
break;
}
}
if (!flag)
{
Debug.LogWarning(string.Concat(this, " is not observed by this object's photonView! OnPhotonSerializeView() in this class won't be used."));
}
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext(base.transform.position);
stream.SendNext(base.transform.rotation);
}
else
{
correctPlayerPos = (Vector3)stream.ReceiveNext();
correctPlayerRot = (Quaternion)stream.ReceiveNext();
}
}
public void Update()
{
if (!base.photonView.isMine)
{
base.transform.position = Vector3.Lerp(base.transform.position, correctPlayerPos, Time.deltaTime * SmoothingDelay);
base.transform.rotation = Quaternion.Lerp(base.transform.rotation, correctPlayerRot, Time.deltaTime * SmoothingDelay);
}
}
}