Unity3D в представлении Photon Serialize

Я использую этот код для просмотра фотонов (c#) в игровом движке Unity/сети единства Photon. Однако для сетевых анимаций и других вещей код по какой-то причине просто не будет сетевыми моими анимациями.

using UnityEngine;
using System.Collections;

public class NetworkCharacter : Photon.MonoBehaviour {

    Vector3 realPos = Vector3.zero;
    Quaternion realRot = Quaternion.identity;
    Animator anim;
    bool gotFU = false;

    // Use this for initialization
    void Start () {
        anim = GetComponent<Animator> ();
    }

    // Update is called once per frame
    void Update () {
        if (photonView.isMine) 
        {

        } 
        else 
        {
            transform.position = Vector3.Lerp (transform.position, realPos, 0.1f);
            transform.rotation = Quaternion.Lerp (transform.rotation, realRot, 0.1f);
        }
    }

    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting) 
        {
            stream.SendNext (transform.position);
            stream.SendNext (transform.rotation);
            stream.SendNext (anim.GetFloat("Speed"));
            stream.SendNext (anim.GetFloat("Strafe"));
        } 
        else 
        {
            realPos = (Vector3)stream.ReceiveNext ();
            realRot = (Quaternion)stream.ReceiveNext ();
            anim.SetFloat("Speed", (float)stream.ReceiveNext());
            anim.SetFloat("Strafe", (float)stream.ReceiveNext());


            if (gotFU == false) 
            {
                transform.position = realPos;
                transform.rotation = realRot;
                gotFU = true;
            }


        }


    }
}

person Bilaal_Latif    schedule 01.05.2016    source источник


Ответы (1)


Для синхронизации положения и поворота вы можете использовать компонент Photon View и Photon Transform View.

Пожалуйста, проверьте это: Сериализация в Photon

person Wolfik    schedule 13.09.2019