0

Unity ゲーム エンジン/Photon unity ネットワークのフォトン ビュー (c#) でこのコードを使用しています。ただし、アニメーションやその他のものをネットワーク化する目的で、何らかの理由でコードがアニメーションをネットワーク化しません。

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;
            }


        }


    }
}
4

1 に答える 1

0

位置と回転を同期するには、Photon View と Photon Transform View コンポーネントを使用できます。

ぜひチェックしてください: Photonでのシリアライゼーション

于 2019-09-13T08:08:30.757 に答える