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
UnityEngine;
  
public
class
TestGUI : MonoBehaviour
{
  
    // Use this for initialization
    void
Start()
    {
        //todo 启用自定的结构
        Net.Instance.HeadFormater =
new CustomHeadFormater();
    }
  
    // Update is called once per frame
    void
Update()
    {
  
    }
  
    void
OnGUI()
    {
  
        // Now create any Controls you like, and they will be displayed with the custom Skin
        if
(GUILayout.Button("Click Http"))
        {
            NetWriter.SetUrl("http://ph.scutgame.com/service.aspx");
            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
System;
using
GameRanking.Pack;
using
ZyGames.Framework.Common.Serialization;
  
/// <summary>
/// 定制的头部结构解析
/// </summary>
public
class
CustomHeadFormater : IHeadFormater
{
    public
bool TryParse(byte[] data,
out PackageHead head,
out byte[] bodyBytes)
    {
        bodyBytes =
null;
        head =
null;
        int
pos = 0;
        if
(data == null
|| data.Length == 0)
        {
            return
false;
        }
        int
headSize = GetInt(data, ref
pos);
        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;
  
        int
bodyLen = 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));
  
        return
true;
    }
  
    private
int GetInt(byte[] data,
ref int
pos)
    {
        int
val = BitConverter.ToInt32(data, pos);
        pos +=
sizeof(int);
        return
val;
    }
}

  

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
abstract
class
BaseAction : GameAction
{
    protected
BaseAction(int
actionId)
        :
base(actionId)
    {
    }
  
    protected
override void
SetActionHead(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
System;
using
System.Collections.Generic;
using
GameRanking.Pack;
using
ZyGames.Framework.Common.Serialization;
  
public
class
Action1001 : BaseAction
{
    private
Response1001Pack _responseData;
  
    public
Action1001()
        :
base((int)ActionType.RankSelect)
    {
    }
  
    protected
override void
SendParameter(NetWriter writer, object
userData)
    {
    //自定对象參数格式
    Request1001Pack requestPack =
new Request1001Pack()
    {
        PageIndex = 1,
        PageSize = 10
    };
    byte[] data = ProtoBufUtils.Serialize(requestPack);
    writer.SetBodyData(data);
    }
  
    protected
override void
DecodePackage(NetReader reader)
    {
        if
(reader.StatusCode == 0)
        {
        //自定对象格式解包
        _responseData = ProtoBufUtils.Deserialize<Response1001Pack>(reader.Buffer);
              
        }
    }
  
    protected
override void
Process(object
userData)
    {
        if
(_responseData != null)
        {
            UnityEngine.Debug.Log(string.Format("ok,
count:{0}"
, _responseData.PageCount));
        }
    }
}

  

一个完整的样本Sample For Unity3d源代码下载

Scut游戏server引擎Unity3d访问的更多相关文章

  1. Scut游戏服务器引擎6.1.5.6发布,直接可运行,支持热更新

    1. 增加exe版(console),web版本(IIS)的游戏服宿主程序 2. 增加Model支持脚本化,实现不停服更新 3. 增加Language支持脚本化 4. 修改Sns与Pay Center ...

  2. Scut游戏服务器引擎6.0.5.0发布-支持C#脚本

    1. 增加C#脚本支持2. 增加Pay和Sns中间件对Mysql数据库支持3. 精简布署步骤,取消Redis写入程序,将其移到游戏底层运行4. 修正Mysql对中文可能会出现乱码的BUG 点击下载:S ...

  3. Scut游戏服务器引擎之Unity3d接入

    Scut提供Unity3d Sdk包,方便开发人员快速与Scut游戏服务器对接: 先看Unity3d示例如下: 启动Unity3d项目 打开Scutc.svn\SDK\Unity3d\Assets目录 ...

  4. Scut游戏服务器引擎之新手入门

    1. 开发语言:Scut提供C#或Python两种脚本语言开发,Python脚本的性能会比较差,建议使用编译执行的C#代码: 2. 运行平台:Scut可以Window与Linux平台上运行,Linux ...

  5. Scut游戏服务器引擎6.5.8.6发布

    1.增加从Redis中加载数据到Cache可设置筛选条件2.修改在Web项目中的不能支持自定协议问题3.修改Share类型的Model在Redis中为空时会尝试从DB中加载数据4.修改Model命名空 ...

  6. Scut游戏服务器引擎6.0.5.2发布

    1. 增加C#脚本中能引用多个C#脚本文件的支持2. 修正Web应用程序中使用C#脚本解析不到Bin目录的问题

  7. Scut游戏服务器引擎6.0.5.1发布

    1. 修正缓存删除时不会更新到Redis的问题 2. 修正Model组合3个以上子类时Change事件未绑定的问题 3. 修正中间层MySql与MsSql数据库Sql语句分页问题

  8. Scut游戏服务器引擎5.6.3.5发布

    版本:5.6.3.5 (2013-11-25) 1. 优化实体ChangeKey队列,减少写库IO(默认为5分钟写入一次数据库) 2. 优化Protobuf序列化启用自动GZip压缩,减少Redis内 ...

  9. Scut游戏引擎改造兼容Codis。

    原生的Scut引擎是采用redis来做数据缓存层,引擎在以异步的方式(时间可配置,默认100ms)实现数据同步.为了提高redis的可扩展性.高可用性,把redis换成codis,因为codis有部分 ...

随机推荐

  1. nyoj 228 士兵杀死(五岁以下儿童)【树状数组】

    分析:这个问题问的是,因为它是一个单独的更新.因此,让我们更新,然后在c[i]表现为1~i之间,还原之后看起来像一个. #include <cstdio> #include <cst ...

  2. 使IIS Express支持其他网络客户端访问

    今天尝试利用Android客户端Web浏览器访问VS2012 IIS Express调试中的Web应用,发现这个IIS Express仅支持localhost主机名地址访问. 上网搜索找到解决方案,几 ...

  3. Ubuntu14.04 用 CrossOver 安装 TMQQ2013

    Crossover 是 wine 的优化+商业版本号 ,  免去了wine的繁琐配置,让Ubuntu安装windows软件很easy..... 部分移植的软件还有官方的维护,执行效果也比較好..... ...

  4. 採用Android中的httpclient框架发送post请求

    /** * 採用httpclientPost请求的方式 * * @param username * @param password * @return null表示求得的路径有问题,text返回请求得 ...

  5. HDU 4982 Goffi and Squary Partition(推理)

    HDU 4982 Goffi and Squary Partition 思路:直接从全然平方数往下找,然后推断是否能构造出该全然平方数,假设能够就是yes,假设都不行就是no.注意构造时候的推断,因为 ...

  6. AES加密 C++调用Crypto++加密库 样例

    这阵子写了一些数据加密的小程序,对照了好几种算法后,选择了AES,高级加密标准(英语:Advanced Encryption Standard,缩写:AES).听这名字就非常厉害的样子 预计会搜索到这 ...

  7. Android在API推荐的方式来实现SQLite数据库的增长、删除、变化、检查操作

    package com.examp.use_SQLite.dao; import java.util.ArrayList; import java.util.List; import android. ...

  8. AutoFac使用方法总结:Part I

    注册部分 使用RegisterType进行注册 [Fact] public void can_resolve_myclass() { var builder = new ContainerBuilde ...

  9. [BEROR]CodeSign error: code signing is required for product type &#39;Application&#39; in SDK &#39;iOS 8.1&#39;

    解决方法: 选择project->Build Settings -> Code Signing -> Code Signing Identity -> Debug -> ...

  10. SRM 628 D1L3:DoraemonPuzzleGame,math,后市展望,dp

    称号:c=problem_statement&pm=13283&rd=16009">http://community.topcoder.com/stat?c=probl ...