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
{"androidStore":"GooglePlay"}
\ No newline at end of file
fileFormatVersion: 2
guid: a1f10cde32a534283847f0c5e0d94f5a
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 6a3c17335a5c045be9c16d3e915f6de9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 9fc0d4010bbf28b4594072e72b8655ab
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 01d236b657afd43c2a1c7f7ca5f7a2df
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: aff07f27f767b4b6db999011b1d7b436
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 8bb0cf470545c43f99a184adf60d566c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json;
using UnityEngine;
public class GameManager : MonoBehaviour
{
public void OnLoginBtnClicked()
{
NativeLogger.I("fastsdk_btn_unity", "clicked login");
//SdkPluginManager.CallSdkLogin();
HoolaiSdkManager.Login();
}
public void OnLogoutBtnClicked()
{
NativeLogger.I("fastsdk_btn_unity", "clicked logout");
HoolaiSdkManager.Logout();
}
public void OnEnterServerBtnClicked()
{
NativeLogger.I("fastsdk_btn_unity", "clicked EnterServer");
PlayerInfo playerInfo = new PlayerInfo();
playerInfo.RoleId = "1234567";
playerInfo.RoleName = "大鹏一日同风起";
playerInfo.RoleLevel = "999";
playerInfo.ZoneId = "1";
playerInfo.ZoneName = "傲视九重天";
playerInfo.ServerId = "1";
playerInfo.ServerName = "牛逼格拉斯";
playerInfo.Balance = "9999";
playerInfo.Vip = "99";
playerInfo.PartyName = "少林寺";
playerInfo.AppVersion = "1.0.1";
playerInfo.AppResVersion = "100";
playerInfo.ExtendAction = "无敌";
playerInfo.RoleCreateTime = "";
playerInfo.Phylum = "100";
playerInfo.ClassField = "滴滴滴答";
playerInfo.AddExtra("intKey", 55);
playerInfo.AddExtra("longLongKey", 66786658787676);
playerInfo.AddExtra("stringKey", "Hello111");
HoolaiSdkManager.SendEvent(EventType.EnterServer, playerInfo);
HoolaiSdkManager.SendEvent(EventType.CreateRole, playerInfo);
HoolaiSdkManager.SendEvent(EventType.LevelUp, playerInfo);
HoolaiSdkManager.SendEvent(EventType.CustomerAction, playerInfo);
}
public void OnPayBtnClicked()
{
NativeLogger.I("fastsdk_btn_unity", "clicked Pay");
// 1. 创建并填充对象
PayParams payParams = new PayParams
{
Amount = 100,
ItemId = "sword_101",
ItemName = "钻石",
CallbackInfo = "123456_8888_987654321",
NotifyUrl = "",
Count = 1,
Currency = "USD"
};
payParams.AddOptionalParameter("test", "daily_bonus");
payParams.AddOptionalParameter("player_id", "p-98765");
NativeLogger.I("fastsdk_btn_unity", $"clicked Exit jsonString: {payParams}");
HoolaiSdkManager.StartPay(payParams);
}
public void OnExitBtnClicked()
{
NativeLogger.I("fastsdk_btn_unity", "clicked Exit");
HoolaiSdkManager.ExitGame();
}
public void OnGetProductInfoBtnClicked()
{
NativeLogger.I("fastsdk_btn_unity", "clicked QueryGoodsInfo");
HoolaiSdkManager.QueryGoodsInfo();
}
// 新增方法:使用商品列表中的第一条数据进行支付
public void OnPayWithFirstGoodsBtnClicked()
{
NativeLogger.I("fastsdk_btn_unity", "clicked Pay With First Goods");
List<GoodsInfo> goodsList = PlatformCallback.GetCachedGoodsList();
if (goodsList == null || goodsList.Count == 0)
{
NativeLogger.I("fastsdk_btn_unity", "No goods list available. Please query goods info first.");
return;
}
// 使用第一条商品数据进行支付
GoodsInfo firstGoods = GetGoodsInfoByIndex(goodsList, 0);
if (firstGoods != null)
{
// 将GoodsInfo转换为PayParams
PayParams payParams = ConvertGoodsInfoToPayParams(firstGoods, 1);
if (payParams != null)
{
NativeLogger.I("fastsdk_btn_unity", $"Paying with goods: {firstGoods.itemName}");
HoolaiSdkManager.StartPay(payParams);
}
else
{
NativeLogger.I("fastsdk_btn_unity", "Failed to convert goods info to pay params");
}
}
else
{
NativeLogger.I("fastsdk_btn_unity", "No goods available at index 0");
}
}
// 添加方法用于根据索引获取单个商品信息
public static GoodsInfo GetGoodsInfoByIndex(List<GoodsInfo> goodsList, int index)
{
if (goodsList != null &&
index >= 0 &&
index < goodsList.Count)
{
return goodsList[index];
}
return null;
}
// 新增方法:使用指定索引的商品数据进行支付
public void OnPayWithSpecificGoodsBtnClicked(int goodsIndex)
{
NativeLogger.I("fastsdk_btn_unity", "clicked Pay With Random Goods");
// 获取缓存的商品列表
List<GoodsInfo> goodsList = PlatformCallback.GetCachedGoodsList();
if (goodsList == null || goodsList.Count == 0)
{
NativeLogger.I("fastsdk_btn_unity", "No goods list available. Please query goods info first.");
return;
}
System.Random random = new System.Random();
int randomIndex = random.Next(0, goodsList.Count);
GoodsInfo randomGoods = GetGoodsInfoByIndex(goodsList, randomIndex);
if (randomGoods != null)
{
// 将GoodsInfo转换为PayParams
PayParams payParams = ConvertGoodsInfoToPayParams(randomGoods, 1);
if (payParams != null)
{
NativeLogger.I("fastsdk_btn_unity", $"Paying with random goods: {randomGoods.itemName} at index {randomIndex}");
HoolaiSdkManager.StartPay(payParams);
}
else
{
NativeLogger.I("fastsdk_btn_unity", "Failed to convert goods info to pay params");
}
}
else
{
NativeLogger.I("fastsdk_btn_unity", "No goods available at random index");
}
}
// 添加方法用于将GoodsInfo转换为PayParams
public PayParams ConvertGoodsInfoToPayParams(GoodsInfo goodsInfo, int count = 1)
{
if (goodsInfo == null) return null;
System.Random random = new System.Random();
int randomIndex = random.Next(0, 100);
PayParams payParams = new PayParams
{
// 根据GoodsInfo的数据填充PayParams
Amount = int.TryParse(goodsInfo.itemPrice, out int price) ? price : 1,
ItemId = goodsInfo.itemId ?? "goods_info_6",
ItemName = goodsInfo.itemName ?? "宝石",
Count = count,
CallbackInfo = "Game_itemId_"+ randomIndex, // 游戏透传参数,必传
NotifyUrl = "", // 支付回调地址,默认使用客户端传递的
Currency = goodsInfo.currency ?? "USD"
};
return payParams;
}
public void OnCDKBtnClicked()
{
NativeLogger.I("fastsdk_btn_unity", "clicked CDKey");
HoolaiSdkManager.AccessParticipate(AccessActivityType.CD_KEY, "123456789");
}
public void OnShareBtnClicked()
{
NativeLogger.I("fastsdk_btn_unity", "clicked shareData");
HoolaiSdkManager.ShareData(1, 1, "test");
}
public void OnOpenServiceBtnClicked()
{
NativeLogger.I("fastsdk_btn_unity", "clicked openService");
HoolaiSdkManager.OpenService();
}
public void OnOpenAccountBtnClicked()
{
NativeLogger.I("fastsdk_btn_unity", "clicked openAccount");
HoolaiSdkManager.OpenAccountCenter();
}
}
fileFormatVersion: 2
guid: 789ca815eac2f468b94840a621f0b2e3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 68954ad80604b4901b195c36f9855ef1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LogViewer : MonoBehaviour
{
[Header("UI References")]
public Text logText;
public ScrollRect scrollRect;
[Header("Settings")]
public int maxLines = 1000;
public bool autoScroll = true;
public int lineHeight = 33;
private Queue<string> logQueue = new Queue<string>();
private bool isDirty = false;
void OnEnable()
{
Application.logMessageReceived += HandleLog;
}
void OnDisable()
{
Application.logMessageReceived -= HandleLog;
}
void HandleLog(string logString, string stackTrace, LogType type)
{
string time = System.DateTime.Now.ToString("HH:mm:ss");
string formattedLog = $"[{time}] {logString}";
logQueue.Enqueue(formattedLog);
isDirty = true;
}
void Update()
{
if (isDirty)
{
UpdateLogText();
isDirty = false;
}
}
void UpdateLogText()
{
if (logText == null || scrollRect == null)
{
Debug.LogWarning("LogViewer: 未绑定 logText 或 scrollRect");
return;
}
// 限制最大行数
while (logQueue.Count > maxLines)
{
logQueue.Dequeue();
}
// 拼接日志
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (var log in logQueue)
{
sb.AppendLine(log);
}
logText.text = sb.ToString();
// ✅ 动态计算 Text 实际高度
float preferredHeight = CalculateTextHeight(logText.text, logText);
RectTransform contentRect = logText.GetComponent<RectTransform>().parent as RectTransform;
if (contentRect != null)
{
contentRect.sizeDelta = new Vector2(contentRect.sizeDelta.x, Mathf.Max(preferredHeight, 500));
}
// 自动滚动到底部
if (autoScroll)
{
Canvas.ForceUpdateCanvases();
StartCoroutine(ScrollToBottom());
}
}
// ✅ 计算 Text 实际高度
float CalculateTextHeight(string text, Text textComponent)
{
if (string.IsNullOrEmpty(text))
return 0;
var style = textComponent.GetGenerationSettings(textComponent.rectTransform.rect.size);
var height = textComponent.cachedTextGenerator.GetPreferredHeight(text, style);
return height / textComponent.pixelsPerUnit;
}
System.Collections.IEnumerator ScrollToBottom()
{
yield return null; // 等待一帧
scrollRect.verticalNormalizedPosition = 0f;
}
public void ClearLogs()
{
logQueue.Clear();
if (logText != null)
{
logText.text = "";
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 679f079e039494f3d808228848364635
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 14422ca9d25954423a08b59088e07ddf
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 6bfefc7dc756641159ccbea6ca60d852
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
public class AndroidSdkInterface : MonoBehaviour
{
private static AndroidJavaClass _serviceClass;
private static AndroidJavaObject _serviceInstance;
// 缓存 AndroidJavaClass 和实例对象
private static AndroidJavaObject ServiceInstance
{
get
{
if (_serviceInstance == null)
{
try
{
_serviceClass = new AndroidJavaClass("com.unity.game.plugin.SdkManager");
_serviceInstance = _serviceClass.CallStatic<AndroidJavaObject>("getInstance");
}
catch (System.Exception ex)
{
NativeLogger.I("fastsdk_btn_unity", $"JavaManager 初始化失败: {ex.Message}");
}
}
return _serviceInstance;
}
}
/// <summary>
/// 调用 SdkManager 的 login 方法,确保在主线程执行,异常安全,资源释放
/// </summary>
public static void CallSdkLogin()
{
try
{
UnityMainThreadDispatcher.Instance.Enqueue(() => {
ServiceInstance?.Call("login");
NativeLogger.I("fastsdk_btn_unity", "call SdkManager login");
});
}
catch (System.Exception ex)
{
NativeLogger.I("fastsdk_btn_unity", $"调用 SdkManager.login 异常: {ex.Message}");
}
}
public static void CallSdkLogout()
{
try
{
UnityMainThreadDispatcher.Instance.Enqueue(() => {
ServiceInstance?.Call("logout");
NativeLogger.I("fastsdk_btn_unity", "call SdkManager logout");
});
}
catch (System.Exception ex)
{
NativeLogger.I("fastsdk_btn_unity", $"调用 SdkManager.logout 异常: {ex.Message}");
}
}
public static void CallSdkStartPay(string jsonStr)
{
try
{
UnityMainThreadDispatcher.Instance.Enqueue(() => {
ServiceInstance?.Call("startPay", jsonStr);
});
}
catch (System.Exception ex)
{
NativeLogger.I("fastsdk_btn_unity", $"调用 SdkManager.pay 异常: {ex.Message}");
}
}
public static void CallSdkExit()
{
try
{
UnityMainThreadDispatcher.Instance.Enqueue(() => {
ServiceInstance?.Call("exit");
NativeLogger.I("fastsdk_btn_unity", "call SdkManager exit");
});
}
catch (System.Exception ex)
{
NativeLogger.I("fastsdk_btn_unity", $"调用 SdkManager.exit 异常: {ex.Message}");
}
}
public static void CallSdkSendEvent(EventType type,string jsonStr)
{
try
{
UnityMainThreadDispatcher.Instance.Enqueue(() => {
int eventTypeCode = (int)type;
ServiceInstance?.Call("sendEvent", eventTypeCode, jsonStr);
NativeLogger.I("fastsdk_btn_unity", "call SdkManager sendEvent");
});
}
catch (System.Exception ex)
{
NativeLogger.I("fastsdk_btn_unity", $"调用 SdkManager.enterServer 异常: {ex.Message}");
}
}
public static void CallSdkQueryGoodsInfo()
{
try
{
UnityMainThreadDispatcher.Instance.Enqueue(() => {
ServiceInstance?.Call("queryGoodsInfo");
NativeLogger.I("fastsdk_btn_unity", "call SdkManager queryGoodsInfo");
});
}
catch (System.Exception ex)
{
NativeLogger.I("fastsdk_btn_unity", $"调用 SdkManager.CallSdkQueryGoodsInfo 异常: {ex.Message}");
}
}
public static void CallSdkCDKey(AccessActivityType accessType, string key)
{
try
{
UnityMainThreadDispatcher.Instance.Enqueue(() => {
int keyType = (int)accessType;
ServiceInstance?.Call("accessParticipate", keyType, key);
NativeLogger.I("fastsdk_btn_unity", "call SdkManager accessParticipate");
});
}
catch (System.Exception ex)
{
NativeLogger.I("fastsdk_btn_unity", $"调用 SdkManager.accessParticipate 异常: {ex.Message}");
}
}
public static void CallSdkOpenService()
{
try
{
UnityMainThreadDispatcher.Instance.Enqueue(() => {
ServiceInstance?.Call("openService");
NativeLogger.I("fastsdk_btn_unity", "call SdkManager openService");
});
}
catch (System.Exception ex)
{
NativeLogger.I("fastsdk_btn_unity", $"调用 SdkManager.openService 异常: {ex.Message}");
}
}
public static void CallSdkOpenAccount()
{
try
{
UnityMainThreadDispatcher.Instance.Enqueue(() => {
ServiceInstance?.Call("openAccount");
NativeLogger.I("fastsdk_btn_unity", "call SdkManager openAccount");
});
}
catch (System.Exception ex)
{
NativeLogger.I("fastsdk_btn_unity", $"调用 SdkManager.openAccount 异常: {ex.Message}");
}
}
public static void CallSdkShareData(int type,int childType,string jsonStr)
{
try
{
UnityMainThreadDispatcher.Instance.Enqueue(() => {
ServiceInstance?.Call("shareData", type,childType,jsonStr);
NativeLogger.I("fastsdk_btn_unity", "call SdkManager shareData");
});
}
catch (System.Exception ex)
{
NativeLogger.I("fastsdk_btn_unity", $"调用 SdkManager.shareData 异常: {ex.Message}");
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: dd96c961b73214cf0a9d7857e9433417
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
#if UNITY_IOS && !UNITY_EDITOR
using UnityEngine;
using System.Runtime.InteropServices;
using System;
public class IosSdkInterface
{
// ================== DllImport 声明 ==================
// 基础功能
[DllImport("__Internal")] private static extern void _LoginSdk();
[DllImport("__Internal")] private static extern void _LogoutSdk();
// 支付功能
[DllImport("__Internal")] private static extern void _QueryGoodsInfo();
[DllImport("__Internal")] private static extern void _StartPay(string jsonInfo);
// 分享功能
[DllImport("__Internal")] private static extern void _StartShare(int shareType, string title, string content, string url);
// 数据上报
[DllImport("__Internal")] private static extern void _ReportUserInfoFull(int eventType, string jsonInfo);
// 活动功能
[DllImport("__Internal")] private static extern void _AccessParticipate(int activityType, string activityData);
// 其他功能
[DllImport("__Internal")] private static extern void _OpenAccountCenter();
[DllImport("__Internal")] private static extern void _OpenService();
// ========= C# 封装调用 ============
public static void LoginSdk()
{
_LoginSdk();
}
public static void LogoutSdk()
{
_LogoutSdk();
}
public static void QueryGoodsInfo()
{
_QueryGoodsInfo();
}
public static void StartPay(string json)
{
_StartPay(json);
}
public static void StartShare(int shareType, string title, string imagePath, string url)
{
_StartShare(shareType, title, imagePath, url);
}
public static void ReportUserInfoFull(EventType eventType, string jsonStr)
{
int eventTypeCode = (int)eventType;
_ReportUserInfoFull(eventTypeCode, jsonStr);
}
public static void AccessParticipate(AccessActivityType accessType, string cdKey = "")
{
int activityType = (int)accessType;
_AccessParticipate(activityType, cdKey);
}
public static void OpenAccountCenter()
{
_OpenAccountCenter();
}
public static void OpenService()
{
_OpenService();
}
}
#endif // UNITY_IOS && !UNITY_EDITOR
\ No newline at end of file
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