Собственно вот кусок кода отвечающий за сериализацию объекта.
Синтаксис:
Используется csharp
Vector3 oldPos;
Vector3 newPos;
if!photonView.isMine)
{
Debug.LogError("<Color=Green>Vector3.Lerp: " + Vector3.Lerp(oldPos, newPos, Time.deltaTime * 5f) + "</Color>");
transform.position = Vector3.Lerp(oldPos, newPos, Time.deltaTime * 5f);
}
void IPunObservable.OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
oldPos = transform.position;
stream.SendNext(oldPos);
Debug.LogError("<Color=Yellow>stream.isWriting " + gameObject.name + "| SerializeView position: " + oldPos + "| new Pos " + newPos + "</Color>");
}
else
{
oldPos = transform.position;
newPos = Vector3.zero;
oldPos = (Vector3)stream.ReceiveNext();
newPos = oldPos;
Debug.LogError("<Color=Black>stream.isReading " + gameObject.name + "| SerializeView position: " + oldPos + "| new Pos " + newPos + "</Color>");
}
}
Vector3 newPos;
if!photonView.isMine)
{
Debug.LogError("<Color=Green>Vector3.Lerp: " + Vector3.Lerp(oldPos, newPos, Time.deltaTime * 5f) + "</Color>");
transform.position = Vector3.Lerp(oldPos, newPos, Time.deltaTime * 5f);
}
void IPunObservable.OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
oldPos = transform.position;
stream.SendNext(oldPos);
Debug.LogError("<Color=Yellow>stream.isWriting " + gameObject.name + "| SerializeView position: " + oldPos + "| new Pos " + newPos + "</Color>");
}
else
{
oldPos = transform.position;
newPos = Vector3.zero;
oldPos = (Vector3)stream.ReceiveNext();
newPos = oldPos;
Debug.LogError("<Color=Black>stream.isReading " + gameObject.name + "| SerializeView position: " + oldPos + "| new Pos " + newPos + "</Color>");
}
}
В таком виде объект принимает координаты 0.0.0 и ни о чем другом даже слышать не хочет. Дебаг показывает, что координаты совпадают с позицией объекта, но в инспекторе он всё равно находится в нулях.
Пробовал стандартный фотоновский скрипт
Синтаксис:
Используется csharp
public class SmoothSyncMovement : Photon.MonoBehaviour, IPunObservable
{
public float SmoothingDelay = 5;
private Vector3 correctPlayerPos = Vector3.zero; //We lerp towards this
private Quaternion correctPlayerRot = Quaternion.identity; //We lerp towards this
void Update()
{
if (!photonView.isMine)
{
//Update remote player (smooth this, this looks good, at the cost of some accuracy)
transform.position = Vector3.Lerp(transform.position, correctPlayerPos, Time.deltaTime * 1f);
transform.rotation = Quaternion.Lerp(transform.rotation, correctPlayerRot, Time.deltaTime * 1f);
}
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
//We own this player: send the others our data
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else
{
correctPlayerPos = (Vector3)stream.ReceiveNext();
correctPlayerRot = (Quaternion)stream.ReceiveNext();
}
}
}
{
public float SmoothingDelay = 5;
private Vector3 correctPlayerPos = Vector3.zero; //We lerp towards this
private Quaternion correctPlayerRot = Quaternion.identity; //We lerp towards this
void Update()
{
if (!photonView.isMine)
{
//Update remote player (smooth this, this looks good, at the cost of some accuracy)
transform.position = Vector3.Lerp(transform.position, correctPlayerPos, Time.deltaTime * 1f);
transform.rotation = Quaternion.Lerp(transform.rotation, correctPlayerRot, Time.deltaTime * 1f);
}
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
//We own this player: send the others our data
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else
{
correctPlayerPos = (Vector3)stream.ReceiveNext();
correctPlayerRot = (Quaternion)stream.ReceiveNext();
}
}
}
Но он тоже не дал никаких плодов, разве что объект теперь стал дергаться в ноль ноль координаты.
Я перелапатил уже все форумы англоязычные и русскоязычные, но вся инфа с них не дает решения вопроса.
Вот фото дебага
Вот фото Фотонвиева и в нём находится первый скрипт
Подскажите, что же все таки не так??? Почему при идентичном коде у всех остальных всё работает, а у меня 0 0 0
P.S. создавал отдельный проект и в нем стандартный фотоновский скрипт отображает позицию игроков нормально...