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. The 'with' and 'as' Keywords

    Programming is all about getting the computer to do the work. Is there a way to get Python to automa ...

  2. 函数计算工具链新成员 —— Fun Local 发布啦

    刚刚,我们发布了函数计算工具链的新成员,Fun Local.欢迎大家使用! 如果你还不了解 Fun 是什么,我们来简单解释下. Fun 是什么 Fun 是 have Fun with Serverle ...

  3. thinkphp SAE

    SAE介绍 Sina App Engine(简称SAE)是新浪研发中心开发的国内首个公有云计算平台,是新浪云计算战略的核心组成部分,作为一个简单高效的分布式Web服务开发.运行平台越来越受开发者青睐. ...

  4. 【LeetCode 5】 最长回文子串

    题目链接 描述 [题解] 一个讲得比较好的博客地址; 感觉manacher算法的大概思路就是利用回文串左右对称的性质. 利用之前算出来的以某个点为中心的回文串.而当前要枚举的串被包括在其中. 则可以用 ...

  5. Luogu P2269 [HNOI2002]高质量的数据传输

    这题给大家提供一下思路~ (为不想贴代码找借口) 声明:两个思路都是正确的,并且都AC了.(逃) 总体布局 求传输失败率\(1-\prod(1-p_{i})\)最小就是求 传输成功率\(\prod(1 ...

  6. java发带图片正文和附件的邮件mail

    package com.mail; import java.io.UnsupportedEncodingException; import java.util.Date; import java.ut ...

  7. PAT_A1124#Raffle for Weibo Followers

    Source: PAT A1124 Raffle for Weibo Followers (20 分) Description: John got a full mark on PAT. He was ...

  8. Python翻译

    translator.py # -*- coding: utf-8 -*- # author: inspurer(月小水长) # pc_type lenovo # create_time: 2019/ ...

  9. android sdk 下载 最新版。。4.l

    android sdk 下载 如今时间 2014.0709.,,这是最新的 64 位 windows 的 .为不能翻墙的小伙伴们准本

  10. spring boot jpa 多表关联 @OneToOne @OneToMany @ManyToOne@ManyToMany

    1.一对一关联 @OneToOne import lombok.Data; import javax.persistence.*; /** * @Author: GWL * @Description: ...