unity photon serverunity networking 必须连外网吗

Photon Networking
PlayMaker now offers the possibily to create multiplayer games and applications using
( aka& &PUN& ).
Installation (Pun 1.80) Unity 4 and Unity 5
You can read the&
You must have PlayMaker 1.8 or newer& If you dont' want to update to PlayMaker 1.8, do not import the latest version of PlayMaker support for Photon.
Photon Unity Networking is now available on the&:
You can also manually download it below
You can get the Unity 5 only package, without PUN asset below: Note. It's recommended to use Unity 5.3.4 and up.
All source code is hosted on Github:
&(This is if you want it as a github SubModule in your github Unity Project Repository)
Editor Wizard
PlayMaker integration of Photon features a convenient Editor Wizard that will guide you in your Project, scene and gameObjects set up.
&to set up a projects, scenes and gameObjects to work with Photon networking.
Documentation
The documentation is available&&and describes each photon related actions and events.
The documentation is also accessible from the actions themselves within Unity editor, as you work, by clicking on the help icon&
A demo is available on the&: for you to learn the important aspects and features of Photon and how it works within PlayMaker environment.
You can download the demo manually here:
The demo will be in Assets/PlayMaker Custom Samples/PhotonUnityNetworking/DemoWorker
You can find&&to get a feel of the work involved with the various Fsm created and the different features covered by this demo.
Note:&You can always access these pages right from&&by simply clicking on the little blue book icon with the question mark.
Make use of the&&to ask questions, make comments, suggestions and share your knowledge.
Photon Actions
The exhaustive list of actions is available&.
Note:&You can always access these pages right from&&by simply clicking on the little blue book icon with the question mark.&
Photon Events
The exhaustive list of Photon events is available&.
Last modified on 3/15/ AM by User.1417人阅读
unity(11)
photon(2)
多人互联(2)
啊哈,开始还是些闲话来引出思绪哈。之前以为没有人看我写的就停更了。今天偶然想起进来一看,发现回复私信希望可以继续讲的,很开心。瞬间就有了动力,哈哈。从我自己身上就看到了反馈的重要性,为何微博,微信都要有点赞功能呢?游戏的打击感一定要好呢?我想这应该就是原因所在。
进入正文:前两篇主要介绍了pun,如果看了之前文章,并看了他的demo的话,基本的联网组件大概也应该有些了解了。那么这一篇我们就来讲一下如何通过使用PUN来连接HTC VIVE。
首先将原理,之后放一些代码,我个人觉得还是思想更重要一些。我现在就放上源码,你可能马上就能实现最基础的功能,但是如果没有理解的话,之后自己再做扩展依然是困难重重。当然,这里不是讲pun的原理哈。
看过他自带的demo后,你肯定觉得他的组件是如此的方便,只需要把想要进行网络同步的物体加上PhotonView 组件,将想要同步位置信息的物体加上PhotonTransformView,再将PhotonTransformView挂载到PhotonView的观察组件上就可以了。
那是不是把这两个组件挂载到steamVR的cameraRIg上就行了呢?很显然,当然不是啦,要不还写个毛。
首先VIve是包括手柄在内的一共3个物体。而传统游戏的同步主角都是只有一个。第一个问题来了,如何让PUN知道这3个物体都是要又你控制呢?
第二个问题,正如上文所说只需要把需要网络同步的物体挂载上相应的组件,要知道cameraRIg中有一个组件是包含摄像机的,用unet的都知道摄像机是不能同步的。如果你没用过unet,或者没想明白的,这点你可能有疑问,我来简单的解释一下:你是玩家A,另外一个玩家是B。如果你两个玩家联机的话,在B玩家的视野中是可以看到角色A和角色B,但是肯定不会看到角色A的摄像机啊,一个玩家只会有一个摄像机,所以,想要直接同步cameraRig是不行的,所我们要想其他的方法来同步。
有两种同步方式,1.既然cameraRig包含摄像机无法同步,我们可以自己做一个头部物体作为摄像机的子物体来进行同步,这样就不需要同步摄像机,两个控制器也是这样。这样一来,我们实际上同步的是我们自己做的3个物体。这样在B玩家视野里看到的也是我们自己做的这3个物体。亲测可以实现同步。但是,这种的话,代码写的交互就比较蛋疼,因为他还是cameraRig的子物体,相互之间的调用,非常的不方便。在后来,我就抛弃了这种同步方式,大家看一下,也可以理解一下最初的思路。
接下来我们来说第二种,更棒的同步方式。如果你看明白上面这种同步方式,你就会发现这个问题的实质就是,camerarig之负责本机的头盔,2个手柄的位置信息,以及两个手柄的button事件。就第一点来说,我们只需要一个脚本来同步我们自己的头部,和两只手的模型与cameraRig的3个物体transform信息相同,然后使用pun仅仅同步这3个物体的信息就可以实现,和传统游戏的同步。下面我放上代码。
为了得到头盔和两个控制器,写一个ViveManager的管理类(一个非常简单的单例模式,方便以后的调用)
using UnityE
using System.C
using UnityEngine.SceneM
public class ViveManager : MonoBehaviour {
public GameO
public GameObject leftH
public GameObject rightH
public static ViveManager I
void Awake()
if (Instance == null)
Instance =
下面这个就是同步的脚本,挂载到自己的3块上面,他是根据自己的索引来同步对应的位置,
public class CopyScripts :Photon. MonoBehaviour {
public int index = 1;
// Use this for initialization
void Start () {
DontDestroyOnLoad(this);
// Update is called once per frame
void Update () {
if (photonView.isMine)
switch (index)
transform.position = ViveManager.Instance.head.transform.
transform.rotation = ViveManager.Instance.head.transform.
transform.position = ViveManager.Instance.leftHand.transform.
transform.rotation = ViveManager.Instance.leftHand.transform.
transform.position = ViveManager.Instance.rightHand.transform.
transform.rotation = ViveManager.Instance.rightHand.transform.
这是我们自己要加的脚本,当然要同步的话,不要忘记pun该加的两个同步脚本。
这样,我们就实现了最简单的VR同步,进入到场景后,不同的玩家就可以看到对方。当然现在还没有交互。交互的话,那就下一篇来写了。如果你觉得我的文章对你有帮助,请点赞,投硬币,扔香蕉给我。
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:11845次
排名:千里之外
原创:11篇
评论:31条
(4)(2)(1)(2)(1)(2)(1)(2)(1)
(window.slotbydup = window.slotbydup || []).push({
id: '4740887',
container: s,
size: '250,250',
display: 'inlay-fix'用photon 的遇到过这个问题吗
我是新手,现在开始进行连unity3D与另外一台上架有photon服务器的,发现可以连通,但是是局域网,换个外网连服务器就不行了。而且在局域网内通信还不行,快要奔溃了,不知道哪里有问题,下面是我的代码,服务器端
&& &public class connection: IPeer
&& &{
&& & & &private readonly PhotonPeer photonP
&& & & &private readonly IF
&& & & & & & & public connection(PhotonPeer photonPeer)
&& & & &{
&& & & & & &this.photonPeer = photonP
&& & & & & & & & & & this.fiber.Start();
&& & & &}
&& & & &public void OnDisconnect()
&& & & &{
&& & & & & & & & & }
&& & & &public void OnOperationRequest(OperationRequest request)
&& & & &{
&& & & & & &try
&& & & & & &{
&& & & & & & & &log.DebugFormat(&request={0}&, request);
&& & & & & & & & & & & & & & &switch (request.OperationCode)
&& & & & & & & &{
&& & & & & & & & & &case (short)OperationCode.LoginOperation:
&& & & & & & & & & & & &{
&& & & & & & & & & & & & & &if (request.Params.Count & 2) & & & & & & & & & & & & & & {
&& & & & & & & & & & & & & & & & & & & & & & & & & & & & &var response = new OperationResponse(request, (int)ErrorCode.InvalidParameter, &Login Fail&, new Dictionary&short, object& { { 1, &Login Fail& } });
&& & & & & & & & & & & & & & & &this.fiber.Enqueue(() =& this.PhotonPeer.SendOperationResponse(response));
&& & & & & & & & & & & & & &}
&& & & & & & & & & & & & & &else
&& & & & & & & & & & & & & &{
&& & & & & & & & & & & & & & & &var memberID = (string)request.Params[1];
&& & & & & & & & & & & & & & & &var memberPW = (string)request.Params[2];
&& & & & & & & & & & & & & & & &if (memberID == &test& && memberPW == &1234&)
&& & & & & & & & & & & & & & & &{
&& & & & & & & & & & & & & & & & & &short Ret = 1;
&& & & & & & & & & & & & & & & & & &var parameter = new Dictionary&short, object& {
&& & & & & & & & & & & & & & & & & & & & & & &{ 80, Ret }, {1, memberID}, {2, memberPW} & & & & & & & & & & & & & & & & & & & & & &};
&& & & & & & & & & & & & & & & & & &var eventData = new EventData(
&& & & & & & & & & & & & & & & & & & & & & & & & & & & (short)EventCode.LoginEvent,
&& & & & & & & & & & & & & & & & & & & & & & & & & & & parameter,
&& & & & & & & & & & & & & & & & & & & & & & & & & & & Reliability.Reliable, & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & &false); & & & & & & & & & & & & & & & & & & this.fiber.Enqueue(() =& this.photonPeer.SendEvent
连接服务器没问题,能连通,只是局域网的可以连通,外网不行,待解决,客户端代码;因为太多了,只发主要的,
&& var parameters = new Dictionary&byte,object&
&& {
&& &{(byte)LoginCode.mem_ID,username},
&& &{(byte)LoginCode.mem_PW,password}
&& };
&& &
&& this.peer.OpCustom((byte)Login_operation.login,parameters,true);//这是发送的,不知道错了没
public void OnOperationResponse (OperationResponse operationResponse) &//这是从服务端接受数据,但是没数据过来returncode一直为-1
&& &{ &
&&responsecode = Convert.ToString(operationResponse.OperationCode);
&&duchu =Convert.ToString( operationResponse.ReturnCode);
&&switch(operationResponse.OperationCode)
&&{
&&case (byte)Login_operation.login:
&& if (operationResponse.ReturnCode==(short)ErrorCode.OK)
&& {
&& &send_flag =
&& &respon_name = (string)( operationResponse.Parameters[(byte)LoginResponseCode.memID]);
&& &respon_pw = (string )( operationResponse.Parameters[(byte)LoginResponseCode.memPW]);
&& }
&& else
&& {
&& &send_flag =
&& }
&&求各位解决下啊,小弟搞这个奔溃很多天了!有能过进行客户端的与服务端成功通信的大侠们,能不能借鉴下代码啊
要评论请先&或者&
case (short)OperationCode.LoginOperation: 和 &case (byte)Login_operation.login: 值相同不。。。??
需要公网IP啊,用PhotonCloud可以借助Photon的Server帮忙联通

我要回帖

更多关于 photon unity plugin 的文章

 

随机推荐