Photon Server与Unity3D的交互分为3篇博文实现

  (1)Photon Server的服务器端配置

  (2)Photon Server的Unity3D客户端配置

  (3)Photon Server与Unity3D客户端的交互

1.添加动态链接库

  在Unity3D里新建Plugins文件夹,将\ Photon-OnPremise-Server-SDK_v4-0-29-11263\lib里的Photon3Unity3D.dll添加到Plugins文件夹。Plugins文件夹用来放置第三方的动态链接库,会优先编译。

2.创建PhotonEngine

  在Unity里创建空物体命名为PhotonEngine,然后创建并添加组件PhotonEngine.cs。客户端通过PhotonEngine.cs向服务器端发送和接收请求。 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ExitGames.Client.Photon;
public class PhotonEngine : MonoBehaviour,IPhotonPeerListener {
public static PhotonEngine Instance { get; private set; }
public static PhotonPeer Peer { get; private set; }
   void Awake()
{
//切换场景后保证有且仅有一个PhotonEngine
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(this.gameObject);
}else if (Instance != this)
{
Destroy(this.gameObject);
return;
}
} void Start () {
     //让PhotonEngine继承实现IPhotonPeerListener故listener赋值为this。        
     //客户端通过PhotonPeer向服务器端发送请求,通过IPhotonPeerListener接收服务器端的响应
     Peer = new PhotonPeer(this, ConnectionProtocol.Udp);
     Peer.Connect("127.0.0.1:5055", "Minecraft");//设置连接的ip地址、端口号跟Application } void Update () {
Peer.Service();//PhotonPeer有一存储请求的队列,只有调用Peer.Service()才会连通服务器,发送请求队列和接受请求队列。
   }
   //在游戏关闭时断开连接
void OnDestroy()
{
if (Peer != null && Peer.PeerState == PeerStateValue.Connected)
{
Peer.Disconnect();
}
}
   public void DebugReturn(DebugLevel level, string message)    
   {         }    //服务器端向客户端发送请求时调用
public void OnEvent(EventData eventData)
{ }
   //客户端向服务器端发送请求后,服务器端响应客户端时调用
public void OnOperationResponse(OperationResponse operationResponse)
{ }          //PeerStateValue有5种状态,当状态发生改变时调用   
   public void OnStatusChanged(StatusCode statusCode)    
   {
       Debug.Log("当前状态"+statusCode);  
   }
}

Photon Server的Unity3D客户端配置的更多相关文章

  1. Photon Server与Unity3D客户端的交互

    Photon Server与Unity3D的交互分为3篇博文实现 (1)Photon Server的服务器端配置 (2)Photon Server的Unity3D客户端配置 (3)Photon Ser ...

  2. Photon Server初识(六) --- 客户端与服务端消息传递

    前一章客户端与服务端连接成功,现在需要前后端进行数据传递. 一.前端发送消息.在项目Scripts目录中新建脚本 TestSer.cs.并挂载到相机上 二.客户端发送数据给服务端.编辑客户端代码 Te ...

  3. Photon Server的服务器端配置

    Photon Server与Unity3D的交互分为3篇博文实现 (1)Photon Server的服务器端配置 (2)Photon Server的Unity3D客户端配置 (3)Photon Ser ...

  4. Photon Server 服务端编程

    Photon Server 和 Unity3D 数据交互: Photon Server 服务端编程 Unity3D 客户端编程 VS2017 之 MYSQL实体数据模 一:Photon Server的 ...

  5. Unity3D 客户端编程

    Photon Server 和 Unity3D 数据交互: Photon Server 服务端编程 Unity3D 客户端编程. VS2017 之 MYSQL实体数据模 1:打开unity新建新项目, ...

  6. Unity3d客户端与Photon服务器数据通信

    今天先介绍一下Photon服务器是什么,可以做什么,为什么要使用它? Photon:开发多人联网游戏最轻松的方案!可以迅速简单实现多人实时在线网络游戏(pvp). Photon:透过位于各地的Phot ...

  7. 看过自会理解, Photon Server 常见概念分析.

    http://stackoverflow.com/questions/10823915/photon-server-newbie-questions/11653419#11653419 Channel ...

  8. 开源分享 Unity3d客户端与C#分布式服务端游戏框架

    很久之前,在博客园写了一篇文章,<分布式网游server的一些想法语言和平台的选择>,当时就有了用C#做网游服务端的想法.写了个Unity3d客户端分布式服务端框架,最近发布了1.0版本, ...

  9. Photon Server初识(四) --- 部署自己的服务Photon Server

    准备工作: 1.一台 window 虚拟机(本机是window也行) 2.下载SDK : https://www.photonengine.com/zh-CN/sdks#server 一:SDK介绍 ...

随机推荐

  1. 简单的使用Qt的QCustomplot画图

    一.新建一个widget工程 二.将Qcustomplot文件复制到项目下 三.右键qt项目增加已存在的文件 四.在.pro中添加 QT += widgets printsupport 五.在.h中添 ...

  2. iOS 几种定时器

    //第一种 每一秒执行一次(重复性) double delayInSeconds = 1.0; timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_ ...

  3. 【系统安全性】二、Web攻击与防范

    二.Web攻击与防范 1.XSS攻击 跨站脚本攻击(Cross Site Scripting),因为简写CSS,与层叠样式表(Cascading Style Sheets)有歧义,所以取名XSS 原理 ...

  4. C/S模式简单socket通信

    TCP连接方式 sever.c #include <stdio.h>#include <stdlib.h>#include <sys/socket.h>#inclu ...

  5. Openstack组建部署 — Glance Install

    目录 目录 前文列表 Image service overview Openstack Image service包含的组件 Install and configure Prerequisites 先 ...

  6. adb devices unauthorized的解决办法

        Hi, trying to launch adb but get: daemon not running. starting it now on port * daemon started s ...

  7. Codeforces 1189C Candies!

    题目链接:http://codeforces.com/problemset/problem/1189/C 思路:前缀和. AC代码: #include<bits/stdc++.h> usi ...

  8. springboot+mybatis+layUI

    1.idea快速搭建 2.生成后目录结构 3.引入layui-2.4.5 4.static/新建index.html,页面代码参考https://www.layui.com/doc/element/l ...

  9. HTML中改变列表的序号类型

    HTML中,<ol>标签表示有序列表,每一个表项的编号默认从数字开始.比如 <html> <head> <title>test</title> ...

  10. centos7.4 系统优化

    static 表示该服务与其他服务相关联,不能单独设置该服务的启动状态 disabled 表示禁止开机启动 enabled 表示允许开机启动 auditd.service enabled autovt ...