Photon学习笔记


PhotonNetwork 这个类包含了我们需要的全部函数和变量。
 
把plugin文件夹放到工程的根目录。
 
API使用:
 
PhotonNetwork 实现了一些回调函数,让我们呢的游戏能够获取状态的改变。
 
PhotonView 是一个脚本组件。作用是发送消息和实例化其他的PhotonView。需要把PhotonView附加到gameobjects上面。
 
如何添加PhotonView到一个gameobject上面:
 
Component/Miscellaneous/Photon View.
 
OnPhotonSerializeView(PhotonStream stream,PhotonMessageInfo info) 该方法实现同步,是PhotonView的一个方法。
 
发送messages的2种方法:
 
1.RPC
 
2.使用photonView 属性 OnSerializePhotonView()。
 
Void  OnPhotonSerializeView(PhotonStream stream,PhotonMessageInfo info)
 
{
 
if(stream.isWriting)
 
{
 
stream.SendNext((int)controllerScript._characterState);
 
stream.SendNext(transform.position);
 
stream.SendNext(transform.rotation);
 
}
 
Else
 
{
 
controllerScript._characterState = (CharacterState)(int)stream.ReceiveNext();
 
correctPlayerPos = (Vector3)stream.ReceiveNext();
 
correctPlayerRot = (Quaternion)stream.ReceiveNext();
 
}
 
}

相关内容

    暂无相关文章

评论关闭