Commit 0f3088bc authored by gaorui's avatar gaorui
Browse files

Initial commit

parents
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 System.Collections.Generic;
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 Dictionary<string, string> Extra { get; private set; }
public PlayerInfo()
{
Extra = new Dictionary<string, string>();
}
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:
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("关卡 1", 1);
playerInfo.AddExtra("血槽", 1000000.0);
playerInfo.AddExtra("技能释放", "冰火九重天");
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 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: e0aa63e0b228a4038a86c7b4b1f8cbbe
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: c8a121e643821454ca939212ae84039e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
/// <summary>
/// 原生日志记录器。
/// 该类直接调用 Android 或 iOS 的系统级日志API,可以绕过 Unity 的 Debug.Log 剥离机制。
/// 这意味着即使在 Release Build (非 Development Build) 中,日志也能被输出到 Logcat (Android) 或 Console (iOS)。
/// </summary>
public static class NativeLogger
{
#if UNITY_ANDROID && !UNITY_EDITOR
// 为 Android 平台缓存 Java Log Class,避免重复查找
private static readonly AndroidJavaClass _logClass = new AndroidJavaClass("android.util.Log");
#endif
/// <summary>
/// 打印一条信息级别的日志。
/// </summary>
/// <param name="tag">Logcat 中显示的标签</param>
/// <param name="message">日志内容</param>
public static void I(string tag, object message)
{
Debug.Log($"[{tag}] {message}");
#if UNITY_EDITOR
// 在编辑器中,我们仍然使用 Debug.Log,因为它功能更丰富(例如可以点击跳转)
Debug.Log($"[{tag}] {message}");
#elif UNITY_ANDROID
// 在 Android 设备上,直接调用 android.util.Log.i(tag, message)
_logClass.CallStatic<int>("i", tag, message.ToString());
#elif UNITY_IOS
// 在 iOS 设备上,调用自定义的 NSLog 封装
// (需要在 Xcode 项目中添加一个 .mm 文件来实现 _logToConsole)
// _logToConsole($"[I] [{tag}] {message}");
#endif
}
/// <summary>
/// 打印一条警告级别的日志。
/// </summary>
/// <param name="tag">Logcat 中显示的标签</param>
/// <param name="message">日志内容</param>
public static void W(string tag, object message)
{
#if UNITY_EDITOR
Debug.LogWarning($"[{tag}] {message}");
#elif UNITY_ANDROID
_logClass.CallStatic<int>("w", tag, message.ToString());
#elif UNITY_IOS
// _logToConsole($"[W] [{tag}] {message}");
#endif
}
/// <summary>
/// 打印一条错误级别的日志。
/// </summary>
/// <param name="tag">Logcat 中显示的标签</param>
/// <param name="message">日志内容</param>
public static void E(string tag, object message)
{
#if UNITY_EDITOR
Debug.LogError($"[{tag}] {message}");
#elif UNITY_ANDROID
_logClass.CallStatic<int>("e", tag, message.ToString());
#elif UNITY_IOS
// _logToConsole($"[E] [{tag}] {message}");
#endif
}
}
fileFormatVersion: 2
guid: 5505e8ead4d664b11bcd90828bfdc47f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 3494f939baf0a459d9d444c9e3f1809d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
BfgKS3WzGCqGBX6PJvlPvckHPWOL+wMba+sbFDeMcfUobwqt5wqyDzPEELejk0iGqTTQK/4sv2ouexn5a68SekHCeS4FV3QT9I3mooXqQI4b3SPvCX7+JZVNT0neW94oW605rR1zu/zZWcdxrZ8GGGbJMq6j2Wq4Os5nyJJlWoVy9Teli0sXe9G/7bZ9GPBKTZKJ4ChifZUf6fnYzb6XuBTjswGpkvDKXfx8kKjwNPWRj/+K0wWUlDSe+9xi3NPIB3Pq/5MQjFxZbe3H3hZbQIjLkWFELuz26aZvzr0to6MIrfKAAngOOaxY5lqKkqGsoXFptqiVV88nuKAwnytpazOB63W5UAGaeN9SoE5SFsLGzqo/+gS+oM0ZP+mEUi36vTVWJPrYf/dwApmTSVg98YIagzeGzfjliKUbMdya2DVRPgZVFnsjRuAg/C/qaVzr1eGFRfLhb7CbbjhytdBNRe0Oo10DbNIbqgltGZ0/0EM/4DWzjojE3axX/3xP1sZ9BA7K9sxH4KxeCPOIndUht3tnvgXYJchvUi1hyh4wMUhLUdZwvbKCJ8K+aQbFyJUToLlLaIkhtaFMcKLF2DrfxmPW+i7bmSbb43wFGSgKlO/LQK6cxlPG8I6plysz91D9QrUDSdHSrp/yxORn9nVTXyLfqktY/zpoucpa4dpkE5A=
\ No newline at end of file
fileFormatVersion: 2
guid: ff9cdea1ecf474317aae295623180958
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: f54d1bd14bd3ca042bd867b519fee8cc
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