编写本身的Photon游戏服务器(Yanlz+Unity+Photon+Server+UNet+KBEngine+Socket+纤程+UDP+立钻哥哥+==)

《编写本身的Photon游戏服务器》

版本node

做者git

参与者github

完成日期面试

备注数据库

Photon_MyServer_V01_1.0编程

严立钻设计模式

 

2019.01.28跨域

 

 

 

 

 

 

 

##《编写本身的Photon游戏服务器》发布说明:服务器

++++“编写本身的Photon游戏服务器”:是对PhotonServer的一个升级(搭建本身的服务器);(产品从单机到联网是一个跨域,联网框架从UNetPhoton,再到KBEngine,最后本身搭建C++服务器网络

++++编写本身的Photon游戏服务器”:定位在一个实战类拓展,是对PhotonServer知识的一个探索总结与实践

++++PhotonServer的Github:

++++Photon的官网(全球):https://www.photonengine.com/

++++Photon中国网:https://vibrantlink.com/

++++KBEngine的Github:https://github.com/435886030/kbengine

++++YanlzServer的Github:

 

 

 

##《编写本身的Photon游戏服务器》目录

#第一篇:Photon概述

#第二篇:Photon客户端脚本编写

#第三篇:Photon通讯协议

#第四篇:编写本身的Photon游戏服务器

#第五篇:立钻哥哥的Photon拓展

 

 

 

 

 

#第一篇:Photon概述

#第一篇:Photon概述

#第一篇:Photon概述

++++立钻哥哥:Photon是一款跨多个平台的游戏服务器引擎;Unity3D已经和Photon达成了战略合做关系,在Unity3D上开发手机网游,首选Photon引擎,使用它能够很方便的完成Unity3D上网游的编写;

++++A.一、Photon简介

++++A.二、配置Photon服务器

++++A.三、Photon异常排查

++++A.四、在Unity3D里添加Photon插件

++++A.五、立钻哥哥拓展Photon概述

 

 

 

 

##A.一、Photon简介

##A.一、Photon简介

++A.一、Photon简介

++++立钻哥哥:简要介绍Photon的基本状况以及它的应用场景;

 

++Photon简介

++++立钻哥哥:Photon英文愿意是指光量子,在这里是指Exit Game公司的服务器网络游戏引擎

++++Photon引擎是一款实时的Socket服务器和开发框架,其使用方便、容易扩展

++++Photon包含两个部分:一部分是一个Socket服务器;另外一部分是其针对各个平台编写的SDK

++++服务器架构在Windows系统平台上,采用C#语言编写;客户端SDK提供了多种平台的开发API,其中就包括Unity3D客户端

 

++Photon引擎的特色

++++立钻哥哥:Photon引擎的特色以下:

++++一、架构于Windows平台下原生态性能高度优化的系统;

++++二、通过证实适用于众多商业游戏;

++++三、服务器端游戏逻辑采用C#语言实现;

++++四、采用纤程处理消息机制以免采用线程致使的问题;

++++五、部署简单,支持云端服务;

++++六、采用小尺寸的二进制协议,可根据须要使用有序可靠的UDP

++++七、封装了每一个客户端平台的网络层模块;

Tips:【纤程】:纤程包含独立目态栈,寄存器状态的控制信息;目态控制的纤程转接要求较高的编程经验;因为纤程属于目态对象,一个纤程被封锁意味着全部线程被封锁;

++++纤程(Fiber)至关于用户级别的线程或轻进程;

 

 

++Photon的应用场景

++++立钻哥哥:Photon主要用于手机网游:

 

 

 

 

 

 

##A.二、配置Photon服务器

##A.二、配置Photon服务器

++A.二、配置Photon服务器

++++立钻哥哥:这节主要熟悉如何配置Photon服务器

++++A.2.一、安装Photon SDK

++++A.2.二、检查Windows系统里的端口和防火墙设置

++++A.2.三、设置Photon的配置文件

++++A.2.四、运行PhotonControl.exe文件

 

++A.2.一、安装Photon SDK

++++立钻哥哥:好吧,先下载SDK吧

++++Photon的官网(全球):https://www.photonengine.com/

 

 

++解压SDK查看目录结构

++++立钻哥哥:下载了SDK,咱们解压查看一下吧:

 

 

++A.2.二、检查Windows系统里的端口和防火墙设置

++++立钻哥哥:【防火墙】=>【高级设置】=>【入站规则】=>?查看入站规则列表?

 

 

 

++A.2.三、设置Photon的配置文件

++++立钻哥哥:PhotonServer-SDK_V4.0.29.11263\deploy\bin_Win64\PhotonServer.config

 

 

<?xml version=1.0 encoding=Windows-1252?>

<!--

  (c) 2015 by Exit Game GmbH, http://www.exitgames.com

  Photon server configuration file.

  For details see the photon-config.pdf.

 

  This file contains two configurations:

LoadBalancing

    Loadbalanced setup for local development: A Master-server and a game-server.

    Starts the apps: Game, Master, CounterPublisher

    Listens: upd-port 5055, tcp-port: 4530, 843 and 943

(立钻哥哥:“loadbalance”

本地开发的负载平衡设置:主服务器和游戏服务器。

启动应用程序:游戏、Master、CounterPublisher

监听:upd端口5055,tp端口4530,843和943)

-->

 

<Configuration>

  <!-- Multiple instance are supported. Each instance has its own node in the config file.(立钻哥哥:支持多个实例。每一个实例在配置文件中都有本身的节点。) -->

 

  <LoadBalancing

    MaxMessageSize=512000

    MaxQueuedDataPerPeer=512000

    PerPeerMaxReliableDataInTransit=51200

    PerPeerTransmitRateLimitKBSec=256

    PerPeerTransmitRatePeriodMilliseconds=200

    MinimumTimeOut=5000

    MaximumTimeOut=30000

    DisplayName=LoadBalancing (MyCloud)>

 

    <!--  0.0.0.0 opens listeners on all available IPs. Machines with multiple IPs should define the correct one here.(立钻哥哥:0.0.0.0打开全部可用ip上的侦听器。具备多个ip的机器应该在这里定义正确的ip。)-->

    <!-- Port 5055 is Photons default for UDP connections.(立钻哥哥:端口5055是光子用于UDP链接的默认端口。)-->

    <UDPListeners>

    </UDPListeners>

 

    <!-- 0.0.0.0 opens listeners on all available IPs. Machines with multiple IPs should define the correct one here.(立钻哥哥:0.0.0.0打开全部可用ip上的侦听器。具备多个ip的机器应该在这里定义正确的ip。) -->

    <TCPListeners>

    </TCPListeners>

 

    <!-- Policy request listener for Unity and Flash (port 843) and Silverlight (port 943).(立钻哥哥:Unity和Flash(端口843)以及Silverlight(端口943)的策略请求监听器。) -->

    <PolicyFileListeners>

    </PolicyFileListeners>

 

    <!-- WebSocket (and Flash-Fallback) compatible listener.(立钻哥哥:兼容WebSocket(和flash回退)的侦听器。) -->

    <WebSocketListeners>

    </WebSocketListeners>

 

    <!-- Defines the Photon Runtime Assembly to use.(立钻哥哥:定义要使用的光子运行时程序集。) -->

    <Runtime  >

    </Runtime>

 

    <!-- Defines which applications are loaded on start and which of them is used by default. Make sure the default application is defined.(立钻哥哥:定义在启动时加载哪些应用程序,以及默认状况下使用哪些应用程序。确保定义了默认应用程序。) -->

    <!-- Application-folders must be located in the same folder as the bin_win32 folders. The BaseDirectory must include a bin folder.(立钻哥哥:应用程序文件夹必须位于与bin_win32文件夹相同的文件夹中。基目录必须包括一个“bin”文件夹。) -->

    <Applications Default=Master>

    </Applications>

 

  </LoadBalancing>

 

 

  <!-- Instance settings.(立钻哥哥:实例设置。) -->

  <MMoDemo

    MaxMessageSize=512000

    MaxQueuedDataPeer=512000

    PerPeerMaxReliableDataInTransit=51200

    PerPeerTransmitRateLimitKBSec=256

    PerPeerTransmitRatePeriodMilliseconds=200

    MinimumTimeout=5000

    MaximumTimeout=30000

    DisplayName=MMO Demo

    >

 

    <!-- 0.0.0.0 opens listeners on all available IPs. Machines with multiple IPs should define the correct one here.(立钻哥哥:0.0.0.0打开全部可用ip上的侦听器。具备多个ip的机器应该在这里定义正确的ip。) -->

    <!-- Port 5055 is Photons default for UDP connections.(立钻哥哥:端口5055是光子用于UDP链接的默认端口。) -->

    <UDPListeners>

    </UDPListeners>

 

    <!-- 0.0.0.0 opens listeners on all available IPs. Machines with multiple IPs should define the correct one here.(立钻哥哥:0.0.0.0打开全部可用ip上的侦听器。具备多个ip的机器应该在这里定义正确的ip。) -->

    <!-- Port 4530 is Photons default for TCP connections.(立钻哥哥:端口4530是TCP链接的默认端口。) -->

    <!-- A Policy application is defined in case that policy requests are sent to this listener (known bug of some some flash clients) .(立钻哥哥:若是策略请求被发送到这个侦听器(某些flash客户机的已知bug),则定义策略应用程序。)-->

    <TCPListeners>

    </TCPListeners>

 

    <!-- Policy request listener for Unity and Flash (port 843) and Silverlight (port 943).(立钻哥哥:Unity和Flash(端口843)以及Silverlight(端口943)的策略请求监听器。) -->

    <PolicyFileListeners>

    </PolicyFileListeners>

 

    <!-- WebSocket (and Flash-Fallback) compatible listener.(立钻哥哥:兼容WebSocket(和flash回退)的侦听器。) -->

    <WebSocketListeners>

    </WebSocketListeners>

 

    <!-- Defines the Photon Runtime Assembly to use.(立钻哥哥:定义要使用的光子运行时程序集。) -->

    <Runtime  >

    </Runtime>

 

    <!-- Defines which applications are loaded on start and which of them is used by default. Make sure the default application is defined.(立钻哥哥:定义在启动时加载哪些应用程序,以及默认状况下使用哪些应用程序。确保定义了默认应用程序。) -->

    <!-- Application-folders must be located in the same folder as the bin_win32 folders. The BaseDirectory must include a bin folder.(立钻哥哥:应用程序文件夹必须位于与bin_win32文件夹相同的文件夹中。基目录必须包括一个“bin”文件夹。) -->

    <Applications Default=MMoDemo>

    </Applications>

    

  </MMoDemo>

 

</Configuration>

 

 

++<LoadBalancing> ... </LoadBalancing>

++++立钻哥哥:LoadBalancing:负载平衡

<?xml version=1.0 encoding=Windows-1252?>

 

<Configuration>

  <LoadBalancing

    MaxMessageSize=512000

    MaxQueuedDataPerPeer=512000

    PerPeerMaxReliableDataInTransit=51200

    PerPeerTransmitRateLimitKBSec=256

    PerPeerTransmitRatePeriodMilliseconds=200

    MinimumTimeOut=5000

    MaximumTimeOut=30000

    DisplayName=LoadBalancing (MyCloud)>

 

    <UDPListeners>...</UDPListeners>

    <TCPListeners>...</TCPListeners>

    <PolicyFileListeners>...</PolicyFileListeners>

    <WebSocketListeners>...</WebSocketListeners>

    <Runtime  >...</Runtime>

    <Applications Default=Master>...</Applications>

  </LoadBalancing>

 

  <!-- Instance settings.(立钻哥哥:实例设置。) -->

  <MMoDemo></MMoDemo>

 

</Configuration>

 

 

++<LoadBalancing>/<UDPListeners>...</UDPListeners>

++++立钻哥哥:负载均衡/UDP监听(UDPListeners

<?xml version=1.0 encoding=Windows-1252?>

 

<Configuration>

 

  <LoadBalancing

    MaxMessageSize=512000

    MaxQueuedDataPerPeer=512000

    PerPeerMaxReliableDataInTransit=51200

    PerPeerTransmitRateLimitKBSec=256

    PerPeerTransmitRatePeriodMilliseconds=200

    MinimumTimeOut=5000

    MaximumTimeOut=30000

    DisplayName=LoadBalancing (MyCloud)>

 

    <!--  0.0.0.0 opens listeners on all available IPs. Machines with multiple IPs should define the correct one here.(立钻哥哥:0.0.0.0打开全部可用ip上的侦听器。具备多个ip的机器应该在这里定义正确的ip。)-->

    <!-- Port 5055 is Photons default for UDP connections.(立钻哥哥:端口5055是光子用于UDP链接的默认端口。)-->

    <UDPListeners>

      <UDPListener

          IPAddress=0.0.0.0

          Port=5055

          OverrideApplication=Master>

      </UDPListener>

      <UDPListener

          IPAddress=0.0.0.0

          Port=5056

          OverrideApplication=Game>

      </UDPListener>

    </UDPListeners>

 

    <TCPListeners>...</TCPListeners>

    <PolicyFileListeners>...</PolicyFileListeners>

    <WebSocketListeners>...</WebSocketListeners>

    <Runtime  >...</Runtime>

 

    <Applications Default=Master>...</Applications>

  </LoadBalancing>

 

  <MMoDemo>...</MMoDemo>

 

</Configuration>

 

 

++<LoadBalancing>/<TCPListeners>...</TCPListeners>

++++立钻哥哥:负载均衡/TCP监听(TCPListeners

<?xml version=1.0 encoding=Windows-1252?>

 

<Configuration>

 

  <LoadBalancing

    MaxMessageSize=512000

    MaxQueuedDataPerPeer=512000

    PerPeerMaxReliableDataInTransit=51200

    PerPeerTransmitRateLimitKBSec=256

    PerPeerTransmitRatePeriodMilliseconds=200

    MinimumTimeOut=5000

    MaximumTimeOut=30000

    DisplayName=LoadBalancing (MyCloud)>

 

    <UDPListeners>...</UDPListeners>

 

    <!-- 0.0.0.0 opens listeners on all available IPs. Machines with multiple IPs should define the correct one here.(立钻哥哥:0.0.0.0打开全部可用ip上的侦听器。具备多个ip的机器应该在这里定义正确的ip。) -->

    <TCPListeners>

      <!-- TCP Listener for Game clients on Master application.(立钻哥哥:用于主应用程序上的游戏客户机的TCP侦听器。) -->

      <TCPListener

        IPAddress=0.0.0.0

        Port=4530

        OverrideApplication=Master

        PolicyFile=Policy\assets\socket-policy.xml

        InactivityTimeout=10000

        >

      </TCPListener>

 

      <TCPListener

        IPAddress=0.0.0.0

        Port=4531

        OverrideApplication=Game

        PolicyFile=Policy\assets\socket-policy.xml

        InactivityTimeout=10000>

      </TCPListener>

 

      <!-- DONT SENDTHIS. TCP listener for GameServers on Master application.(立钻哥哥:不要SENDTHIS。用于主应用程序上的GameServers的TCP侦听器。) -->

      <TCPListener

        IPAddress=0.0.0.0

        Port=4520

      </TCPListener>

 

    </TCPListeners>

 

    <PolicyFileListeners>...</PolicyFileListeners>

    <WebSocketListeners>...</WebSocketListeners>

    <Runtime  >...</Runtime>

    <Applications Default=Master>...</Applications>

  </LoadBalancing>

 

  <!-- Instance settings.(立钻哥哥:实例设置。) -->

  <MMoDemo>...</MMoDemo>

 

</Configuration>

 

 

++<LoadBalancing>/<PolicyFileListeners>...</PolicyFileListeners>

++++立钻哥哥:负载均衡/协议文件监听(PolicyFileListeners

<?xml version=1.0 encoding=Windows-1252?>

 

<Configuration>

  <!-- Multiple instance are supported. Each instance has its own node in the config file.(立钻哥哥:支持多个实例。每一个实例在配置文件中都有本身的节点。) -->

 

  <LoadBalancing

    MaxMessageSize=512000

    MaxQueuedDataPerPeer=512000

    PerPeerMaxReliableDataInTransit=51200

    PerPeerTransmitRateLimitKBSec=256

    PerPeerTransmitRatePeriodMilliseconds=200

    MinimumTimeOut=5000

    MaximumTimeOut=30000

    DisplayName=LoadBalancing (MyCloud)>

 

    <UDPListeners>...</UDPListeners>

    <TCPListeners>...</TCPListeners>

 

    <!-- Policy request listener for Unity and Flash (port 843) and Silverlight (port 943).(立钻哥哥:Unity和Flash(端口843)以及Silverlight(端口943)的策略请求监听器。) -->

    <PolicyFileListeners>

      <!-- multiple Listeners allowed for different ports.(立钻哥哥:容许多个侦听器用于不一样的端口。) -->

      <PolicyFileListener

        IPAddress=0.0.0.0

        Port=843

        PolicyFile=Policy\assets\socket-policy.xml>

      </PolicyFileListener>

      <PolicyFileListener

        IPAddress=0.0.0.0

        Port=943

        PolicyFile=Policy\assets\socket-policy.xml>

      </PolicyFileListener>

    </PolicyFileListeners>

 

    <WebSocketListeners>...</WebSocketListeners>

    <Runtime  >...</Runtime>

    <Applications Default=Master>...</Applications>

 

  </LoadBalancing>

 

  <!-- Instance settings.(立钻哥哥:实例设置。) -->

  <MMoDemo>...</MMoDemo>

 

</Configuration>

 

 

++<LoadBalancing>/<WebSocketListeners>...</WebSocketListeners>

++++立钻哥哥:负载均衡/WebSocket监听(WebSocketListeners

<?xml version=1.0 encoding=Windows-1252?>

 

<Configuration>

 

  <LoadBalancing

    MaxMessageSize=512000

    MaxQueuedDataPerPeer=512000

    PerPeerMaxReliableDataInTransit=51200

    PerPeerTransmitRateLimitKBSec=256

    PerPeerTransmitRatePeriodMilliseconds=200

    MinimumTimeOut=5000

    MaximumTimeOut=30000

    DisplayName=LoadBalancing (MyCloud)>

 

    <UDPListeners>...</UDPListeners>

    <TCPListeners>...</TCPListeners>

    <PolicyFileListeners>...</PolicyFileListeners>

 

    <!-- WebSocket (and Flash-Fallback) compatible listener.(立钻哥哥:兼容WebSocket(和flash回退)的侦听器。) -->

    <WebSocketListeners>

      <WebSocketListener

        IPAddress=0.0.0.0

        Port=9090

        DisableNagle=true

        InactivityTimeout=10000

        OverrideApplication=Master>

      </WebSocketListener>

 

      <WebSocketListener

        IPAddress=0.0.0.0

        Port=9091

        DisableNagle=true

        InactivityTimeout=10000

        OverrideApplication=Game>

      </WebSocketListener>

 

    </WebSocketListeners>

 

    <Runtime  >...</Runtime>

    <Applications Default=Master>...</Applications>

 

  </LoadBalancing>

 

  <!-- Instance settings.(立钻哥哥:实例设置。) -->

  <MMoDemo>... </MMoDemo>

 

</Configuration>

 

 

++<LoadBalancing>/<Runtime>...</Runtime>

++++立钻哥哥:负载均衡/运行时(Runtime

<?xml version=1.0 encoding=Windows-1252?>

 

<Configuration>

 

  <LoadBalancing

    MaxMessageSize=512000

    MaxQueuedDataPerPeer=512000

    PerPeerMaxReliableDataInTransit=51200

    PerPeerTransmitRateLimitKBSec=256

    PerPeerTransmitRatePeriodMilliseconds=200

    MinimumTimeOut=5000

    MaximumTimeOut=30000

    DisplayName=LoadBalancing (MyCloud)>

 

    <UDPListeners>...</UDPListeners>

    <TCPListeners>...</TCPListeners>

    <PolicyFileListeners>...</PolicyFileListeners>

    <WebSocketListeners>...</WebSocketListeners>

 

    <!-- Defines the Photon Runtime Assembly to use.(立钻哥哥:定义要使用的光子运行时程序集。) -->

    <Runtime  

      Assembly=PhotonHostRuntime, Culture=neutral

      Type=PhotonHostRuntime.PhotonDomainManager

      UnhandledExceptionPolicy=Ignore>

    </Runtime>

 

    <Applications Default=Master>...</Applications>

 

  </LoadBalancing>

 

  <!-- Instance settings.(立钻哥哥:实例设置。) -->

  <MMoDemo>... </MMoDemo>

 

</Configuration>

 

 

++<LoadBalancing>/<Applications>...</Applications>

++++立钻哥哥:负载均衡/应用程序(Applications);

<?xml version=1.0 encoding=Windows-1252?>

 

<Configuration>

 

  <LoadBalancing

    MaxMessageSize=512000

    MaxQueuedDataPerPeer=512000

    PerPeerMaxReliableDataInTransit=51200

    PerPeerTransmitRateLimitKBSec=256

    PerPeerTransmitRatePeriodMilliseconds=200

    MinimumTimeOut=5000

    MaximumTimeOut=30000

    DisplayName=LoadBalancing (MyCloud)>

 

    <UDPListeners>....</UDPListeners>

    <TCPListeners>...</TCPListeners>

    <PolicyFileListeners>...</PolicyFileListeners>

    <WebSocketListeners>...</WebSocketListeners>

    <Runtime  >...</Runtime>

 

    <!-- Defines which applications are loaded on start and which of them is used by default. Make sure the default application is defined.(立钻哥哥:定义在启动时加载哪些应用程序,以及默认状况下使用哪些应用程序。确保定义了默认应用程序。) -->

    <!-- Application-folders must be located in the same folder as the bin_win32 folders. The BaseDirectory must include a bin folder.(立钻哥哥:应用程序文件夹必须位于与bin_win32文件夹相同的文件夹中。基目录必须包括一个“bin”文件夹。) -->

    <Applications Default=Master>

      <Application

        Name=Master

        BaseDirectory=LoadBalancing\Master

        Assembly=Photon.LoadBalancing

        Type=Photon.LoadBalancing.MasterServer.MasterApplication

        ForceAutoRestart=true

        WatchFiles=dll;config

        ExcludeFiles=log4net.config

        >

      </Application>

      <Application

        Name=Game

        BaseDirectory=LoadBalancing\GameServer

        Assembly=Photon.LoadBalancing

        Type=Photon.LoadBalancing.GameServer.GameApplication

        ForceAutoRestart=true

        WatchFiles=dll;config

        ExcludeFiles=log4net.config

        >

      </Application>

 

      <!-- CounterPublisher Application. -->

      <Application

        Name=CounterPublisher

        BaseDirectory=CounterPublisher

        Assembly=CounterPublisher

        Type=Photon.CounterPublisher.Application

        ForceAutoRestart=true

        WatchFiles=dll;config

        ExcludeFiles=log4net.config

        >

      </Application>

 

    </Applications>

 

  </LoadBalancing>

 

  <!-- Instance settings.(立钻哥哥:实例设置。) -->

  <MMoDemo>... </MMoDemo>

 

</Configuration>

 

 

 

++<MMoDemo>...</MMoDemo>

++++立钻哥哥:MMO(Massive Multiplayer Online)大型多人在线

<?xml version=1.0 encoding=Windows-1252?>

 

<Configuration>

  <LoadBalancing>...</LoadBalancing>

 

  <!-- Instance settings.(立钻哥哥:实例设置。) -->

  <MMoDemo

    MaxMessageSize=512000

    MaxQueuedDataPeer=512000

    PerPeerMaxReliableDataInTransit=51200

    PerPeerTransmitRateLimitKBSec=256

    PerPeerTransmitRatePeriodMilliseconds=200

    MinimumTimeout=5000

    MaximumTimeout=30000

    DisplayName=MMO Demo

    >

 

    <UDPListeners>...</UDPListeners>

    <TCPListeners>...</TCPListeners>

    <PolicyFileListeners>...</PolicyFileListeners>

    <WebSocketListeners>...</WebSocketListeners>

    <Runtime  >...</Runtime>

    <Applications Default=MMoDemo>...</Applications>

    

  </MMoDemo>

 

</Configuration>

 

 

 

++A.2.四、运行PhotonControl.exe文件

++++立钻哥哥:PhotonServer\deploy\bin_Win64\PhotonControl.exe

 

 

 

 

 

##A.三、Photon异常排查

##A.三、Photon异常排查

++A.三、Photon异常排查

++++立钻哥哥:程序都会有bug,那咱们就来Debug一下;这节将介绍当Photon服务器不能启动的时候,如何检查和处理;

++++A.3.一、如何检查Photon服务器运行须要开放的端口

++++A.3.二、如何检查Windows系统里的端口和防火墙设置

++++A.3.三、如何检查Photon异常日志

++++A.3.四、立钻哥哥Debug经验谈

 

 

++A.3.一、如何检查Photon服务器运行须要开放的端口

++++立钻哥哥:udp-port: 5055】,【tcp-port: 4530, 843, 943】等;

 

 

 

++A.3.二、如何检查Windows系统里的端口和防火墙设置

++++立钻哥哥:防火墙】=>【高级设置】=>【入站规则】=>【新建规则】;

 

 

++A.3.三、如何检查Photon异常日志

++++立钻哥哥:异常排查的一个有效途径就是看Log,固然引擎必须提供日志系统,这样才能有记录可查,要不本身写一个日志系统记录引擎的相关日志;固然,做为牛逼引擎的Photon提供了完整的日志记录系统,因此咱们就能够直接查看分析了

 

++++PhotonServer-SDK\deploy\log\

 

++++PhotonServer-SDK\deploy\bin_Win64\log\

 

 

++Photon-LoadBalancing-20190130.log

++++立钻哥哥:Photon\deploy\bin_Win64\log\Photon-LoadBalancing-20190130.log

 

 

++A.3.四、立钻哥哥Debug经验谈

++++立钻哥哥:做为资深的游戏开发人员,看Log分析的能力是要有的;根据业务编写本身的日志跟踪系统也是要有的;固然做为网络项目,日志的上传接收等后台记录系统也是要有的

++++日志系统在一个成熟项目中是必须有的,做为前期项目更是锦上添花的功能

 

 

 

 

 

 

 

##A.四、在Unity3D里添加Photon插件

##A.四、在Unity3D里添加Photon插件

++A.四、在Unity3D里添加Photon插件

++++立钻哥哥:这节将介绍如何在Unity3D里添加Photon插件,使其能在Unity3D里被正常使用

++++A.4.一、Photon插件在Unity3D里添加后的文件内容及结构

++++A.4.二、Photon插件在Unity3D上的使用方法

++++A.4.三、如何编写脚本代码,与Photon服务器链接

++++A.4.四、立钻哥哥对Photon插件的理解与使用

 

++A.4.一、Photon插件在Unity3D里添加后的文件内容及结构

++++立钻哥哥:好吧,让咱们新建一个Unity工程吧

 

 

++++添加“Photon3Unity3D.dll”到Unity工程的Plugins/下:

 

 

 

++A.4.二、Photon插件在Unity3D上的使用方法

++++立钻哥哥:好吧,Dll添加进Unity工程了,那咱们就开始使用吧

++++新建一个脚本,挂载到任何物体(“立钻哥哥的PhotonServer”)上吧:

 

 

++推荐使用VS打开脚本

++++立钻哥哥:Unity支持Mono编辑器,但使用Photon引擎时,建议使用VS,能够查看到解决方案之类的细节,谁让VS牛逼呢!

 

 

++A.4.三、如何编写脚本代码,与Photon服务器链接

++++立钻哥哥:好吧,开始编写代码咯,验证一下吧

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

 

using ExitGames.Client.Photon;    //立钻哥哥:引入Photon命名空间

 

//立钻哥哥的一个测试Photon服务的Demo

public class YanlzPhotonDemoV03 : MonoBehaviour, IPhotonPeerListener{

    public void DebugReturn(DebugLevel level, string message){}

    public void OnEvent(EventData eventData){}

    public void OnOperationResponse(OperationResponse operationResponse){}

    public void OnStatusChanged(StatusCode statusCode){}

 

    void Start(){}

    void Update(){}

}    //立钻哥哥:public class YanlzPhotonDemoV03{}

 

 

++链接Photon服务器

++++立钻哥哥:编写简单业务,尝试链接Photon服务器

++++[new PhotonPeer(this, ConnectionProtocol.Udp);]

++++[myPeer.Connect(myServAddress, myServAppName);]

++++[myPeer.Service();]

++++[public void OnStatusChanged(StatusCode statusCode){}]

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

 

using ExitGame.Client.Photon;    //立钻哥哥:引入Photon命名空间

 

//立钻哥哥的一个测试Photon服务的Demo

public class YanlzPhotonDemoV03 : MonoBehaviour, IPhotonPeerListener{

    PhotonPeer myPeer;

    string myServAddress = 127.0.0.1:5055;

    string myServAppName = Lite;

 

    void Start(){

        myPeer = new PhotonPeer(this, ConnectionProtocol.Udp);

        myPeer.Connect(myServAddress, myServAppName);

    }

 

    void Update(){

        myPeer.Service();

    }

 

    public void DebugReturn(DebugLevel level, string message){}

    public void OnEvent(EventData eventData){}

    public void OnOperationResponse(OperationResponse operationResponse){}

 

    public void OnStatusChanged(){

        switch(statusCode){

            case StatusCode.Connect:{

                Debug.Log(立钻哥哥:链接成功!---1111---);

                break;

            }

            case StatusCode.Disconnect:{

                Debug.Log(立钻哥哥:断开链接!---9999---);

                break;

            }

            case StatusCode.ExceptionOnConnect:{

                Debug.Log(立钻哥哥:链接异常! ---5555---);

                break;

            }

        }

    }    //立钻哥哥:public void OnStatusChanged(){}

 

}    //立钻哥哥:public class YanlzPhotonDemoV03{}

 

 

++A.4.四、立钻哥哥对Photon插件的理解与使用

++++立钻哥哥:到目前为止已经把Photon插件初步与Unity对接上了,是否是很刺激呢?接下来会更刺激,那就继续往下看吧!

 

 

 

 

 

 

 

 

 

 

#第二篇:Photon客户端脚本编写

#第二篇:Photon客户端脚本编写

#第二篇:Photon客户端脚本编写

++++立钻哥哥:从这一篇开始咱们开始编写脚本了,简单操练一下,为后面的深度开发热热身呗!主要完成在Unity3D客户端编写脚本与Photon服务器进行数据通讯以及完成游戏房间的基本操做;手机网游中数据通讯是基本的核心功能,为后期实现Unity3D客户端和Photon服务器之间通讯打下基础;同时也掌握了基于游戏房间的此类游戏中如何进入和离开游戏房间;

++++B.一、向Photon服务器发送请求

++++B.二、处理Photon服务器返回的响应

++++B.三、游戏房间操做

++++B.四、自定义事件

++++B.五、立钻哥哥拓展脚本编写

 

 

 

 

##B.一、向Photon服务器发送请求

##B.一、向Photon服务器发送请求

++B.一、向Photon服务器发送请求

++++立钻哥哥:本节将介绍如何从Unity3D客户端发送请求到Photon服务器;这就开始进入使用Photon开发网络游戏了

++++B.1.一、如何实现消息发送函数SendMessage

++++B.1.二、如何调用Photon服务函数Service

 

++B.1.一、如何实现消息发送函数SendMessage

++++立钻哥哥:myPeer.OpCustom(LiteOpKey.GameID, para, true);

++++class LiteOpKey{}:

namespace ExitGames.Client.Photon.Lite{

    public static class LiteOpKey{

        public const byte ActorList = 252;

        public const byte ActorNr = 254;

        public const byte ActorProperties = 249;

        public const byte Add = 238;

        [Obsolete(Use GameId)]

        public const byte Asid = 255;

        public const byte Broadcast = 250;

        public const byte Cache = 247;

        public const byte Code = 244;

        public const byte Data = 245;

        public const byte GameId = 255;

        public const byte GameProperties = 248;

        public const byte Group = 240;

        public const byte Properties = 251;

        public const byte ReceiverGroup = 246;

        public const byte Remove = 239;

        [Obsolete(Use GameId)]

        public const byte RoomName = 255;

        public const byte TargetActorNr = 253;

    }    //立钻哥哥:public static class LiteOpKey{}

}    //立钻哥哥:namespace ExitGames.Client.Photon.Lite{}

 

 

++++SendMessage(){}:

using ExitGame.Client.Photon;    //立钻哥哥:引入Photon命名空间

 

//立钻哥哥的一个测试Photon服务的Demo

public class YanlzPhotonDemoV03 : MonoBehaviour, IPhotonPeerListener{

    PhotonPeer myPeer;

    string myServAddress = 127.0.0.1:5055;

    string myServAppName = Lite;

 

    void Start(){

        myPeer = new PhotonPeer(this, ConnectionProtocol.Udp);

        myPeer.Connect(myServAddress, myServAppName);

    }

 

    void Update(){

        myPeer.Service();

    }

 

    Void SendMyMessage(){

        Dictionary<byte, object> para = new Dictionary<byte, object>();

        Para[LiteOpKey.GameId] = 1;

        myPeer.OpCustom(LiteOpKey.GameId, para, true);

    }

 

    Void OnGUI(){

        If(GUI.Button(new Rect(Screen.width/2 - 50, 100, 100, 30), 设置游戏编号)){

            SendMyMessage();

        }

    }

 

    public void DebugReturn(DebugLevel level, string message){}

 

    public void OnEvent(EventData eventData){

        Debug.Log(立钻哥哥:触发了事件: + eventData.ToStringFull());

    }

 

    public void OnOperationResponse(OperationResponse operationResponse){

        Debug.Log(立钻哥哥:服务器返回响应: + operationResponse.ToStringFull());

    }

 

    public void OnStatusChanged(){

        switch(statusCode){

            case StatusCode.Connect:{

                Debug.Log(立钻哥哥:链接成功!---1111---);

                break;

             }

            case StatusCode.Disconnect:{

                Debug.Log(立钻哥哥:断开链接!---9999---);

                break;

            }

            case StatusCode.ExceptionOnConnect:{

                Debug.Log(立钻哥哥:链接异常! ---5555---);

                break;

            }

        }

    }    //立钻哥哥:public void OnStatusChanged(){}

 

}    //立钻哥哥:public class YanlzPhotonDemoV03{}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

++立钻哥哥推荐的拓展学习连接(Link_Url)

立钻哥哥推荐的拓展学习连接(Link_Url)

++++立钻哥哥Unity 学习空间: http://blog.csdn.net/VRunSoftYanlz/

++++Unity5.x用户手册http://www.javashuo.com/article/p-ufnzpmga-s.html

++++Unity面试题ABChttp://www.javashuo.com/article/p-mwacxwca-gm.html

++++Unity面试题Dhttp://www.javashuo.com/article/p-wuwcrclr-s.html

++++Unity面试题Ehttp://www.javashuo.com/article/p-hmabbtmc-ba.html

++++Unity面试题Fhttp://www.javashuo.com/article/p-olslkfao-cq.html

++++Cocos2dx面试题http://www.javashuo.com/article/p-daozmsii-cz.html

++++禅道[zentao]http://www.javashuo.com/article/p-rqsvjwtk-cz.html

++++C#事件http://www.javashuo.com/article/p-zmwruvql-gm.html

++++C#委托http://www.javashuo.com/article/p-uozpymaf-gh.html

++++C#集合http://www.javashuo.com/article/p-sfqfdqsf-ex.html

++++C#泛型http://www.javashuo.com/article/p-xrttqngo-ee.html

++++C#接口http://www.javashuo.com/article/p-vhlfplgv-dm.html

++++C#静态类https://blog.csdn.net/vrunsoftyanlz/article/details/78630979

++++C#中System.String类http://www.javashuo.com/article/p-olslkfao-cq.html

++++C#数据类型http://www.javashuo.com/article/p-hmabbtmc-ba.html

++++Unity3D默认的快捷键http://www.javashuo.com/article/p-wuwcrclr-s.html

++++Unity引擎基础http://www.javashuo.com/article/p-beommoeb-ka.html

++++Unity面向组件开发http://www.javashuo.com/article/p-eigmuvut-dt.html

++++Unity物理系统http://www.javashuo.com/article/p-nqvvciwv-kd.html

++++Unity2D平台开发http://www.javashuo.com/article/p-ycaagdtj-hs.html

++++UGUI基础http://www.javashuo.com/article/p-rukxwckw-mc.html

++++UGUI进阶http://www.javashuo.com/article/p-wcatruhq-gt.html

++++UGUI综合http://www.javashuo.com/article/p-dkccmqii-gg.html

++++Unity动画系统基础http://www.javashuo.com/article/p-mbrdouxy-dq.html

++++Unity动画系统进阶http://www.javashuo.com/article/p-aqaqpbkh-bp.html

++++Navigation导航系统http://www.javashuo.com/article/p-dswwllas-t.html

++++Unity特效渲染http://www.javashuo.com/article/p-ckojjyfj-bp.html

++++Unity数据存储http://www.javashuo.com/article/p-bvlzynso-m.html

++++Unity中Sqlite数据库http://www.javashuo.com/article/p-ejutsbxl-ca.html

++++WWW类和协程http://www.javashuo.com/article/p-dbwmhsav-cy.html

++++Unity网络http://www.javashuo.com/article/p-sqrlntgh-dw.html

++++PhotonServer简介http://www.javashuo.com/article/p-cjotdrlu-z.html

++++编写Photon游戏服务器http://www.javashuo.com/article/p-mrqkaqlj-dn.html

++++设计模式简单整理http://www.javashuo.com/article/p-rngqugib-hg.html

++++专题:设计模式(精华篇)http://www.javashuo.com/article/p-nbohnaya-hw.html

++++U3D小项目参考https://blog.csdn.net/vrunsoftyanlz/article/details/80141811

++++Unity案例(Vehicle)http://www.javashuo.com/article/p-wxnfscgy-dy.html

++++UML类图http://www.javashuo.com/article/p-sxberuew-bm.html

++++PowerDesigner简介http://www.javashuo.com/article/p-deknpwxv-cu.html

++++Unity知识点0001http://www.javashuo.com/article/p-ryvdxxjr-ep.html

++++Unity知识点0008http://www.javashuo.com/article/p-kxgstxls-gu.html

++++U3D_Shader编程(第一篇:快速入门篇)http://www.javashuo.com/article/p-kyppgrac-gz.html

++++U3D_Shader编程(第二篇:基础夯实篇)http://www.javashuo.com/article/p-qkyowtli-hv.html

++++框架知识点http://www.javashuo.com/article/p-eufbowgf-u.html

++++游戏框架(UI框架夯实篇)http://www.javashuo.com/article/p-cvemoigb-cu.html

++++游戏框架(初探篇)http://www.javashuo.com/article/p-zfpoilbc-hy.html

++++Lua快速入门篇(基础概述)http://www.javashuo.com/article/p-shernvtt-u.html

++++Lua快速入门篇(XLua教程):http://www.javashuo.com/article/p-pduvmusb-ho.html

++++Lua快速入门篇(Xlua拓展):http://www.javashuo.com/article/p-rrszijom-cm.html

++++UnityAPI.Rigidbody刚体http://www.javashuo.com/article/p-phaztrtw-w.html

++++HTC_VIVE开发基础http://www.javashuo.com/article/p-mhcdmelt-bt.html

++++Oculus杂谈http://www.javashuo.com/article/p-unmgvyjw-ce.html

++++Oculus安装使用http://www.javashuo.com/article/p-ulvvimkb-cr.html

++++SteamVR简介http://www.javashuo.com/article/p-awcwwcaq-ea.html

++++SteamVR脚本功能分析http://www.javashuo.com/article/p-ajqgwdev-ek.html

++++SteamVR2.0开发指南http://www.javashuo.com/article/p-wgdghzsl-er.html

++++SteamVR/Extrashttp://www.javashuo.com/article/p-qrebqbra-he.html

++++SteamVR/Inputhttp://www.javashuo.com/article/p-avbvrjff-ga.html

++++OpenXR简介http://www.javashuo.com/article/p-qgsgcamr-eu.html

++++VRTK杂谈http://www.javashuo.com/article/p-gsryrkjk-eb.html

++++VRTK快速入门(杂谈)http://www.javashuo.com/article/p-bgvfnmia-cm.html

++++VRTK官方示例(目录)http://www.javashuo.com/article/p-dsnjffvq-ea.html

++++VRTK代码结构(目录)http://www.javashuo.com/article/p-wfilzqyd-es.html

++++VRTK(SceneResources)http://www.javashuo.com/article/p-ryptqvzl-hm.html

++++VRTK_ControllerEventshttp://www.javashuo.com/article/p-sciqvywx-hv.html

++++VRTK_InteractTouchhttp://www.javashuo.com/article/p-ggucvtwz-hq.html

++++UnityAPI.Material材质http://www.javashuo.com/article/p-ntyoqcng-q.html

++++UnityAPI.Android安卓http://www.javashuo.com/article/p-fyyfgkck-q.html

++++UnityAPI.AndroidJNI安卓JNIhttp://www.javashuo.com/article/p-kvxjsnzf-w.html

++++UnityAPI.Transform变换http://www.javashuo.com/article/p-bfgrrhxl-cq.html

++++UnityAPI.WheelCollider轮碰撞器http://www.javashuo.com/article/p-smnaoooi-cn.html

++++UnityAPI.Resources资源http://www.javashuo.com/article/p-utqnokva-bu.html

++++JSON数据结构http://www.javashuo.com/article/p-dljbtddn-g.html

++++CocosStudio快速入门http://www.javashuo.com/article/p-qldbaqqa-v.html

++++VR实验:以太网帧的构成http://www.javashuo.com/article/p-fnfhdcgt-bp.html

++++FrameVR示例V0913http://www.javashuo.com/article/p-xnlrngai-cw.html

++++FrameVR示例V1003http://www.javashuo.com/article/p-ztazxpkv-bd.html

++++SwitchMachineV1022http://www.javashuo.com/article/p-tqkoklov-s.html

++++PlaySceneManagerV1022http://www.javashuo.com/article/p-tqkoklov-s.html

++++Unity企业内训(目录)http://www.javashuo.com/article/p-oefbctlf-mn.html

++++Unity企业内训(第1讲)http://www.javashuo.com/article/p-ehlblkrj-mc.html

++++Unity企业内训(第2讲)http://www.javashuo.com/article/p-tiecmlwc-ma.html

++++Unity企业内训(第3讲)http://www.javashuo.com/article/p-mlpucjnv-ma.html

++++Unity企业内训(第4讲)http://www.javashuo.com/article/p-vfalurum-kz.html

++++Unity企业内训(第5讲)http://www.javashuo.com/article/p-ncrckqey-kv.html

++++Unity企业内训(第6讲)http://www.javashuo.com/article/p-gcrucvtb-ku.html

++++插件<Obi Rope>http://www.javashuo.com/article/p-rmhegsmj-kr.html

++++计算机组成原理(教材篇)http://www.javashuo.com/article/p-sejaldpf-kr.html

++++立钻哥哥Unity 学习空间: http://blog.csdn.net/VRunSoftYanlz/

--_--VRunSoft:lovezuanzuan--_--