TYPESDK Mobile Game Aggregation SDK Client Design Ideas and Architecture Part 4: Partial Structure Design and Ideas of Unity Development Platform

In the previous article "iOS Platform Interface Design and Ideas", we expounded the interface structure and ideas of the ios platform. Here we will explain the interface structure and ideas under the unity platform.

       The unity platform is a development platform, and our program code is stacked under this ide. The unity side does not need to think too much about how the underlying mechanisms on different operating platforms (Android/iOS) are implemented. Unity itself has already done corresponding processing. We only need to know what our current operating platform is, and then Make relevant platform differences

       2. Adaptable to different operating platforms (Android/iOS)

Just call the interface.

       Because the unity platform is a development platform, we deal with the differences in game channels on the operating platform (Android/iOS), so some clients of unity don’t need to care much about channel differentiation.

1. As usual, let’s first look at the requirements we want to design

       1. Easy to call

2. The designed modules

       1. The only interface module for external calls

       2. Interface realization for different operating platforms (Android/ios/windows)

3. Specific details

With the structure shown in the figure, we have mainly implemented the following functions in untiy

1. All interface calls of the game client are through the typesdk class

2. Typesdk will call the implementation logic of the interface on different platforms according to the current operating platform

3. The implementation logic on these different platforms will call the interface of the native environment across platforms

4. Send all information data in the native environment to the typenotify class

5. The typenotify class forwards relevant data to the typesdk class

6. Typesdk will process the data and feed it back to the game client

       In the typeSDK class called by the game, we need the following interface definition

       Login interface public void InitSDK()

       Get the sdk user data cached on the native platform public U3DTypeBaseData GetUserData()

       Get the channel configuration information cached in the native platform public U3DTypeBaseData GetPlatformData()

       Login interface public void Login()

       Logout interface public void Logout()

       Payment interface public string PayItem(U3DTypeBaseData _in_pay)

       Submit user information interface public void UpdatePlayerInfo()

       Big exit game interface public void ExitGame()

       Execute the extended function interface public void DoAnyFunction(string _func_name, U3DTypeBaseData _in_data) according to the function name

       We can use class inheritance to implement calling different interfaces in different operating environments

       In c#, we can use the macro definition to achieve this function. For specific examples, please refer to the following code examples


Click ( here ) to collapse or open

  1. public class TypeSDK :
  2.        #if UNITY_ANDROID
  3.            Hello_Type_Common
  4.        #elif UNITY_IOS
  5.              Bonjour_Type_Common_IOS
  6.        #elif UNITY_STANDALONE_WIN
  7.           Bonjour_Type_Common_Win
  8.        #else
  9.          Bonjour_Type_Common_Win
  10.        #endif
  11.        {
  12.        }


       用来响应原生平台的数据传递类typenotify

       因为unity本身已经对跨平台的数据接收做了很好的封装,只需要知道我们的脚本对象名字,其他平台就可以直接执行这个脚本内的函数,所以我们在设计聚合sdk时,做了如下的一些响应函数的定义


点击(此处)折叠或打开

  1. //登录成功响应
  2.        public void NotifyLogin(string _in_data)
  3.        //登出响应
  4.        public void NotifyLogout(string _in_data)
  5.        //支付结果响应
  6.        public void NotifyPayResult(string _in_data)
  7.        //初始化完毕响应
  8.        public void NotifyInitFinish(string _in_data)
  9.        //拓展函数回调响应
  10.        void NotifyExtraFunction(string _json_string)


       如此一来,整个流程就成型了一个完整的体系。从接口的调用,到跨平台数据的接收都有了相关的设计。

这个项目已开源,大家有兴趣可以自己研究或者参照项目编写自己的聚合SDK
项目地址:https://code.csdn.net/typesdk_code
项目地址:https://github.com/typesdk

Guess you like

Origin blog.csdn.net/kasimshi/article/details/54693230