Commit 21f8bf4e authored by gaorui's avatar gaorui
Browse files

feat(app): 调整场景与接口

parent 274f3796
......@@ -159,7 +159,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -1000, y: -450}
m_SizeDelta: {x: 240, y: 80}
m_SizeDelta: {x: 260, y: 120}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &40919616
MonoBehaviour:
......@@ -339,8 +339,8 @@ MonoBehaviour:
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 24
m_fontSizeBase: 24
m_fontSize: 30
m_fontSizeBase: 30
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
......@@ -473,8 +473,8 @@ MonoBehaviour:
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 24
m_fontSizeBase: 24
m_fontSize: 32
m_fontSizeBase: 32
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
......@@ -693,7 +693,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -1000, y: 0}
m_SizeDelta: {x: 240, y: 80}
m_SizeDelta: {x: 260, y: 120}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &165585585
MonoBehaviour:
......@@ -870,7 +870,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -1000, y: 150}
m_SizeDelta: {x: 240, y: 80}
m_SizeDelta: {x: 260, y: 120}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &259715465
MonoBehaviour:
......@@ -1050,8 +1050,8 @@ MonoBehaviour:
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 24
m_fontSizeBase: 24
m_fontSize: 30
m_fontSizeBase: 30
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
......@@ -1173,7 +1173,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -1000, y: 300}
m_SizeDelta: {x: 240, y: 80}
m_SizeDelta: {x: 260, y: 120}
m_Pivot: {x: 0.5000001, y: 0.5}
--- !u!114 &633987596
MonoBehaviour:
......@@ -1775,8 +1775,8 @@ MonoBehaviour:
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 24
m_fontSizeBase: 24
m_fontSize: 30
m_fontSizeBase: 30
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
......@@ -1964,7 +1964,7 @@ GameObject:
- component: {fileID: 1076467005}
- component: {fileID: 1076467004}
m_Layer: 0
m_Name: BtnManager
m_Name: GameSdkManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
......@@ -2034,7 +2034,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -1000, y: -300}
m_SizeDelta: {x: 240, y: 80}
m_SizeDelta: {x: 260, y: 120}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1114040582
MonoBehaviour:
......@@ -2214,8 +2214,8 @@ MonoBehaviour:
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 24
m_fontSizeBase: 24
m_fontSize: 30
m_fontSizeBase: 30
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
......@@ -2755,7 +2755,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -700, y: 150}
m_SizeDelta: {x: 240, y: 80}
m_SizeDelta: {x: 260, y: 120}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1459490477
MonoBehaviour:
......@@ -3010,8 +3010,8 @@ MonoBehaviour:
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 24
m_fontSizeBase: 24
m_fontSize: 32
m_fontSizeBase: 32
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
......@@ -3176,7 +3176,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -1000, y: -150}
m_SizeDelta: {x: 240, y: 80}
m_SizeDelta: {x: 260, y: 120}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1577749885
MonoBehaviour:
......@@ -3356,8 +3356,8 @@ MonoBehaviour:
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 24
m_fontSizeBase: 24
m_fontSize: 30
m_fontSizeBase: 30
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
......@@ -3750,8 +3750,8 @@ MonoBehaviour:
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 24
m_fontSizeBase: 24
m_fontSize: 30
m_fontSizeBase: 30
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
......@@ -3884,8 +3884,8 @@ MonoBehaviour:
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 24
m_fontSizeBase: 24
m_fontSize: 30
m_fontSizeBase: 30
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
......@@ -3971,7 +3971,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -700, y: 450}
m_SizeDelta: {x: 240, y: 80}
m_SizeDelta: {x: 260, y: 120}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1889515971
MonoBehaviour:
......@@ -4104,7 +4104,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -700, y: 300}
m_SizeDelta: {x: 240, y: 80}
m_SizeDelta: {x: 260, y: 120}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1966209685
MonoBehaviour:
......@@ -4417,8 +4417,8 @@ MonoBehaviour:
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 24
m_fontSizeBase: 24
m_fontSize: 32
m_fontSizeBase: 32
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
......
fileFormatVersion: 2
guid: 789ca815eac2f468b94840a621f0b2e3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -5,6 +5,14 @@ using UnityEngine;
public class GameManager : MonoBehaviour
{
private void Awake()
{
// 触发单例构造,内部会调用 PlatformCallback.SetListener(this)
var _ = HoolaiListener.Instance;
}
public void OnLoginBtnClicked()
{
NativeLogger.I("fastsdk_btn_unity", "clicked login");
......@@ -90,7 +98,7 @@ public class GameManager : MonoBehaviour
{
NativeLogger.I("fastsdk_btn_unity", "clicked Pay With First Goods");
List<GoodsInfo> goodsList = PlatformCallback.GetCachedGoodsList();
List<GoodsInfo> goodsList = HoolaiListener.Instance.GetCachedGoodsList();
if (goodsList == null || goodsList.Count == 0)
{
......@@ -141,7 +149,7 @@ public class GameManager : MonoBehaviour
NativeLogger.I("fastsdk_btn_unity", "clicked Pay With Random Goods");
// 获取缓存的商品列表
List<GoodsInfo> goodsList = PlatformCallback.GetCachedGoodsList();
List<GoodsInfo> goodsList = HoolaiListener.Instance.GetCachedGoodsList();
if (goodsList == null || goodsList.Count == 0)
{
......
using System;
using System.Collections.Generic;
public class HoolaiListener : IPlatformCallbackListener
{
private static HoolaiListener _instance;
private List<GoodsInfo> _cachedGoodsList;
//商品列表更新事件
public event Action<List<GoodsInfo>> OnGoodsListUpdated;
public static HoolaiListener Instance
{
get
{
if (_instance == null)
{
_instance = new HoolaiListener();
}
return _instance;
}
}
private HoolaiListener()
{
// 自动设置监听器
PlatformCallback.SetListener(this);
}
public void OnInitSuccess(InitResult result)
{
NativeLogger.I("fastsdk_unity_result", $"OnInitSuccess GameId:{result.gameId} channel:{result.channel} channelId:{result.channelId}");
}
public void OnInitFailed(string reason)
{
NativeLogger.I("fastsdk_unity_result", $"OnInitFailed reason:{reason}");
}
public void OnLoginFailed(string reason)
{
NativeLogger.I("fastsdk_unity_result", $"OnLoginFailed reason:{reason}");
}
public void OnLoginSuccess(LoginResult result)
{
NativeLogger.I("fastsdk_unity_result", $"OnLoginSuccess uid:{result.uid} channel:{result.channel} channelId:{result.accessToken}");
}
public void OnRefreshUser(LoginResult result)
{
NativeLogger.I("fastsdk_unity_result", $"OnRefreshUser uid:{result.uid} channel:{result.channel} channelId:{result.accessToken}");
}
public void OnLogout(string message)
{
NativeLogger.I("fastsdk_unity_result", $"OnLogout reason:{message}");
}
public void OnPayFailed(string reason)
{
NativeLogger.I("fastsdk_unity_result", $"OnPayFailed reason:{reason}");
}
public void OnPayGoodsList(List<GoodsInfo> goodsList)
{
_cachedGoodsList = goodsList;
OnGoodsListUpdated?.Invoke(goodsList);
NativeLogger.I("fastsdk_unity_result", $"OnPayGoodsList count:{goodsList?.Count ?? 0}");
}
// 获取缓存的商品列表
public List<GoodsInfo> GetCachedGoodsList()
{
return _cachedGoodsList;
}
public void OnPaySuccess(string message)
{
NativeLogger.I("fastsdk_unity_result", $"OnPaySuccess message:{message}");
}
public void OnShareFailed(string reason)
{
NativeLogger.I("fastsdk_unity_result", $"OnShareFailed reason:{reason}");
}
public void OnShareSuccess(string reason)
{
NativeLogger.I("fastsdk_unity_result", $"OnShareSuccess reason:{reason}");
}
public void OnUpdate(string data)
{
NativeLogger.I("fastsdk_unity_result", $"OnUpdate data:{data}");
}
public void OnCustomExit()
{
NativeLogger.I("fastsdk_unity_result", $"OnCustomExit");
}
}
using System.Collections.Generic;
public interface IPlatformCallbackListener
{
void OnInitSuccess(InitResult result);
void OnInitFailed(string reason);
void OnUpdate(string data);
void OnLoginSuccess(LoginResult result);
void OnLoginFailed(string reason);
void OnRefreshUser(LoginResult result);
void OnLogout(string message);
void OnPayGoodsList(List<GoodsInfo> goodsList);
void OnPaySuccess(string message);
void OnPayFailed(string reason);
void OnShareSuccess(string message);
void OnShareFailed(string reason);
void OnCustomExit();
}
\ No newline at end of file
......@@ -37,9 +37,7 @@ public class GoodsInfo
public class PlatformCallback : MonoBehaviour
{
// 添加字段用于保存商品列表
private List<GoodsInfo> _goodsLists;
private static IPlatformCallbackListener _listener;
// 单例实现,确保只有一个接收器实例
public static PlatformCallback Instance { get; private set; }
......@@ -64,46 +62,46 @@ public class PlatformCallback : MonoBehaviour
NativeLogger.I("fastsdk_unity_result", "[PlatformCallback] Initialized with GameObject name: " + gameObject.name);
}
public static void SetListener(IPlatformCallbackListener listener)
{
_listener = listener;
}
public void onInitSuccess(string jsonStr)
{
Debug.Log("Unity onInitSuccess: " + 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);
_listener?.OnInitSuccess(result);
}
}
public void onInitFailed(string reason)
{
NativeLogger.I("fastsdk_unity_result", "[Unity] onInitFailed called with reason: " + reason);
_listener.OnInitFailed(reason);
}
//自定义退出界面
public void onCustomExit()
{
NativeLogger.I("fastsdk_unity_result", "[Unity] onCustomExit called");
_listener?.OnCustomExit();
}
//预留
public void onUpdate(string data)
{
NativeLogger.I("fastsdk_unity_result", "[Unity] onUpdate called with data: " + data);
_listener?.OnUpdate(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))
......@@ -113,9 +111,9 @@ public class PlatformCallback : MonoBehaviour
}
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}");
if (loginResult.uid != 0)
{
_listener?.OnLoginSuccess(loginResult);
}
}
......@@ -134,55 +132,49 @@ public class PlatformCallback : MonoBehaviour
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}");
_listener?.OnRefreshUser(loginResult);
}
}
public void onLoginFailed(string reason)
{
NativeLogger.I("fastsdk_unity_result", "[Unity] onLoginFailed called with reason: " + reason);
_listener?.OnLoginFailed(reason);
}
public void onLogout(string message)
{
NativeLogger.I("fastsdk_unity_result", "[Unity] onLogout called with message: " + message);
_listener?.OnLogout(message);
}
public void onPayGoodsList(string jsonStr)
{
Debug.Log("Unity 收到商品列表: " + 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)
List<GoodsInfo> goodsLists = JsonConvert.DeserializeObject<List<GoodsInfo>>(jsonStr);
NativeLogger.I("fastsdk_unity_result", "[Unity] onPayGoodsList deserialized, count: " + (goodsLists?.Count ?? 0) + ", listener is null: " + (_listener == null));
if (_listener == null)
{
NativeLogger.I("fastsdk_unity_result", $"[Unity] onPayGoodsList: {_goodsLists}");
NativeLogger.I("fastsdk_unity_result", "[Unity] onPayGoodsList called_listener is null");
}
}
// 添加方法用于获取保存的商品列表
public static List<GoodsInfo> GetCachedGoodsList()
{
return Instance != null ? Instance._goodsLists : null;
_listener?.OnPayGoodsList(goodsLists);
//if (goodsLists != null && goodsLists.Count!=0)
//{
// _listener?.OnPayGoodsList(goodsLists);
//}
}
public void onPaySuccess(string jsonStr)
{
NativeLogger.I("fastsdk_unity_result", $"[Unity] onPaySuccess called {jsonStr}");
_listener?.OnPaySuccess(jsonStr);
}
public void onPayFailed(string reason)
{
NativeLogger.I("fastsdk_unity_result", "[Unity] onPayFailed called with reason: " + reason);
_listener?.OnPayFailed(reason);
}
......@@ -190,11 +182,13 @@ public class PlatformCallback : MonoBehaviour
public void onShareSuccess(string jsonStr)
{
NativeLogger.I("fastsdk_unity_result", $"[Unity] onShareSuccess called {jsonStr}");
_listener?.OnShareSuccess(jsonStr);
}
public void onShareFailed(string jsonStr)
{
NativeLogger.I("fastsdk_unity_result", $"[Unity] onShareFailed called {jsonStr}");
_listener?.OnShareFailed(jsonStr);
}
}
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