Commit 29fc4445 authored by gaorui's avatar gaorui
Browse files

feat(config): 新增 dialog 弹窗,新增多个 Android 支付档位

parent d8b0a35f
No preview for this file type
This diff is collapsed.
using UnityEngine;
using UnityEngine.UI;
public class ExitConfirmationDialog : MonoBehaviour
{
public GameObject dialog; // Reference to the dialog panel
public Button confirmButton;
public Button cancelButton;
void Start()
{
// 初始化时不强制设置 dialog 状态,保持与 Inspector 设置一致
// 如果 dialog 未分配,则默认隐藏
if (dialog != null)
{
// 只在 dialog 已分配的情况下进行初始化
}
else
{
dialog = gameObject; // 默认使用自身 GameObject
}
// Set up button listeners
confirmButton.onClick.AddListener(OnConfirmExit);
cancelButton.onClick.AddListener(OnCancelExit);
// 确保初始隐藏
HideDialog();
}
// Method to show the dialog
public void ShowDialog()
{
try
{
UnityMainThreadDispatcher.Instance.Enqueue(() => {
if (dialog != null)
{
NativeLogger.I("[Unity Dialog]", $"SetActive 1 {dialog.activeSelf}");
dialog.SetActive(true);
NativeLogger.I("[Unity Dialog]", $"SetActive 2 {dialog.activeSelf}");
}
else
{
NativeLogger.I("[Unity Dialog]", "Dialog is null");
}
});
}
catch (System.Exception ex)
{
NativeLogger.I("[Unity Dialog]", $"SetActive true {ex.Message}");
}
}
// Method to hide the dialog
public void HideDialog()
{
try
{
UnityMainThreadDispatcher.Instance.Enqueue(() => {
if (dialog != null)
{
dialog.SetActive(false);
}
});
}
catch (System.Exception ex)
{
NativeLogger.I("[Unity Dialog]", $"SetActive false {ex.Message}");
}
}
// Method to handle confirm exit
public void OnConfirmExit()
{
Debug.Log("Exiting the application...");
// Exit the application
Application.Quit();
}
// Method to handle cancel exit
public void OnCancelExit()
{
Debug.Log("Exit canceled.");
// Hide the dialog
dialog.SetActive(false);
}
}
fileFormatVersion: 2
guid: e61a69e5f636041048817aea3af86d3f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -6,22 +6,43 @@ using UnityEngine;
public class GameManager : MonoBehaviour
{
public ExitConfirmationDialog exitDialog; // 在 Inspector 中设置
private bool isExiting = false; // 防止重复调用退出
private void Awake()
{
// 触发单例构造,内部会调用 PlatformCallback.SetListener(this)
var _ = HoolaiListener.Instance;
HoolaiListener.Instance.SetExitConfirmationDialog(exitDialog);
}
//Android 需监听返回事件,如果当前场景没有返回拦截了需调用 SDK 的退出接口
//Android 需监听返回事件,如果当前场景没有游戏业务处理了(比如拦截返回上一个场景,此时无需调用,但返回到顶级场景后继续返回需处理此逻辑)需调用 SDK 的退出接口
void Update()
{
if (Input.GetKey(KeyCode.Escape))
{
NativeLogger.I("Game_Unity_Log", "clicked Exit");
HoolaiSdkManager.ExitGame();
HandleExit();
}
}
private void HandleExit()
{
// 防止重复调用
if (isExiting) return;
isExiting = true;
NativeLogger.I("Game_Unity_Log", "clicked Exit");
HoolaiSdkManager.ExitGame();
// 延迟重置标志位,防止短时间内重复触发
Invoke("ResetExitFlag", 0.5f);
}
private void ResetExitFlag()
{
isExiting = false;
}
public void OnLoginBtnClicked()
{
......@@ -73,20 +94,87 @@ public class GameManager : MonoBehaviour
}
public void OnPayBtnClicked()
public void OnPayBtnClicked1()
{
NativeLogger.I("Game_Unity_Log", "clicked Pay");
// 1. 创建并填充对象
PayParams payParams = new PayParams
{
Amount = 100,// 单位:分
ItemId = "com.nekki.sf3.cn_1",
ItemName = "礼包0",
CallbackInfo = "123456_8888_987654321",
NotifyUrl = "",
Count = 1,
Currency = "CNY"
};
payParams.AddOptionalParameter("test", "daily_bonus");
payParams.AddOptionalParameter("player_id", "p-98765");
NativeLogger.I("Game_Unity_Log", $"clicked Exit jsonString: {payParams}");
HoolaiSdkManager.StartPay(payParams);
}
public void OnPayBtnClicked6()
{
NativeLogger.I("Game_Unity_Log", "clicked Pay");
// 1. 创建并填充对象
PayParams payParams = new PayParams
{
Amount = 600, // 单位:分
ItemId = "com.nekki.sf3.cn_6",
ItemName = "礼包1",
CallbackInfo = "123456_8888_987654321",
NotifyUrl = "",
Count = 1,
Currency = "CNY"
};
payParams.AddOptionalParameter("test", "daily_bonus");
payParams.AddOptionalParameter("player_id", "p-98765");
NativeLogger.I("Game_Unity_Log", $"clicked Exit jsonString: {payParams}");
HoolaiSdkManager.StartPay(payParams);
}
public void OnPayBtnClicked68()
{
NativeLogger.I("Game_Unity_Log", "clicked Pay");
// 1. 创建并填充对象
PayParams payParams = new PayParams
{
Amount = 6800,// 单位:分
ItemId = "com.nekki.sf3.ch_68",
ItemName = "礼包10",
CallbackInfo = "123456_8888_987654321",
NotifyUrl = "",
Count = 1,
Currency = "CNY"
};
payParams.AddOptionalParameter("test", "daily_bonus");
payParams.AddOptionalParameter("player_id", "p-98765");
NativeLogger.I("Game_Unity_Log", $"clicked Exit jsonString: {payParams}");
HoolaiSdkManager.StartPay(payParams);
}
public void OnPayBtnClicked128()
{
NativeLogger.I("Game_Unity_Log", "clicked Pay");
// 1. 创建并填充对象
PayParams payParams = new PayParams
{
Amount = 100,
ItemId = "sword_101",
ItemName = "钻石",
Amount = 12800,// 单位:分
ItemId = "com.nekki.sf3.cn_128",
ItemName = "礼包20",
CallbackInfo = "123456_8888_987654321",
NotifyUrl = "",
Count = 1,
Currency = "USD"
Currency = "CNY"
};
payParams.AddOptionalParameter("test", "daily_bonus");
payParams.AddOptionalParameter("player_id", "p-98765");
......
......@@ -9,6 +9,8 @@ public class HoolaiListener : IPlatformCallbackListener
//商品列表更新事件
public event Action<List<GoodsInfo>> OnGoodsListUpdated;
public ExitConfirmationDialog exitDialog;
public static HoolaiListener Instance
{
get
......@@ -27,6 +29,12 @@ public class HoolaiListener : IPlatformCallbackListener
PlatformCallback.SetListener(this);
}
// 初始化退出标准警告
public void SetExitConfirmationDialog(ExitConfirmationDialog dialog)
{
exitDialog = dialog; // 保存对话框实例
}
public void OnInitSuccess(InitResult result)
{
NativeLogger.I("Game_Unity_Callback", $"OnInitSuccess GameId:{result.gameId} channel:{result.channel} channelId:{result.channelId}");
......@@ -99,5 +107,13 @@ public class HoolaiListener : IPlatformCallbackListener
public void OnCustomExit()
{
NativeLogger.I("Game_Unity_Callback", $"OnCustomExit show Game Exit Dialog!");
if (exitDialog != null)
{
exitDialog.ShowDialog(); // 显示确认对话框
}
else
{
NativeLogger.I("Game_Unity_Callback", "ExitConfirmationDialog is not set!");
}
}
}
......@@ -14,12 +14,12 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_PixelRect:
serializedVersion: 2
x: -1
y: 63
width: 1710
x: 0
y: 53
width: 1920
height: 975
m_ShowMode: 4
m_Title: "\u9879\u76EE"
m_Title: Inspector
m_RootView: {fileID: 2}
m_MinSize: {x: 875, y: 300}
m_MaxSize: {x: 10000, y: 10000}
......@@ -44,7 +44,7 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 1710
width: 1920
height: 975
m_MinSize: {x: 875, y: 300}
m_MaxSize: {x: 10000, y: 10000}
......@@ -69,7 +69,7 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 1710
width: 1920
height: 30
m_MinSize: {x: 0, y: 0}
m_MaxSize: {x: 0, y: 0}
......@@ -91,7 +91,7 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 955
width: 1710
width: 1920
height: 20
m_MinSize: {x: 0, y: 0}
m_MaxSize: {x: 0, y: 0}
......@@ -114,12 +114,12 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 30
width: 1710
width: 1920
height: 925
m_MinSize: {x: 300, y: 100}
m_MaxSize: {x: 24288, y: 16192}
vertical: 0
controlID: 37
controlID: 102
draggingID: 0
--- !u!114 &6
MonoBehaviour:
......@@ -140,7 +140,7 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 1201
width: 1347.5
height: 925
m_MinSize: {x: 200, y: 100}
m_MaxSize: {x: 16192, y: 16192}
......@@ -166,7 +166,7 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 1201
width: 1347.5
height: 457.5
m_MinSize: {x: 200, y: 50}
m_MaxSize: {x: 16192, y: 8096}
......@@ -190,7 +190,7 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 296
width: 331.5
height: 457.5
m_MinSize: {x: 201, y: 221}
m_MaxSize: {x: 4001, y: 4021}
......@@ -209,23 +209,23 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 1
m_Script: {fileID: 12006, guid: 0000000000000000e000000000000000, type: 0}
m_Name: SceneView
m_Name: SimulatorWindow
m_EditorClassIdentifier:
m_Children: []
m_Position:
serializedVersion: 2
x: 296
x: 331.5
y: 0
width: 905
width: 1016
height: 457.5
m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 14}
m_MinSize: {x: 202, y: 221}
m_MaxSize: {x: 4002, y: 4021}
m_ActualView: {fileID: 12}
m_Panes:
- {fileID: 14}
- {fileID: 12}
m_Selected: 0
m_LastSelected: 1
m_Selected: 1
m_LastSelected: 0
--- !u!114 &10
MonoBehaviour:
m_ObjectHideFlags: 52
......@@ -243,7 +243,7 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 457.5
width: 1201
width: 1347.5
height: 467.5
m_MinSize: {x: 231, y: 271}
m_MaxSize: {x: 10001, y: 10021}
......@@ -269,12 +269,12 @@ MonoBehaviour:
m_Children: []
m_Position:
serializedVersion: 2
x: 1201
x: 1347.5
y: 0
width: 509
width: 572.5
height: 925
m_MinSize: {x: 275, y: 50}
m_MaxSize: {x: 4000, y: 4000}
m_MinSize: {x: 276, y: 71}
m_MaxSize: {x: 4001, y: 4021}
m_ActualView: {fileID: 18}
m_Panes:
- {fileID: 18}
......@@ -295,15 +295,15 @@ MonoBehaviour:
m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 4000, y: 4000}
m_TitleContent:
m_Text: "\u6A21\u62DF\u5668"
m_Text: Simulator
m_Image: {fileID: 3038311277492192215, guid: 0000000000000000d000000000000000, type: 0}
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 333
x: 331.5
y: 83
width: 1013.5
height: 516
width: 1014
height: 436.5
m_SerializedDataModeController:
m_DataMode: 0
m_PreferredDataMode: 0
......@@ -322,7 +322,7 @@ MonoBehaviour:
m_ShowGizmos: 0
m_TargetDisplay: 0
m_ClearColor: {r: 0, g: 0, b: 0, a: 1}
m_TargetSize: {x: 2340, y: 1080}
m_TargetSize: {x: 2640, y: 1200}
m_TextureFilterMode: 0
m_TextureHideFlags: 61
m_RenderIMGUI: 1
......@@ -330,7 +330,7 @@ MonoBehaviour:
m_UseMipMap: 0
m_SimulatorState:
controlPanelVisible: 0
controlPanelWidth: NaN
controlPanelWidth: 0
controlPanelFoldoutKeys:
- UnityEditor.DeviceSimulation.ApplicationSettingsPlugin
controlPanelFoldoutValues: 00
......@@ -338,11 +338,11 @@ MonoBehaviour:
- UnityEditor.DeviceSimulation.ApplicationSettingsPlugin
pluginStates:
- '{}'
scale: 10
fitToScreenEnabled: 1
scale: 32
fitToScreenEnabled: 0
rotationDegree: 90
highlightSafeAreaEnabled: 0
friendlyName: Google Pixel 5
friendlyName: Huawei P40 Pro
screenIndex: 0
networkReachability: 1
systemLanguage: 10
......@@ -361,14 +361,14 @@ MonoBehaviour:
m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 4000, y: 4000}
m_TitleContent:
m_Text: "\u5C42\u7EA7"
m_Text: Hierarchy
m_Image: {fileID: -3734745235275155857, guid: 0000000000000000d000000000000000, type: 0}
m_Tooltip:
m_Pos:
serializedVersion: 2
x: -1
y: 93
width: 295
x: 0
y: 83
width: 330.5
height: 436.5
m_SerializedDataModeController:
m_DataMode: 0
......@@ -383,23 +383,23 @@ MonoBehaviour:
m_SceneHierarchy:
m_TreeViewState:
scrollPos: {x: 0, y: 0}
m_SelectedIDs: 186a0000
m_SelectedIDs:
m_LastClickedID: 0
m_ExpandedIDs: 4ef2ffffacf2ffff0af3ffff74f3fffff2f3ffff26fbffff
m_ExpandedIDs: e0faffff
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name: PlatformCallback
m_OriginalName: PlatformCallback
m_Name:
m_OriginalName:
m_EditFieldRect:
serializedVersion: 2
x: 0
y: 0
width: 0
height: 0
m_UserData: 25970
m_UserData: 0
m_IsWaitingForDelay: 0
m_IsRenaming: 0
m_OriginalEventType: 0
m_OriginalEventType: 11
m_IsRenamingFilename: 0
m_ClientGUIView: {fileID: 8}
m_SearchString:
......@@ -424,14 +424,14 @@ MonoBehaviour:
m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 4000, y: 4000}
m_TitleContent:
m_Text: "\u573A\u666F"
m_Text: Scene
m_Image: {fileID: 8634526014445323508, guid: 0000000000000000d000000000000000, type: 0}
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 295
y: 93
width: 903
x: 331.5
y: 83
width: 1014
height: 436.5
m_SerializedDataModeController:
m_DataMode: 0
......@@ -960,9 +960,9 @@ MonoBehaviour:
m_PlayAudio: 0
m_AudioPlay: 0
m_Position:
m_Target: {x: 978.68414, y: 490.59204, z: -10.483236}
m_Target: {x: 727.4361, y: 364.2118, z: -6.140175}
speed: 2
m_Value: {x: 978.68414, y: 490.59204, z: -10.483236}
m_Value: {x: 727.4361, y: 364.2118, z: -6.140175}
m_RenderMode: 0
m_CameraMode:
drawMode: 0
......@@ -1012,9 +1012,9 @@ MonoBehaviour:
speed: 2
m_Value: {x: 0, y: 0, z: 0, w: 1}
m_Size:
m_Target: 10
m_Target: 1014.0175
speed: 2
m_Value: 10
m_Value: 1014.0175
m_Ortho:
m_Target: 1
speed: 2
......@@ -1054,14 +1054,14 @@ MonoBehaviour:
m_MinSize: {x: 230, y: 250}
m_MaxSize: {x: 10000, y: 10000}
m_TitleContent:
m_Text: "\u9879\u76EE"
m_Text: Project
m_Image: {fileID: -5179483145760003458, guid: 0000000000000000d000000000000000, type: 0}
m_Tooltip:
m_Pos:
serializedVersion: 2
x: -1
y: 550.5
width: 1200
x: 0
y: 540.5
width: 1346.5
height: 446.5
m_SerializedDataModeController:
m_DataMode: 0
......@@ -1084,7 +1084,7 @@ MonoBehaviour:
m_SkipHidden: 0
m_SearchArea: 1
m_Folders:
- Assets/Scenes
- Assets/Plugins/Android/libs
m_Globs: []
m_OriginalText:
m_ImportLogFlags: 0
......@@ -1092,16 +1092,16 @@ MonoBehaviour:
m_ViewMode: 1
m_StartGridSize: 64
m_LastFolders:
- Assets/Scenes
- Assets/Plugins/Android/libs
m_LastFoldersGridSize: -1
m_LastProjectPath: /Users/fengchao/Desktop/UnityDemo
m_LastProjectPath: /Users/gr/Desktop/UnityProject/UnityDemo
m_LockTracker:
m_IsLocked: 0
m_FolderTreeState:
scrollPos: {x: 0, y: 0}
m_SelectedIDs: be660000
m_LastClickedID: 26302
m_ExpandedIDs: 00000000a6660000a8660000aa660000ac660000ae66000000ca9a3b
m_SelectedIDs: 9a630000
m_LastClickedID: 25498
m_ExpandedIDs: 00000000886300008a6300008c6300008e6300009063000092630000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
......@@ -1129,7 +1129,7 @@ MonoBehaviour:
scrollPos: {x: 0, y: 0}
m_SelectedIDs:
m_LastClickedID: 0
m_ExpandedIDs: 00000000a6660000a8660000aa660000ac660000ae660000
m_ExpandedIDs: 00000000886300008a6300008c6300008e6300009063000092630000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
......@@ -1156,7 +1156,7 @@ MonoBehaviour:
m_ListAreaState:
m_SelectedInstanceIDs:
m_LastClickedInstanceID: 0
m_HadKeyboardFocusLastEvent: 1
m_HadKeyboardFocusLastEvent: 0
m_ExpandedInstanceIDs: c6230000b25c0000245a000000000000
m_RenameOverlay:
m_UserAcceptedRename: 0
......@@ -1200,15 +1200,15 @@ MonoBehaviour:
m_MinSize: {x: 100, y: 100}
m_MaxSize: {x: 4000, y: 4000}
m_TitleContent:
m_Text: "\u63A7\u5236\u53F0"
m_Text: Console
m_Image: {fileID: -4950941429401207979, guid: 0000000000000000d000000000000000, type: 0}
m_Tooltip:
m_Pos:
serializedVersion: 2
x: -1
y: 607.5
width: 1200
height: 389.5
x: 0
y: 540.5
width: 1346.5
height: 446.5
m_SerializedDataModeController:
m_DataMode: 0
m_PreferredDataMode: 0
......@@ -1269,14 +1269,14 @@ MonoBehaviour:
m_MinSize: {x: 275, y: 50}
m_MaxSize: {x: 4000, y: 4000}
m_TitleContent:
m_Text: "\u68C0\u67E5\u5668"
m_Text: Inspector
m_Image: {fileID: -440750813802333266, guid: 0000000000000000d000000000000000, type: 0}
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 1200
y: 93
width: 508
x: 1347.5
y: 83
width: 571.5
height: 904
m_SerializedDataModeController:
m_DataMode: 0
......
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