目录

服务器

```

  void maini(){

    printf("hello world");

  }

```

  1. 最小资产库创建

  2. entity配置

  3. 实体的Python实现

  4. 创建第一个空间Space

  5. 让entity进入空间Space

客户端(unity)

  1. 生成客户端SDK

  2. 实现Client部分验证

验证测试

====================================正文=====================================

服务器

  1. 最小资产库创建

    • 运行文件“new_assets.bat”,生成最小资产库“server_assets”,更名为“first_assets"
  2. entity配置

    • entity声明
      ```
      void main(){
        printf("shit");
      }
      ```

      hasClient 表示这个实体有客户端

    • entity配置
      • 新建def配置文件,配置文件名称规定为(实体名称.def)
      • 添加方法声明
        <root>
        <!-- Cell上的方法 -->
        <CellMethods>
        <Broadcast>
        <!--Exposed 表示此方法暴漏给客户端调用-->
        <Exposed/>
        <Arg> UNICODE </Arg>
        </Broadcast>
        </CellMethods> <!-- 客户端上的方法 -->
        <ClientrMethods>
        <onEnter>
        </onEnter> <SendMsgToServer>
        <Arg> UNICODE </Arg>
        </SendMsgToServer>
        </ClientrMethods>
        </root>

        {项目资产库}\scripts\entity_defs\PlayerEntity.def

  3. entity的 Python实现

    • 名称规则(实体名.py)
    • base文件夹下的部分
      # -*- coding utf-8 -*-
      import KBEngine
      from KBEDebug import * class FirstPlayer(KBEngine.Proxy):
      #base部分的实现
      def __init__(self):
      KBEngine.Entity.__init__(self)

      {资产库}\base\FirstPlayer.py

    • cell文件夹下的部分
      # -*- coding: utf-8 -*-
      import KBEngine
      from KBEDebug import * class FirstEntity(KBEngine.Entity):
      def __init__(self):
      KBEngine.Entity.__init__(self)
      #这里是FirstEntity的cell,当其Cell创建完毕时,通知其自身的客户端的onEnter函数
      self.client.onEnter() def SendMsgToServer(self, callerID, content):
      INFO_MSG("FirstPlay-SendMsgToServer")
      #广播给所有客户端
      self.allClient.Broadcast(str(self.id) + ":" + content)

      {资产库}\scripts\cell\FirstPlayer.py

    • entity何时创建?
      教程采用:使用账户入口对第一个enetity进行创建,只添加一句:<accountEntityScriptType> FirstEntity </accountEntityScriptType>
          <dbmgr>
      <account_system>
      <accountEntityScriptType> PlayerEntity </accountEntityScriptType>

      {项目资产库}/res/server/kbengine.xml

  4. Space配置

    • entity声明和def文件配置

      <root>
      <PlayerEntity hasClient="true"></PlayerEntity>
      <!-- 添加下面这行 -->
      <WorldSpace></WorldSpace>
      </root>

      {资产库}\scripts\entities.xml

    • <root>
      <!-- BaseApp上的远程方法 -->
      <BaseMethods>
      </BaseMethods>
      <!-- CellApp上的远程方法 -->
      <CellMethods>
      </CellMethods>
      </root>

      {资产库}\scripts\entity_defs\WorldSpace.def

  5. Space的 Python实现

    • 名称规则(空间名.py)
    • base部分
      # -*- coding-utf8 -*-
      import KBEngine
      from KBEDebug import * class WorldSpace(KBEngine.Space):
      # WorldSpace的base部分,这是一个实体,并不是Space本身,Space位于内存中,我们通过这个实体关联并控制Space
      def __init__(self):
      KBEngine.Space.__init__(self)
      # 在全局变量globaldata字典中保存Space
      KBEngine.globalData["WorldSpace"] = self

      {资产库}\scripts\base\WorldSpace.py

    • cell部分
      import KBEngine
      
      class WorldSpace(KBEngine.Space):
      def __init__(self):
      KBEngine.Space.__init__(self)
      pass

      {资产库}\scripts\cell\WoldSpace.py

    • space何时创建
      教程采用:Baseapp就绪时创建Space空间,在baseapp就绪后加载空间space
      def onBaseAppReady(isBootstrap):
      """
      KBEngine method.
      baseapp已经准备好了
      @param isBootstrap: 是否为第一个启动的baseapp
      @type isBootstrap: BOOL
      """
      INFO_MSG('onBaseAppReady: isBootstrap=%s, appID=%s, bootstrapGroupIndex=%s, bootstrapGlobalIndex=%s' % \
      (isBootstrap, os.getenv("KBE_COMPONENTID"), os.getenv("KBE_BOOTIDX_GROUP"), os.getenv("KBE_BOOTIDX_GLOBAL")))
      #添加此句以使得space在baseapp启动后就加载进来
      KBEngine.createEntityLocally("WorldSpace", {})

      {资产库}\scripts\base\kbemain.py

  6. 验证空间Space是否加载成功

    1. 开始验证:打开guiconsole(......\kbengine-2.4.\kbe\tools\server\guiconsole)选择baseapp,然后选中debug便签,输入Python语句:KBEngine.entities.items(),Ctrl+Enter执行语句,输出结果如下:
    2. 错误警告

      我们可能需要设置一下用户账户和密码,位置在{资产库}res\server\kbengine.xml: root -> dbmgr -> databaseInterfaces -> default -> auth

    3. 注意2(9个窗口一个都不能少)
      折叠的代码中所有的实例名称(PlayerEntity 或者 FIrstPlayer 选一个统一)都需要统一,我上面没有再修改,吐槽博客园的编辑器   (¬︿¬☆)

  7. 让entity进入空间Space

    1. 我们再次打开之前的文件({项目资产库}/scripts/base/PlayerEntity.py)
    2. 添加一个回调和函数,onClientEnabled ,因为我们的PlayerEntity继承了Proxy,所以当客户端可用时,这个函数会被执行,此时我们选择让entity进入空间

客户端(unity)

  1. 生成客户端SDK

    1. 配置SDK生成工具
  2. 实现Client部分验证

验证测试

最新文章

  1. MongoDB数据实体中的ObjectId序列化成json的一个小坑
  2. shell简单用法笔记(一)
  3. Dijkstra算法初步 - 迷宫问题
  4. Google-glog 日志库使用手记
  5. RelativeLayout相对布局属性
  6. sql常识-LEFT JOIN
  7. Orleans-Hello World
  8. 用MVC+EF快速弄出一个CRUD
  9. LeetCode OJ 62. Unique Paths
  10. HTML5的优点与缺点?
  11. VsCode源码分析之布局
  12. Web服务端性能提升实践
  13. Sprint2的每日更新
  14. Ruby环境搭建
  15. 跟着百度学PHP[14]-PDO的错误处理模式&amp;PDO执行SQL
  16. TimeQuest学习总结
  17. RESTful API架构和oauth2.0认证机制(概念版)
  18. Python函数(十一)-生成器
  19. JSONModel 简单例子
  20. 查看python 3中的内置函数列表,以及函数功能描述

热门文章

  1. bzoj 3751: [NOIP2014]解方程【数学】
  2. hdu 1348【凸包模板】
  3. 小程序 获取地理位置-- wx.getLocation
  4. [App Store Connect帮助]七、在 App Store 上发行(2.4)设定价格与销售范围:安排价格调整
  5. spring进行事务管理
  6. hdu 2063 过山车 (最大匹配 匈牙利算法模板)
  7. poj 1511 Invitation Cards spfa 邻接矩阵
  8. [hdu1695] GCD【莫比乌斯反演】
  9. 使用dubbox开发REST应用
  10. Python的数据类型:list和tuple