如何使用高级功能
Android的設定¶
要使用Hercules的附加功能,Android Gradle模块必须启用prefab功能。
Android Studio專案的設定¶
-
使用Android Gradle Plugin 4.1未滿時
-
在gradle.properties文件中添加如下內容。
-
-
使用 Android Gradle 插件 4.1 以上的情況下
-
在 build.gradle 文件中的 android 區塊中添加如下內容。
-
-
在您的模組級 build.gradle 文件中,將以下庫添加到
dependencies部分:
CMake / ndk-build 配置(用於 C/C++ 使用)¶
-
使用NDK r21或更高版本时
// 當使用 CMake 時 find_package(Hercules REQUIRED CONFIG) target_link_libraries( ... Hercules::Hercules ) // 使用 Android.mk 時 LOCAL_SHARED_LIBRARIES := Hercules include $(BUILD_SHARED_LIBRARY) ifneq ($(call ndk-major-at-least,21),true) $(call import-add-path,$(NDK_GRADLE_INJECTED_IMPORT_PATH)) endif $(call import-module, prefab/Hercules) -
當使用 NDK r21 或更低版本時
-
將 Hercules.h 文件單獨添加到您的項目中,並通過指定其路徑直接鏈接 .so 文件。
// 當使用 CMake target_link_libraries( ... ${CMAKE_CURRENT_SOURCE_DIR}/../build/intermediates/merged_native_libs/${CMAKE_BUILD_TYPE}/out/lib/${ANDROID_ABI}/libHercules.so ) // 當使用 Android.mk include $(CLEAR_VARS) LOCAL_MODULE := Hercules LOCAL_SRC_FILES := ../build/intermediates/merged_native_libs/release/out/lib/$(TARGET_ARCH_ABI)/libHercules.so include $(PREBUILT_SHARED_LIBRARY) LOCAL_SHARED_LIBRARIES := Hercules
-
iOS的設定¶
設定方法¶
- 通过CocoaPods安装到项目中的Hercules框架的路径下找到.h并导入到项目中。
可以选择并使用包含在模拟器或设备目标路径中的任何头文件。
路径如下:
设置Unity¶
進行專案設定¶
-
在Unity的預處理器標誌中添加USE_HERCULES。
- 玩家設置 → 其他設置 → 腳本編譯 → 腳本定義符號
-
检查是否允许‘unsafe’代码。
- 玩家设置 → 其他设置 → 脚本编译 → 允许‘unsafe’代码
Unreal 設定¶
SDK Unreal Plugin 中包含的 Hercules 模組不支援 Hercules 擴充功能。
若要在 Unreal 環境中使用 Hercules 擴充功能,請參考以下內容。
- 移除 HiveSDK UE Plugin 中包含的 Hercules 模組
-
啟用 HiveSDK UE Plugin 頂部的 HerculesPlugin(在 Build.cs 中依據使用的平台進行選擇)
if (Target.Platform == UnrealTargetPlatform.Android) PrivateDependencyModuleNames.AddRange(new string[] { "HerculesPlugin" }); if (Target.Platform == UnrealTargetPlatform.IOS) PrivateDependencyModuleNames.AddRange(new string[] { "HerculesPlugin" }); if (Target.Platform == UnrealTargetPlatform.Win64) PrivateDependencyModuleNames.AddRange(new string[] { "HerculesPlugin" }); -
若使用 HiveSDK UE Plugin 中包含的 HerculesPlugin,必須直接呼叫主要函式。
#include "HerculesPlugin.h" // 使用 HiveConsole 發放的 game_id 與 app_id 值 #if PLATFORM_WINDOWS CHerculesPlugin::Initialize(game_id, 0, app_id, app_version); #else CHerculesPlugin::Initialize(game_id, 0); #endif // 當 Hive Device ID 發放後進行設定 ::HerculesSetDeviceId(TCHAR_TO_UTF8(*deviceId)); // 使用者登入時設定 Player ID,重新登入時需再次設定 ::HerculesSetPlayerId(TCHAR_TO_UTF8(*playerId));

