Commit c141e353 authored by gaorui's avatar gaorui
Browse files

Merge branch 'feat-dev3' into 'main'

Feat dev3

See merge request unity-cross/UnityDemo!1
parents 2ce8d1c7 b31b4ba9
fileFormatVersion: 2
guid: e4b23c671991d4a08a765cd49bdd64d0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UnityMainThreadDispatcher : MonoBehaviour
{
private static readonly Queue<Action> _executionQueue = new Queue<Action>();
private static UnityMainThreadDispatcher _instance;
public static UnityMainThreadDispatcher Instance
{
get
{
if (_instance == null)
{
var go = new GameObject("MainThreadDispatcher");
_instance = go.AddComponent<UnityMainThreadDispatcher>();
DontDestroyOnLoad(go);
}
return _instance;
}
}
public void Enqueue(Action action)
{
lock (_executionQueue)
{
_executionQueue.Enqueue(action);
}
}
void Update()
{
lock (_executionQueue)
{
while (_executionQueue.Count > 0)
{
_executionQueue.Dequeue()?.Invoke();
}
}
}
}
fileFormatVersion: 2
guid: 043e2ec79b0d243c5a7bbf97aef950ae
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: b2dbb909333c14c8d8775786c409dffc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using Newtonsoft.Json;
using UnityEngine;
public static class HoolaiSdkManager
{
// ==================== 登录 ====================
public static void Login()
{
#if UNITY_ANDROID && !UNITY_EDITOR
AndroidSdkInterface.CallSdkLogin();
#elif UNITY_IOS && !UNITY_EDITOR
IosSdkInterface.LoginSdk();
#else
Debug.Log("【UnifiedSdkManager】模拟调用:登录");
#endif
}
// ==================== 登出 ====================
public static void Logout()
{
#if UNITY_ANDROID && !UNITY_EDITOR
AndroidSdkInterface.CallSdkLogout();
#elif UNITY_IOS && !UNITY_EDITOR
IosSdkInterface.LogoutSdk();
#else
Debug.Log("【UnifiedSdkManager】模拟调用:登出");
#endif
}
// ==================== 支付 ====================
public static void StartPay(PayParams payParams)
{
string jsonStr = JsonConvert.SerializeObject(payParams);
#if UNITY_ANDROID && !UNITY_EDITOR
AndroidSdkInterface.CallSdkStartPay(jsonStr);
#elif UNITY_IOS && !UNITY_EDITOR
IosSdkInterface.StartPay(jsonStr);
#else
Debug.Log($"【UnifiedSdkManager】模拟调用:支付,参数={jsonStr}");
#endif
}
// ==================== 数据上报 ====================
public static void SendEvent(EventType eventType, PlayerInfo playerInfo)
{
string jsonStr = JsonConvert.SerializeObject(playerInfo);
#if UNITY_ANDROID && !UNITY_EDITOR
AndroidSdkInterface.CallSdkSendEvent(eventType, jsonStr);
#elif UNITY_IOS && !UNITY_EDITOR
IosSdkInterface.ReportUserInfoFull(eventType, jsonStr);
#else
Debug.Log($"【UnifiedSdkManager】模拟调用:数据上报,类型={eventType},参数={jsonStr}");
#endif
}
// ==================== 查询商品信息 ====================
public static void QueryGoodsInfo()
{
#if UNITY_ANDROID && !UNITY_EDITOR
AndroidSdkInterface.CallSdkQueryGoodsInfo();
#elif UNITY_IOS && !UNITY_EDITOR
IosSdkInterface.QueryGoodsInfo();
#else
Debug.Log("【UnifiedSdkManager】模拟调用:查询商品信息");
#endif
}
// ==================== CDKey 活动 ====================
public static void AccessParticipate(AccessActivityType accessType, string cdKey)
{
#if UNITY_ANDROID && !UNITY_EDITOR
AndroidSdkInterface.CallSdkCDKey(accessType,cdKey);
#elif UNITY_IOS && !UNITY_EDITOR
IosSdkInterface.AccessParticipate(accessType, cdKey);
#else
Debug.Log($"【UnifiedSdkManager】模拟调用:参与活动,CDKey={cdKey}");
#endif
}
// ==================== 打开客服 ====================
public static void OpenService()
{
#if UNITY_ANDROID && !UNITY_EDITOR
AndroidSdkInterface.CallSdkOpenService();
#elif UNITY_IOS && !UNITY_EDITOR
IosSdkInterface.OpenService();
#else
Debug.Log("【UnifiedSdkManager】模拟调用:打开客服");
#endif
}
// ==================== 打开账号中心 ====================
public static void OpenAccountCenter()
{
#if UNITY_ANDROID && !UNITY_EDITOR
AndroidSdkInterface.CallSdkOpenAccount();
#elif UNITY_IOS && !UNITY_EDITOR
IosSdkInterface.OpenAccountCenter();
#else
Debug.Log("【UnifiedSdkManager】模拟调用:打开账号中心");
#endif
}
// ==================== 分享 ====================
public static void ShareData(int platform, int childType, string jsonStr)
{
#if UNITY_ANDROID && !UNITY_EDITOR
AndroidSdkInterface.CallSdkShareData(platform, childType, jsonStr);
#elif UNITY_IOS && !UNITY_EDITOR
// iOS 分享参数解析(可根据需要扩展)
Debug.Log("【UnifiedSdkManager】iOS 分享暂未实现完整解析");
IosSdkInterface.StartShare(platform, "Title", "Content", "https://example.com");
#else
Debug.Log($"【UnifiedSdkManager】模拟调用:分享,平台={platform},子类型={childType}");
#endif
}
// ==================== 退出游戏 ====================
public static void ExitGame()
{
#if UNITY_ANDROID && !UNITY_EDITOR
AndroidSdkInterface.CallSdkExit();
#elif UNITY_IOS && !UNITY_EDITOR
// iOS 通常不直接退出应用
Debug.Log("【UnifiedSdkManager】iOS 不支持直接退出应用");
#else
Debug.Log("【UnifiedSdkManager】模拟调用:退出游戏");
#endif
}
}
fileFormatVersion: 2
guid: ab62b7684d21a4ecc905ad6fd5c276a3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections.Generic;
using Newtonsoft.Json;
using UnityEngine;
[System.Serializable]
public class InitResult
{
public string channel;
public int gameId;
public int channelId;
}
[System.Serializable]
public class LoginResult
{
public long uid;
public string accessToken;
public string channel;
public string channelUid; // 已弃用,默认为0
public string serverArea;
public string extendInfo; // 扩展参数转 JSON 字符串再传过来
}
[System.Serializable]
public class GoodsInfo
{
public string currency;
public string itemId;
public string itemName;
public string itemCount;
public string itemPrice;
public string showTag;
public string region;//仅 iOS返回
public string symbol;//仅 iOS返回
}
public class PlatformCallback : MonoBehaviour
{
// 添加字段用于保存商品列表
private List<GoodsInfo> _goodsLists;
// 单例实现,确保只有一个接收器实例
public static PlatformCallback Instance { get; private set; }
void Awake()
{
// 单例模式实现
if (Instance != null && Instance != this)
{
NativeLogger.I("fastsdk_unity_result", "[ ] Destroying duplicate instance");
Destroy(gameObject);
return;
}
Instance = this;
// 确保接收器在场景切换中不被销毁
DontDestroyOnLoad(gameObject);
// 确保游戏对象名称与 Android 调用匹配
gameObject.name = "PlatformCallback";
NativeLogger.I("fastsdk_unity_result", "[PlatformCallback] Initialized with GameObject name: " + gameObject.name);
}
public void onInitSuccess(string jsonStr)
{
NativeLogger.I("fastsdk_unity_result", "[AndroidBrigsCall] onInitSuccess called with result: " + jsonStr);
InitResult result = JsonConvert.DeserializeObject<InitResult>(jsonStr);
if (result != null)
{
NativeLogger.I("fastsdk_unity_result", "反序列化成功!");
NativeLogger.I("fastsdk_unity_result", "Channel: " + result.channel);
NativeLogger.I("fastsdk_unity_result", "Game ID: " + result.gameId);
NativeLogger.I("fastsdk_unity_result", "Channel ID: " + result.channelId);
}
}
public void onInitFailed(string reason)
{
NativeLogger.I("fastsdk_unity_result", "[Unity] onInitFailed called with reason: " + reason);
}
//自定义退出界面
public void onCustomExit()
{
NativeLogger.I("fastsdk_unity_result", "[Unity] onCustomExit called");
}
//预留
public void onUpdate(string data)
{
NativeLogger.I("fastsdk_unity_result", "[Unity] onUpdate called with data: " + data);
}
//登录成功
public void onLoginSuccess(string jsonStr)
{
NativeLogger.I("fastsdk_unity_result", "[Unity] onLoginSuccess called with result: " + jsonStr);
//判断 null 或空字符串判断空白字符串(包括空格、制表符等)
if (string.IsNullOrEmpty(jsonStr) || string.IsNullOrWhiteSpace(jsonStr))
{
NativeLogger.I("fastsdk_unity_result", "[Unity] Android returned empty or invalid string");
return;
}
LoginResult loginResult = JsonConvert.DeserializeObject<LoginResult>(jsonStr);
if (loginResult.uid != 0) {
// 示例:如果接收到特定消息,切换到另一个场景
NativeLogger.I("fastsdk_unity_result", $"[Unity] Login successful, uid:{loginResult.uid} channel:{loginResult.channel} channelUid:{loginResult.channelUid} accessToken:{loginResult.accessToken}");
}
}
public void onRefreshUser(string jsonStr)
{
NativeLogger.I("fastsdk_unity_result", "[Unity] onRefreshUser called with result: " + jsonStr);
//判断 null 或空字符串判断空白字符串(包括空格、制表符等)
if (string.IsNullOrEmpty(jsonStr) || string.IsNullOrWhiteSpace(jsonStr))
{
NativeLogger.I("fastsdk_unity_result", "[Unity] Android returned empty or invalid string");
return;
}
LoginResult loginResult = JsonConvert.DeserializeObject<LoginResult>(jsonStr);
if (loginResult.uid != 0)
{
// 示例:如果接收到特定消息,切换到另一个场景
NativeLogger.I("fastsdk_unity_result", $"[Unity] onRefreshUser Login successful, uid:{loginResult.uid} channel:{loginResult.channel} channelUid:{loginResult.channelUid} accessToken:{loginResult.accessToken}");
}
}
public void onLoginFailed(string reason)
{
NativeLogger.I("fastsdk_unity_result", "[Unity] onLoginFailed called with reason: " + reason);
}
public void onLogout(string message)
{
NativeLogger.I("fastsdk_unity_result", "[Unity] onLogout called with message: " + message);
}
public void onPayGoodsList(string jsonStr)
{
NativeLogger.I("fastsdk_unity_result", "[Unity] onPayGoodsList called with message: " + jsonStr);
//goodsList = JsonConvert.DeserializeObject<List<GoodsInfo>(jsonStr);
// 方法一:直接解析为List<GoodsInfo>
_goodsLists = JsonConvert.DeserializeObject<List<GoodsInfo>>(jsonStr);
if (_goodsLists != null && _goodsLists.Count!=0)
{
NativeLogger.I("fastsdk_unity_result", $"[Unity] onPayGoodsList: {_goodsLists}");
}
}
// 添加方法用于获取保存的商品列表
public static List<GoodsInfo> GetCachedGoodsList()
{
return Instance != null ? Instance._goodsLists : null;
}
public void onPaySuccess(string jsonStr)
{
NativeLogger.I("fastsdk_unity_result", $"[Unity] onPaySuccess called {jsonStr}");
}
public void onPayFailed(string reason)
{
NativeLogger.I("fastsdk_unity_result", "[Unity] onPayFailed called with reason: " + reason);
}
//分享,无特殊处理可不实现
public void onShareSuccess(string jsonStr)
{
NativeLogger.I("fastsdk_unity_result", $"[Unity] onShareSuccess called {jsonStr}");
}
public void onShareFailed(string jsonStr)
{
NativeLogger.I("fastsdk_unity_result", $"[Unity] onShareFailed called {jsonStr}");
}
}
fileFormatVersion: 2
guid: 1339b90d384704209afa5c373e6c0035
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 7cc20c96e2f4a4a80ad5d2e39d1dde68
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

public enum AccessActivityType
{
CD_KEY = 1 //CD_KEY
}
fileFormatVersion: 2
guid: 3e15ad2b0dd7a44fdb24799ebfb8054a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
public enum EventType
{
EnterServer = 1, //进服
LevelUp = 2, //升级
CreateRole = 3, //创角
CustomerAction = 4 //自定义报送
}
fileFormatVersion: 2
guid: dcc183b5758dd4b8caf1e9e6c43c4364
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections.Generic;
using Newtonsoft.Json;
public class PayParams
{
[JsonProperty("amount")]
public int Amount { get; set; }
[JsonProperty("itemId")]
public string ItemId { get; set; }
[JsonProperty("itemName")]
public string ItemName { get; set; }
[JsonProperty("count")]
public int Count { get; set; }
[JsonProperty("callbackInfo")]
public string CallbackInfo { get; set; }
[JsonProperty("notifyUrl")]
public string NotifyUrl { get; set; }
[JsonProperty("currency")]
public string Currency { get; set; }
[JsonProperty("opt")]
public Dictionary<string, string> Opt { get; private set; }
public PayParams()
{
Opt = new Dictionary<string, string>();
}
public void AddOptionalParameter(string key, string value)
{
Opt[key] = value;
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: bfe2d353691bb483e875696578a9b4b9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using Newtonsoft.Json;
public class PlayerInfo
{
[JsonProperty("roleId")]
public string RoleId { get; set; }
[JsonProperty("roleName")]
public string RoleName { get; set; }
[JsonProperty("roleLevel")]
public string RoleLevel { get; set; }
[JsonProperty("zoneId")]
public string ZoneId { get; set; }
[JsonProperty("zoneName")]
public string ZoneName { get; set; }
[JsonProperty("serverId")]
public string ServerId { get; set; }
[JsonProperty("serverName")]
public string ServerName { get; set; }
[JsonProperty("balance")]
public string Balance { get; set; }
[JsonProperty("vip")]
public string Vip { get; set; }
[JsonProperty("partyName")]
public string PartyName { get; set; }
[JsonProperty("appVersion")]
public string AppVersion { get; set; }
[JsonProperty("appResVersion")]
public string AppResVersion { get; set; }
[JsonProperty("extendAction")]
public string ExtendAction { get; set; }
[JsonProperty("roleCreateTime")]
public string RoleCreateTime { get; set; }
[JsonProperty("phylum")]
public string Phylum { get; set; }
[JsonProperty("classField")]
public string ClassField { get; set; }
[JsonProperty("extra")]
public string Extra { get; private set; }
public void AddExtra(string key, int value)
{
if (string.IsNullOrEmpty(key)) return;
Extra += key+":"+CrateValue(value)+",";
}
public void AddExtra(string key, double value)
{
if (string.IsNullOrEmpty(key)) return;
Extra += key + ":" + CrateValue(value) + ",";
}
public void AddExtra(string key, string value)
{
if (string.IsNullOrEmpty(key) || value == null) return;
Extra += key + ":" + CrateValue(value) + ",";
}
private string CrateValue(int val)
{
return "INT|||" + val;
}
private string CrateValue(double val)
{
return "DOUBLE|||" + val;
}
private string CrateValue(string val)
{
return val;
}
}
fileFormatVersion: 2
guid: 577112532e4464953b5b9594c275ae11
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
{
"name": "NewAssembly",
"rootNamespace": "",
"references": [
"Unity.TextMeshPro"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [
{
"name": "com.unity.nuget.newtonsoft-json",
"expression": "",
"define": ""
}
],
"noEngineReferences": false
}
\ No newline at end of file
fileFormatVersion: 2
guid: a00106c589ef74c21903b62a64daac6e
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: ae9e5ac1843c944138202b504167711e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment