Scut游戏server引擎Unity3d访问
Scut提供Unity3d Sdk包。便利的高速发展和Scut游戏server对接; 看Unity3d示为以下的比率:
启动Unity3d项目
打开Scutc.svn\SDK\Unity3d\Assets文件夹下的TestScene.unity项目文件,选中Main
Camera。将TestGUI.cs文件拖动到Inspector窗体的Script,如图:


点击
执行。例如以下:
文件夹层次说明
1)
Net层:封装Http与Socket请求操作,以及网络协议的数据解析和请求參数的打包,当中NetWriter里有SetMd5Key为设置网络协议请求參数的Key,用于跟服务校验请求參数的有效性
2)
Reflect层:提供高性能的反射功能
3)
Security层:加密操作
4)
Serialization层:封装对象的序列化操作
5)
Game层:游戏业务逻辑层代码实现功能,此文件夹下的Action和Behaviour文件夹,依据业务自己实现代码
6)
CustomHeadFormater类:自定的结构消息头解析器
7)
TestGUI.cs为測试脚本
TestGUI代码
|
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
|
using public TestGUI : MonoBehaviour { // Use this for initialization voidStart() { //todo 启用自定的结构 Net.Instance.HeadFormater =new CustomHeadFormater(); } // Update is called once per frame voidUpdate() { } voidOnGUI() { // Now create any Controls you like, and they will be displayed with the custom Skin if(GUILayout.Button("Click Http")) { Net.Instance.Send((int)ActionType.RankSelect,null);
} // Any Controls created here will use the default Skin and not the custom Skin if(GUILayout.Button("Click Socket")) { NetWriter.SetUrl("ph.scutgame.com:9001"); Net.Instance.Send((int)ActionType.RankSelect,null);
} }} |
Send方法接口会依据url是否带http字段来推断是否是用http还是socket,
Action和Behaviour文件夹下实现自己的业务代码
自定头部解析类CustomHeadFormater代码
|
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
52
53
54
|
using using using /// <summary>
/// 定制的头部结构解析
/// </summary>
public CustomHeadFormater : IHeadFormater
{ publicbool TryParse(byte[] data,out PackageHead head,out byte[] bodyBytes) { bodyBytes =null;
head =null;
intpos = 0; if(data == null|| data.Length == 0) { returnfalse; } intheadSize = GetInt(data, refpos); byte[] headBytes =new byte[headSize]; Buffer.BlockCopy(data, pos, headBytes, 0, headBytes.Length); pos += headSize; ResponsePack resPack = ProtoBufUtils.Deserialize<ResponsePack>(headBytes); head =new PackageHead(); head.StatusCode = resPack.ErrorCode; head.MsgId = resPack.MsgId; head.Description = resPack.ErrorInfo; head.ActionId = resPack.ActionId; head.StrTime = resPack.St; intbodyLen = data.Length - pos; if(bodyLen > 0) { bodyBytes =new byte[bodyLen]; Buffer.BlockCopy(data, pos, bodyBytes, 0, bodyLen); } else { bodyBytes =new byte[0]; } //UnityEngine.Debug.Log(string.Format("ActionId:{0}, ErrorCode:{1}, len:{2}", resPack.ActionId, resPack.ErrorCode, bodyBytes.Length)); returntrue; } privateint GetInt(byte[] data,ref intpos) { intval = BitConverter.ToInt32(data, pos); pos +=sizeof(int); returnval; }} |
BaseAction代码
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
/// <summary>
/// 自定结构Action代理基类/// </summary>
public class { protectedBaseAction(intactionId) :base(actionId) { } protectedoverride voidSetActionHead(NetWriter writer) { MessagePack headPack =new MessagePack() { MsgId = Head.MsgId, ActionId = ActionId, SessionId = Head.SessionId, UserId = Head.UserId }; byte[] data = ProtoBufUtils.Serialize(headPack); writer.SetHeadBuffer(data); writer.SetBodyData(null); }} |
Action1001代码
|
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
|
using using using using public Action1001 : BaseAction { privateResponse1001Pack _responseData; publicAction1001() :base((int)ActionType.RankSelect) { } protectedoverride voidSendParameter(NetWriter writer, objectuserData) { //自定对象參数格式 Request1001Pack requestPack =new Request1001Pack() { PageIndex = 1, PageSize = 10 }; byte[] data = ProtoBufUtils.Serialize(requestPack); writer.SetBodyData(data); } protectedoverride voidDecodePackage(NetReader reader) { if(reader.StatusCode == 0) { //自定对象格式解包 _responseData = ProtoBufUtils.Deserialize<Response1001Pack>(reader.Buffer); } } protectedoverride voidProcess(objectuserData) { if(_responseData != null) { UnityEngine.Debug.Log(string.Format("ok,, _responseData.PageCount));
} }} |
一个完整的样本Sample For Unity3d源代码下载
Scut游戏server引擎Unity3d访问的更多相关文章
- Scut游戏服务器引擎6.1.5.6发布,直接可运行,支持热更新
1. 增加exe版(console),web版本(IIS)的游戏服宿主程序 2. 增加Model支持脚本化,实现不停服更新 3. 增加Language支持脚本化 4. 修改Sns与Pay Center ...
- Scut游戏服务器引擎6.0.5.0发布-支持C#脚本
1. 增加C#脚本支持2. 增加Pay和Sns中间件对Mysql数据库支持3. 精简布署步骤,取消Redis写入程序,将其移到游戏底层运行4. 修正Mysql对中文可能会出现乱码的BUG 点击下载:S ...
- Scut游戏服务器引擎之Unity3d接入
Scut提供Unity3d Sdk包,方便开发人员快速与Scut游戏服务器对接: 先看Unity3d示例如下: 启动Unity3d项目 打开Scutc.svn\SDK\Unity3d\Assets目录 ...
- Scut游戏服务器引擎之新手入门
1. 开发语言:Scut提供C#或Python两种脚本语言开发,Python脚本的性能会比较差,建议使用编译执行的C#代码: 2. 运行平台:Scut可以Window与Linux平台上运行,Linux ...
- Scut游戏服务器引擎6.5.8.6发布
1.增加从Redis中加载数据到Cache可设置筛选条件2.修改在Web项目中的不能支持自定协议问题3.修改Share类型的Model在Redis中为空时会尝试从DB中加载数据4.修改Model命名空 ...
- Scut游戏服务器引擎6.0.5.2发布
1. 增加C#脚本中能引用多个C#脚本文件的支持2. 修正Web应用程序中使用C#脚本解析不到Bin目录的问题
- Scut游戏服务器引擎6.0.5.1发布
1. 修正缓存删除时不会更新到Redis的问题 2. 修正Model组合3个以上子类时Change事件未绑定的问题 3. 修正中间层MySql与MsSql数据库Sql语句分页问题
- Scut游戏服务器引擎5.6.3.5发布
版本:5.6.3.5 (2013-11-25) 1. 优化实体ChangeKey队列,减少写库IO(默认为5分钟写入一次数据库) 2. 优化Protobuf序列化启用自动GZip压缩,减少Redis内 ...
- Scut游戏引擎改造兼容Codis。
原生的Scut引擎是采用redis来做数据缓存层,引擎在以异步的方式(时间可配置,默认100ms)实现数据同步.为了提高redis的可扩展性.高可用性,把redis换成codis,因为codis有部分 ...
随机推荐
- 关于Relay Log无法自己主动删除的问题(Neither --relay-log nor --relay-log-index were used)
今天查看mysql err日志.发现mysql重新启动时总会有例如以下日志出现: [Warning] Neither --relay-log nor --relay-log-index were us ...
- .NET垃圾回收笔记
名词 垃圾收集目标 ephemeral GC 发生在Gen 0 和Gen 1 的垃圾收集 Full GC 发生Gen 2 及以上的Gen与LOH的垃圾收集 垃圾收集模式 工作站模式 GC直接发生在内存 ...
- HSQL
Whenever I connect to HSQLDB from my application deployed on eclipse Juno, it throws an exception as ...
- poj 2586 Y2K Accounting Bug (贪心)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8678 Accepted: 428 ...
- 【SICP归纳】2 高阶函数和数据抽象
上一篇博文相应的是书中的第一章的一二两节,我们已经大致的有了一种构造的感觉不是么. 书中展示了非常多有趣的句法(syntax). 如今我们要让思想进一步的抽象.写这篇博客的时候并未学完整本书.更不敢说 ...
- 【HTML+CSS】(1)基本语法
HTML基金会 <em>他强调标签,<strong>加粗标签 <q>短文本引用.<blockquote>长文本引用,这两个标签会让文字带双引號. 空 ...
- delphi webbrowser 经常使用的演示样本
var Form : IHTMLFormElement ; D:IHTMLDocument2 ; begin with WebBrowser1 do begin D := Document as IH ...
- Eclipse 在线安装fat jar插件
在线安装步骤: eclipse菜单栏 help >software updates >Search for new features to install>new update si ...
- 使用crontab创建 linux 系统定时任务#
任务1: 每隔1分钟,运行一次 /home/sn/yeelink.sh文件 ,用于上传数据到www.yeelink.net 1. 先在当时目录里面创建一个cronfile文件 vim cronfile ...
- 【原创】leetCodeOj --- Find Peak Element 解题报告
题目地址: https://oj.leetcode.com/problems/find-peak-element/ 题目内容: A peak element is an element that is ...