1
This commit is contained in:
+13
@@ -1,5 +1,18 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &-8242085915615494463
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 11
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
version: 7
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 8
|
||||
|
||||
+13
@@ -242,3 +242,16 @@ Material:
|
||||
- _SpecularColor: {r: 1, g: 1, b: 1, a: 0}
|
||||
- _TintColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
--- !u!114 &6604337420184386843
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 11
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
version: 7
|
||||
|
||||
+13
@@ -251,3 +251,16 @@ Material:
|
||||
- _SpecularColor: {r: 0.86415094, g: 0.6179495, b: 0.6179495, a: 0}
|
||||
- _TintColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
--- !u!114 &794974413630142426
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 11
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
version: 7
|
||||
|
||||
+13
@@ -252,3 +252,16 @@ Material:
|
||||
- _SpecularColor: {r: 1, g: 1, b: 1, a: 0}
|
||||
- _TintColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
--- !u!114 &6604137824023753845
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 11
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
version: 7
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Assets.MyGame.Scripts.Net.API.GameConfig_SubClass;
|
||||
using Assets.MyGame.Scripts.Net.API.GameConfig_SubClass;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
@@ -56,11 +56,13 @@ namespace Assets.MyGame.Scripts.Net.WebResponses
|
||||
[Serializable]
|
||||
public class FireCannonSendData
|
||||
{
|
||||
public string roomId;
|
||||
public string userId;
|
||||
public List<string> bulletIds;
|
||||
public long gold;
|
||||
public int count;
|
||||
public List<string> bulletIds;
|
||||
public SyncGameData extra;
|
||||
public bool isBot;
|
||||
}
|
||||
/// <summary>
|
||||
/// 同步游戏数据
|
||||
|
||||
@@ -22,6 +22,13 @@ namespace Assets.MyGame.Scripts.Net
|
||||
{
|
||||
private readonly Dictionary<SocketType, WebSocket> sockets = new();
|
||||
private readonly Dictionary<SocketType, string> socketPaths = new();
|
||||
private readonly Dictionary<SocketType, string> socketUrls = new();
|
||||
private readonly Dictionary<SocketType, Action> handshakeActions = new();
|
||||
private readonly HashSet<SocketType> handshakeCompleted = new();
|
||||
private readonly HashSet<SocketType> reconnecting = new();
|
||||
private readonly HashSet<SocketType> manualClosing = new();
|
||||
private float nextHeartbeatTime;
|
||||
private const float HeartbeatIntervalSeconds = 20f;
|
||||
|
||||
//private const string baseUrl = "ws://game5241.wzaxr.top";
|
||||
#if UNITY_EDITOR
|
||||
@@ -33,7 +40,7 @@ namespace Assets.MyGame.Scripts.Net
|
||||
private const string baseUrl = "ws://8.137.163.153";
|
||||
|
||||
#endif
|
||||
public bool isGame=false;
|
||||
public bool isGame = false;
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
@@ -43,12 +50,26 @@ namespace Assets.MyGame.Scripts.Net
|
||||
socketPaths[SocketType.login] = "/loginhub";
|
||||
socketPaths[SocketType.chess] = "/chessgamehub";
|
||||
socketPaths[SocketType.customer] = "/customerHub";
|
||||
nextHeartbeatTime = Time.realtimeSinceStartup + HeartbeatIntervalSeconds;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Time.realtimeSinceStartup < nextHeartbeatTime)
|
||||
return;
|
||||
|
||||
nextHeartbeatTime = Time.realtimeSinceStartup + HeartbeatIntervalSeconds;
|
||||
foreach (var pair in sockets)
|
||||
{
|
||||
if (pair.Value != null && pair.Value.IsOpen && handshakeCompleted.Contains(pair.Key))
|
||||
pair.Value.Send("{\"type\":6}\u001e");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建或返回已存在的 WebSocket
|
||||
/// </summary>
|
||||
public WebSocket Connect(SocketType type,Action action=null)
|
||||
public WebSocket Connect(SocketType type, Action action = null)
|
||||
{
|
||||
return Connect(type, null, action);
|
||||
}
|
||||
@@ -73,7 +94,6 @@ namespace Assets.MyGame.Scripts.Net
|
||||
case SocketType.login:
|
||||
break;
|
||||
case SocketType.room:
|
||||
WebSocketSendList.JoinRoom("11109", GameManager.Instance.user.id, 1);
|
||||
break;
|
||||
case SocketType.game:
|
||||
break;
|
||||
@@ -94,6 +114,8 @@ namespace Assets.MyGame.Scripts.Net
|
||||
// 未指定 url 时用默认 baseUrl + socketPaths
|
||||
if (string.IsNullOrEmpty(url))
|
||||
url = baseUrl + socketPaths[type];
|
||||
socketUrls[type] = url;
|
||||
handshakeActions[type] = action;
|
||||
var ws = new WebSocket(new Uri(url));
|
||||
sockets[type] = ws;
|
||||
// 事件绑定
|
||||
@@ -104,31 +126,10 @@ namespace Assets.MyGame.Scripts.Net
|
||||
|
||||
|
||||
#endif
|
||||
web.Send("{\"protocol\":\"json\",\"version\":1}\u001e ");
|
||||
switch (type)
|
||||
{
|
||||
case SocketType.login:
|
||||
WebSocketSendList.Bind(GameManager.Instance.user.id);
|
||||
break;
|
||||
case SocketType.room:
|
||||
|
||||
break;
|
||||
case SocketType.game:
|
||||
|
||||
break;
|
||||
case SocketType.chess:
|
||||
//WebSocketSendList.GetRoomListChineseChess(1);
|
||||
//UIManager.Instance.Get<ChineseChessMainPanel>(UIPanel.MainGamePanelZGXQ).subUIManager.ShowAsync(UIPanel.ZGXQDistrict);
|
||||
UIManager.Instance.ShowAsync(UIPanel.MainGamePanelZGXQ);
|
||||
|
||||
break;
|
||||
case SocketType.customer:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (action != null)
|
||||
action?.Invoke();
|
||||
reconnecting.Remove(type);
|
||||
handshakeCompleted.Remove(type);
|
||||
// SignalR 握手完成前不能发送 Bind、JoinRoom 等 Hub 调用。
|
||||
web.Send("{\"protocol\":\"json\",\"version\":1}\u001e");
|
||||
};
|
||||
|
||||
ws.OnClosed += (web, code, reason) =>
|
||||
@@ -138,10 +139,17 @@ namespace Assets.MyGame.Scripts.Net
|
||||
|
||||
|
||||
#endif
|
||||
handshakeCompleted.Remove(type);
|
||||
if (sockets.TryGetValue(type, out var current) && ReferenceEquals(current, web))
|
||||
sockets.Remove(type);
|
||||
if (manualClosing.Remove(type))
|
||||
return;
|
||||
|
||||
// 自动重连
|
||||
switch (type)
|
||||
{
|
||||
case SocketType.login:
|
||||
StartReconnect(type);
|
||||
break;
|
||||
case SocketType.room:
|
||||
break;
|
||||
@@ -151,15 +159,15 @@ namespace Assets.MyGame.Scripts.Net
|
||||
int sitpos = 0;
|
||||
foreach (var item in GameManager.Instance.gameData.currRoomData.players)
|
||||
{
|
||||
if (item.userId==GameManager.Instance.user.id)
|
||||
if (item.userId == GameManager.Instance.user.id)
|
||||
{
|
||||
sitpos = item.position; break;
|
||||
}
|
||||
}
|
||||
StartCoroutine(Reconnect(type, () =>
|
||||
StartReconnect(type, () =>
|
||||
{
|
||||
WebSocketSendList.JoinRoom(GameManager.Instance.gameData.currRoomData.roomId, GameManager.Instance.user.id, sitpos);
|
||||
}));
|
||||
});
|
||||
}
|
||||
break;
|
||||
case SocketType.chess:
|
||||
@@ -169,17 +177,8 @@ namespace Assets.MyGame.Scripts.Net
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
ws.OnClosed += (web, code, message) =>
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
|
||||
Debug.LogError($"[WebSocket] {type} 错误{code}: {message}");
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
ws.OnMessage += (web, msg) =>
|
||||
@@ -214,7 +213,7 @@ namespace Assets.MyGame.Scripts.Net
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
|
||||
Debug.LogWarning($"[WebSocket] {type} 未连接,无法发送消息");
|
||||
Debug.LogWarning($"[WebSocket] {type} 未连接,无法发送消息" + msg);
|
||||
|
||||
#endif
|
||||
UIManager.Instance.ShowBoardError($"[WebSocket] {type} 未连接,无法发送消息");
|
||||
@@ -228,6 +227,8 @@ namespace Assets.MyGame.Scripts.Net
|
||||
{
|
||||
if (sockets.TryGetValue(type, out var ws))
|
||||
{
|
||||
manualClosing.Add(type);
|
||||
handshakeCompleted.Remove(type);
|
||||
ws.Close(WebSocketStatusCodes.NormalClosure, "正常关闭"); // 或者 CloseStatusCode.Normal
|
||||
//ws.Close();
|
||||
sockets.Remove(type);
|
||||
@@ -248,7 +249,14 @@ namespace Assets.MyGame.Scripts.Net
|
||||
/// <summary>
|
||||
/// 自动重连
|
||||
/// </summary>
|
||||
private System.Collections.IEnumerator Reconnect(SocketType type,Action action=null)
|
||||
private void StartReconnect(SocketType type, Action action = null)
|
||||
{
|
||||
if (!reconnecting.Add(type))
|
||||
return;
|
||||
StartCoroutine(Reconnect(type, action));
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator Reconnect(SocketType type, Action action = null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
|
||||
@@ -256,7 +264,36 @@ namespace Assets.MyGame.Scripts.Net
|
||||
|
||||
#endif
|
||||
yield return new WaitForSeconds(3f);
|
||||
Connect(type,action);
|
||||
if (manualClosing.Contains(type))
|
||||
{
|
||||
reconnecting.Remove(type);
|
||||
yield break;
|
||||
}
|
||||
|
||||
socketUrls.TryGetValue(type, out var url);
|
||||
Connect(type, url, action);
|
||||
}
|
||||
|
||||
private void OnHandshakeCompleted(SocketType type)
|
||||
{
|
||||
if (!handshakeCompleted.Add(type))
|
||||
return;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case SocketType.login:
|
||||
WebSocketSendList.Bind(GameManager.Instance.user.id);
|
||||
break;
|
||||
case SocketType.chess:
|
||||
UIManager.Instance.ShowAsync(UIPanel.MainGamePanelZGXQ);
|
||||
break;
|
||||
}
|
||||
|
||||
if (handshakeActions.TryGetValue(type, out var action) && action != null)
|
||||
{
|
||||
handshakeActions[type] = null;
|
||||
action.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -264,11 +301,13 @@ namespace Assets.MyGame.Scripts.Net
|
||||
/// </summary>
|
||||
private void OnDestroy()
|
||||
{
|
||||
foreach (var ws in sockets.Values)
|
||||
foreach (var type in new List<SocketType>(sockets.Keys))
|
||||
manualClosing.Add(type);
|
||||
foreach (var ws in new List<WebSocket>(sockets.Values))
|
||||
{
|
||||
ws.Close();
|
||||
}
|
||||
sockets.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,19 @@ namespace Assets.MyGame.Scripts.Net
|
||||
string[] msgs = msg.Split('\u001e');
|
||||
foreach (var item in msgs)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(item))
|
||||
continue;
|
||||
|
||||
if (item.Trim() == "{}")
|
||||
{
|
||||
OnHandshakeCompleted(type);
|
||||
continue;
|
||||
}
|
||||
|
||||
var v = JsonConvert.DeserializeObject<WebSocketResponseBase<object>>(item);
|
||||
if (v == null)
|
||||
{
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
// TODO: 这里可以做统一消息分发
|
||||
#region 消息处理
|
||||
|
||||
@@ -285,7 +285,16 @@ namespace Assets.MyGame.Scripts.Net
|
||||
//WebSocketManager.Instance.isGame = false;
|
||||
|
||||
//GameManager.Instance.StartGame();RoomChangeResponse
|
||||
var userid = JsonConvert.DeserializeObject<WebSocketResponseBase<string>>(msg).arguments[0];
|
||||
var response = JsonConvert.DeserializeObject<WebSocketResponseBase<string>>(msg);
|
||||
// ⭐ 数据保护:arguments 为空直接返回,避免抛异常
|
||||
if (response?.arguments == null || response.arguments.Count == 0)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
Debug.LogWarning("[LeaveRoomResult] arguments 为空,忽略");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
var userid = response.arguments[0];
|
||||
switch (GameManager.Instance.gameData.currGameType)
|
||||
{
|
||||
case GameType.JQQD:
|
||||
@@ -295,6 +304,7 @@ namespace Assets.MyGame.Scripts.Net
|
||||
case GameType.FLZY:
|
||||
{
|
||||
var panel = UIManager.Instance.Get<GameMainPanel_FLZY>(UIPanel.MainGamePanelFLZY);
|
||||
if (panel == null || panel.currSitData == null) break;
|
||||
if (panel.currSitData.user == userid)
|
||||
{
|
||||
UIManager.Instance.ShowAsync(UIPanel.HomeMainPanel, UIPanel.MainGamePanelFLZY);
|
||||
@@ -313,6 +323,7 @@ namespace Assets.MyGame.Scripts.Net
|
||||
case GameType.YYSC:
|
||||
{
|
||||
var panel = UIManager.Instance.Get<GameMainPanel_YYSC>(UIPanel.MainGamePanelYYSC);
|
||||
if (panel == null || panel.currSitData == null) break;
|
||||
if (panel.currSitData.user == userid)
|
||||
{
|
||||
UIManager.Instance.ShowAsync(UIPanel.HomeMainPanel, UIPanel.MainGamePanelYYSC);
|
||||
@@ -333,6 +344,7 @@ namespace Assets.MyGame.Scripts.Net
|
||||
case GameType.XJMH:
|
||||
{
|
||||
var panel = UIManager.Instance.Get<GameMainPanel_XJMH>(UIPanel.MainGamePanelXJMH);
|
||||
if (panel == null || panel.currSitData == null) break;
|
||||
if (panel.currSitData.user == userid)
|
||||
{
|
||||
UIManager.Instance.ShowAsync(UIPanel.HomeMainPanel, UIPanel.MainGamePanelXJMH);
|
||||
@@ -352,6 +364,7 @@ namespace Assets.MyGame.Scripts.Net
|
||||
case GameType.HHWK:
|
||||
{
|
||||
var panel = UIManager.Instance.Get<GameMainPanel_HHWK>(UIPanel.MainGamePanelHHWK);
|
||||
if (panel == null || panel.currSitData == null) break;
|
||||
if (panel.currSitData.user == userid)
|
||||
{
|
||||
UIManager.Instance.ShowAsync(UIPanel.HomeMainPanel, UIPanel.MainGamePanelHHWK);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Assets.MyGame.Scripts.Net;
|
||||
using Assets.MyGame.Scripts.Net;
|
||||
using Assets.MyGame.Scripts.Net.WebResponses;
|
||||
using Assets.MyGame.Scripts.Net.WebResponses.ChineseChess;
|
||||
using Newtonsoft.Json;
|
||||
@@ -101,39 +101,37 @@ public partial class WebSocketSendList
|
||||
WebSocketManager.Instance.Send(SocketType.game, JsonConvert.SerializeObject(sendObj));
|
||||
}
|
||||
/// <summary>
|
||||
/// 发射子弹
|
||||
/// 真人玩家发射子弹(新版,对接服务端 RoomFireNotice 新签名)
|
||||
/// 服务端方法:FireCannon(roomId, userId, gold, count, bulletIds, extra, isBot)
|
||||
/// 广播事件:RoomFireNotice(roomId, userId, gold, count, bulletIds, extra, isBot)
|
||||
/// 新版无需 timestamp 和 sign,bulletIds 由客户端生成
|
||||
/// </summary>
|
||||
/// <param name="roomId"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="roomId">房间ID</param>
|
||||
/// <param name="userId">玩家ID</param>
|
||||
/// <param name="gold">单价</param>
|
||||
/// <param name="count">数量</param>
|
||||
/// <summary>
|
||||
/// 发射子弹(与 KillFish 同结构版本)
|
||||
/// </summary>
|
||||
/// <param name="bulletIds">子弹ID列表(客户端生成,长度需等于 count)</param>
|
||||
/// <param name="extra">附加数据(SyncGameData)</param>
|
||||
/// <param name="isBot">是否机器人(真人玩家固定 false)</param>
|
||||
public static void FireCannon(
|
||||
string roomId,
|
||||
string userId,
|
||||
long gold,
|
||||
int count,
|
||||
List<string> bulletIds,
|
||||
object extra,
|
||||
string signKey
|
||||
bool isBot = false
|
||||
)
|
||||
{
|
||||
long timespan = BeijingTimeManager.Instance.CurrentTimestampMs; // 毫秒
|
||||
long timestamp = timespan / 1000; // 秒级
|
||||
|
||||
// FireCannon 的签名规则与 KillFish 一样:roomId|userId|gold|count|timestamp
|
||||
string sign = MakeFireCannonSign(roomId, userId, gold, count, timestamp, signKey);
|
||||
|
||||
var sendObj = new WebSocketSendList(
|
||||
"FireCannon",
|
||||
roomId,
|
||||
userId,
|
||||
gold,
|
||||
count,
|
||||
timestamp,
|
||||
sign,
|
||||
extra
|
||||
bulletIds,
|
||||
extra,
|
||||
isBot
|
||||
);
|
||||
|
||||
WebSocketManager.Instance.Send(SocketType.game, JsonConvert.SerializeObject(sendObj));
|
||||
|
||||
@@ -1720,20 +1720,24 @@ public class GameMainPanel_FishBase : GameMainPanel_Base
|
||||
// 三射 = 3 发,否则 = 1 发
|
||||
int count = isSanShe ? 3 : 1;
|
||||
|
||||
// 新版 FireCannon 不需要 timestamp 和 sign
|
||||
// ⭐ 客户端生成 bulletIds(GUID),与服务端 RoomFireNotice 新签名对齐
|
||||
// 本地玩家也通过服务器广播回来创建子弹,bulletIds 必须提前生成
|
||||
List<string> bulletIds = new List<string>(count);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
bulletIds.Add(System.Guid.NewGuid().ToString("N"));
|
||||
}
|
||||
|
||||
// 新版 FireCannon:roomId, userId, gold, count, bulletIds, extra, isBot
|
||||
WebSocketSendList.FireCannon(
|
||||
roomdata.roomId,
|
||||
user.id,
|
||||
currSitData.consumeGoldNum,
|
||||
count,
|
||||
bulletIds,
|
||||
sgd,
|
||||
"63215f0afa3f5b25"
|
||||
false
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
// WebSocketSendList.FireCannon(roomdata.roomId, user.id,currSitData.consumeGoldNum,1,BeijingTimeManager.Instance.CurrentTimestamp, "63215f0afa3f5b25", sgd);
|
||||
}
|
||||
|
||||
|
||||
@@ -1833,8 +1837,10 @@ public class GameMainPanel_FishBase : GameMainPanel_Base
|
||||
float angle = botLastAngle.TryGetValue(sync.userId, out float a) ? a : sit.currentAngle;
|
||||
if (sync.bulletIds == null || sync.bulletIds.Count == 0) return;
|
||||
|
||||
// bot 从 botLastFireData 还原完整技能参数;真人玩家用默认参数
|
||||
if (sit.isBot && botLastFireData.TryGetValue(sync.userId, out var fireData))
|
||||
// ⭐ 优先用服务器广播的 sync.isBot 标记判断是否机器人
|
||||
// bot 从 botLastFireData 还原完整技能参数;真人玩家用默认参数
|
||||
bool isBot = sync.isBot || sit.isBot;
|
||||
if (isBot && botLastFireData.TryGetValue(sync.userId, out var fireData))
|
||||
{
|
||||
FireBullet(sit, angle, fireData.isSanShe, fireData.twoRTruuect,
|
||||
fireData.isSuoDing, sync.bulletIds, fireData.monsterIDs);
|
||||
|
||||
@@ -50,7 +50,7 @@ public class BackPackPropItem : MonoBehaviour
|
||||
public TextMeshProUGUI propCount;
|
||||
|
||||
// 金币/钻石图标从 Resources 读取(放 Assets/Resources 根目录),静态缓存避免重复加载
|
||||
private const string GoldResName = "gild";
|
||||
private const string GoldResName = "gold";
|
||||
private const string DiamondResName = "diamond";
|
||||
private static Sprite _goldSprite;
|
||||
private static Sprite _diamondSprite;
|
||||
|
||||
@@ -263,18 +263,30 @@ public class UIHome_BY_EmailPanel : SubUIBase
|
||||
if (item.rewardGold>=0)
|
||||
{
|
||||
GameObject obj = Instantiate(propPrefab, propPrefabParent);
|
||||
Addressables.LoadAssetAsync<Sprite>("Assets/UIResources/Home/邮件/图层 2311.png").Completed+=(AsyncOperationHandle<Sprite> op) =>
|
||||
ResourceRequest request = Resources.LoadAsync<Sprite>("gold");
|
||||
request.completed += (op) =>
|
||||
{
|
||||
if (op.Status==AsyncOperationStatus.Succeeded)
|
||||
if (op is ResourceRequest req && req.asset is Sprite sprite)
|
||||
{
|
||||
obj.transform.GetChild(0).GetComponent<Image>().sprite = op.Result;
|
||||
obj.transform.GetChild(0).GetComponent<Image>().sprite = sprite;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("加载失败: " + op.OperationException);
|
||||
Debug.LogError("加载失败: ");
|
||||
}
|
||||
|
||||
};
|
||||
//Addressables.LoadAssetAsync<Sprite>("Assets/UIResources/Home/邮件/图层 2311.png").Completed+=(AsyncOperationHandle<Sprite> op) =>
|
||||
//{
|
||||
// if (op.Status==AsyncOperationStatus.Succeeded)
|
||||
// {
|
||||
// obj.transform.GetChild(0).GetComponent<Image>().sprite = op.Result;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Debug.LogError("加载失败: " + op.OperationException);
|
||||
// }
|
||||
|
||||
//};
|
||||
obj.transform.GetChild(0).GetChild(0).GetComponent<TextMeshProUGUI>().text = item.rewardGold.ToString();
|
||||
if (item.isReward)
|
||||
{
|
||||
@@ -293,18 +305,30 @@ public class UIHome_BY_EmailPanel : SubUIBase
|
||||
{
|
||||
|
||||
GameObject obj = Instantiate(propPrefab, propPrefabParent);
|
||||
Addressables.LoadAssetAsync<Sprite>("Assets/UIResources/Home/邮件/图层 2314.png").Completed += (AsyncOperationHandle<Sprite> op) =>
|
||||
ResourceRequest request = Resources.LoadAsync<Sprite>("diamond");
|
||||
request.completed += (op) =>
|
||||
{
|
||||
if (op.Status == AsyncOperationStatus.Succeeded)
|
||||
if (op is ResourceRequest req && req.asset is Sprite sprite)
|
||||
{
|
||||
obj.transform.GetChild(0).GetComponent<Image>().sprite = op.Result;
|
||||
obj.transform.GetChild(0).GetComponent<Image>().sprite = sprite;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("加载失败: " + op.OperationException);
|
||||
Debug.LogError("加载失败: ");
|
||||
}
|
||||
|
||||
};
|
||||
//Addressables.LoadAssetAsync<Sprite>("Assets/UIResources/Home/邮件/图层 2314.png").Completed += (AsyncOperationHandle<Sprite> op) =>
|
||||
//{
|
||||
// if (op.Status == AsyncOperationStatus.Succeeded)
|
||||
// {
|
||||
// obj.transform.GetChild(0).GetComponent<Image>().sprite = op.Result;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Debug.LogError("加载失败: " + op.OperationException);
|
||||
// }
|
||||
|
||||
//};
|
||||
obj.transform.GetChild(0).GetChild(0).GetComponent<TextMeshProUGUI>().text = item.rewardDiamond.ToString();
|
||||
if (item.isReward)
|
||||
{
|
||||
|
||||
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Reference in New Issue
Block a user