跳转至

如何使用高级功能

Android设置

要使用Hercules的附加功能,必须在Android Gradle模块中启用prefab功能。

Android Studio项目的设置

  • 使用Android Gradle Plugin 4.1以下时

    • 在gradle.properties文件中添加如下内容。

      android.enablePrefab=true
      
  • 使用 Android Gradle 插件 4.1 及以上版本

    • 在 build.gradle 文件中的 android 块中添加如下内容。

      android {
          ...
          buildFeatures {
                  prefab true
          }
      }
      
  • 在你的模块级别 build.gradle 文件中,将以下库添加到 dependencies 部分:

    dependencies {
        implementation "com.com2us.android.hive:hive-hercules"
        implementation "com.com2us.android.gamesec:hercules:20250527" // 用于使用 Hercules 的附加功能
    

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并导入到项目中。
    可以选择并使用包含在模拟器或设备目标路径中的任何头文件。
    路径如下所示。
    `${PROJECT_ROOT_DIR}/Pods/Hercules/Hive_SDK_iOS_External_${HIVE_SDK_VERSION}/Hercules.xcframework/${SIMULATOR_OR_PHONEOS}/Hercules.framework/Headers/Hercules.h`
    

设置Unity

进行项目设置

  • 在Unity的预处理器标志中添加USE_HERCULES。

    • 玩家设置 → 其他设置 → 脚本编译 → 脚本定义符号

  • 检查是否允许‘unsafe’代码。

    • 玩家设置 → 其他设置 → 脚本编译 → 允许‘unsafe’代码

Unreal 设置

SDK Unreal Plugin 中包含的 Hercules 模块不支持 Hercules 扩展功能。
如果要在 Unreal 环境中使用 Hercules 扩展功能,请参考以下内容。

  • 移除 HiveSDK UE Plugin 中包含的 Hercules 模块
  • 设置为不使用已移除的 Hercules 模块

    hive::Configuration::setUseHercules(false);
    

  • 启用 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));