位置: 编程技术 - 正文
推荐整理分享Scut游戏服务器引擎之Unity3d接入(scumpve服务器),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:scumpve服务器,scum服务器价格,scumpvp服务器,scytl服务器,scum服务器价格,scytl服务器,scum官方服务器ip,scum官方服务器ip,内容如对您有帮助,希望把文章链接给更多的朋友!
Scut提供Unity3d Sdk包,方便开发人员快速与Scut游戏服务器对接; 先看Unity3d示例如下:
启动Unity3d项目 打开Scutc.svnSDKUnity3dAssets目录下的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代码
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("[color=blue ! 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:"); Net.Instance.Send((int)ActionType.RankSelect, null); } }}Send方法接口会根据url是否带http字段来判断是否是用http还是socket, Action和Behaviour目录下实现自己的业务代码
自定头部解析类CustomHeadFormater代码
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.ToInt(data, pos); pos = sizeof(int); return val; }}BaseAction代码/// <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); }}Action代码using System;using System.Collections.Generic;using GameRanking.Pack;using ZyGames.Framework.Common.Serialization;public class Action : BaseAction{ private ResponsePack _responseData; public Action() : base((int)ActionType.RankSelect) { } protected override void SendParameter(NetWriter writer, object userData) { //自定对象参数式 RequestPack requestPack = new RequestPack() { PageIndex = 1, PageSize = }; byte[] data = ProtoBufUtils.Serialize(requestPack); writer.SetBodyData(data); } protected override void DecodePackage(NetReader reader) { if (reader.StatusCode == 0) { //自定对象式解包 _responseData = ProtoBufUtils.Deserialize<ResponsePack>(reader.Buffer); } } protected override void Process(object userData) { if (_responseData != null) { UnityEngine.Debug.Log(string.Format("ok, count:{0}", _responseData.PageCount)); } }}声明:此篇文档时来自于【狗刨学习网】社区,是网友自行发布的Unity3D学习文章,如果有什么内容侵犯了你的相关权益,请与官方沟通,我们会即时处理。更多精彩内容:www.gopedu.comUnity3D游戏开发之动画脚本 Animation Scripting 动画脚本AnimationScripting有时你需要程序化的驱动你的角色骨骼.例如你可能需要你的角色的头注视3d空间的某个点.这个活最好让脚本来干.幸运的是,Unity做
C#程序员整理的Unity 3D笔记(九):Unity 3D测试浅析 Unity中的组件上的类,是不能new的,必须通过组件去获取,new出来的东西是null。if(amainfo.nameHash==Animator.StringToHash(BaseLayer.idle)){m_animator.SetBool(Run,true);}代
Unity技巧集合 这篇文章将收集unity的相关技巧,会不断地更新内容。1)保存运行中的状态unity在运行状态时是不能够保存的。但在运行时编辑的时候,有时会发现比较
标签: scumpve服务器
本文链接地址:https://www.jiuchutong.com/biancheng/369391.html 转载请保留说明!友情链接: 武汉网站建设