一、Photon简介
Photon是一款非常不错的游戏服务端引擎,是一个服务器应用程序,可以在你选择的机器上运行,并且完全是自定义和权威性的控制,你可以自由的配置和部署多人应用的基础设施。
在客户端,Photon支持多样的平台,使用C,C#,Flash进行编程的方式是不同的,但是基本的工作流是相似的。在这文档中我们尝试去解释它的概念和背景,而语言的细节部分需要查阅每个语言平台的参考文档。
下载地址:https://www.photonengine.com/en/OnPremise/Download
解压后的相关文件夹说明:
deploy:主要存放photon的服务器控制程序和服务端Demo
doc:顾名思义,文档
lib:Photon类库,开发服务端需要引用的
src-server:服务端Demo源代码
在网络段,使用了Photon,所以拿来研究了下。看看代码,梳理了一下RPC流程。
记录下来,以供以后参考和使用。
官方网站:https://www.photonengine.com/en/PUN
分两个部分一个编辑器界面工作流程,一个是网络调用流程。
二、RPC编辑器调用代码
PhotonEditor.cs文件内,直接说代码
#region RPC List Handling
public static void UpdateRpcList()
{
List<string> additionalRpcs = new List<string>()
HashSet<string> currentRpcs = new HashSet<string>()
var types = GetAllSubTypesInScripts(typeof(MonoBehaviour))
int countOldRpcs = 0
foreach (var mono in types)
{
MethodInfo[] methods = mono.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
foreach (MethodInfo method in methods)
{
bool isOldRpc = false
#pragma warning disable 618
// we let the Editor check for outdated RPC attributes in code. that should not cause a compile warning
if (method.IsDefined(typeof (RPC), false))
{
countOldRpcs++
isOldRpc = true
}
#pragma warning restore 618
if (isOldRpc || method.IsDefined(typeof(PunRPC), false))
{
currentRpcs.Add(method.Name)
if (!additionalRpcs.Contains(method.Name) && !PhotonNetwork.PhotonServerSettings.RpcList.Contains(method.Name))
{
additionalRpcs.Add(method.Name)
}
}
}
}
if (additionalRpcs.Count > 0)
{
// LIMITS RPC COUNT
if (additionalRpcs.Count + PhotonNetwork.PhotonServerSettings.RpcList.Count >= byte.MaxValue)
{
if (currentRpcs.Count <= byte.MaxValue)
{
bool clearList = EditorUtility.DisplayDialog(CurrentLang.IncorrectRPCListTitle, CurrentLang.IncorrectRPCListLabel, CurrentLang.RemoveOutdatedRPCsLabel, CurrentLang.CancelButton)
if (clearList)
{
PhotonNetwork.PhotonServerSettings.RpcList.Clear()
PhotonNetwork.PhotonServerSettings.RpcList.AddRange(currentRpcs)
}
else
{
return
}
}
else
{
EditorUtility.DisplayDialog(CurrentLang.FullRPCListTitle, CurrentLang.FullRPCListLabel, CurrentLang.SkipRPCListUpdateLabel)
return
}
}
additionalRpcs.Sort()
PhotonNetwork.PhotonServerSettings.RpcList.AddRange(additionalRpcs)
EditorUtility.SetDirty(PhotonNetwork.PhotonServerSettings)
}
if (countOldRpcs > 0)
{
bool convertRPCs = EditorUtility.DisplayDialog(CurrentLang.RpcFoundDialogTitle, CurrentLang.RpcFoundMessage, CurrentLang.RpcReplaceButton, CurrentLang.RpcSkipReplace)
if (convertRPCs)
{
PhotonConverter.ConvertRpcAttribute("")
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51