Compare commits

...

2 Commits

Author SHA1 Message Date
杨号敬
b07e5a782a Merge branch 'main' of http://shu.sheziwanglo.cn:3000/shurongsen/Cute_demon_attacks 2025-01-06 16:05:27 +08:00
杨号敬
813c2fc849 最强钓手逻辑 2025-01-06 16:05:16 +08:00
2 changed files with 358 additions and 31 deletions

View File

@ -9873,6 +9873,7 @@ GameObject:
- component: {fileID: 99292838} - component: {fileID: 99292838}
- component: {fileID: 99292840} - component: {fileID: 99292840}
- component: {fileID: 99292839} - component: {fileID: 99292839}
- component: {fileID: 99292841}
m_Layer: 5 m_Layer: 5
m_Name: lagantou m_Name: lagantou
m_TagString: Untagged m_TagString: Untagged
@ -9938,6 +9939,50 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 99292837} m_GameObject: {fileID: 99292837}
m_CullTransparentMesh: 1 m_CullTransparentMesh: 1
--- !u!114 &99292841
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 99292837}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_WrapAround: 0
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_SelectedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 99292839}
m_OnClick:
m_PersistentCalls:
m_Calls: []
--- !u!1 &99864169 --- !u!1 &99864169
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -34517,27 +34562,27 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3011360593699687250, guid: a8cc81ed2c5736a46a14628d8d489ac4, type: 3} - target: {fileID: 3011360593699687250, guid: a8cc81ed2c5736a46a14628d8d489ac4, type: 3}
propertyPath: m_AnchorMax.y propertyPath: m_AnchorMax.y
value: 0 value: 1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3011360593699687250, guid: a8cc81ed2c5736a46a14628d8d489ac4, type: 3} - target: {fileID: 3011360593699687250, guid: a8cc81ed2c5736a46a14628d8d489ac4, type: 3}
propertyPath: m_AnchorMin.y propertyPath: m_AnchorMin.y
value: 0 value: 1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3011360593699687250, guid: a8cc81ed2c5736a46a14628d8d489ac4, type: 3} - target: {fileID: 3011360593699687250, guid: a8cc81ed2c5736a46a14628d8d489ac4, type: 3}
propertyPath: m_SizeDelta.x propertyPath: m_SizeDelta.x
value: 0 value: 600
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3011360593699687250, guid: a8cc81ed2c5736a46a14628d8d489ac4, type: 3} - target: {fileID: 3011360593699687250, guid: a8cc81ed2c5736a46a14628d8d489ac4, type: 3}
propertyPath: m_SizeDelta.y propertyPath: m_SizeDelta.y
value: 0 value: 733
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3011360593699687250, guid: a8cc81ed2c5736a46a14628d8d489ac4, type: 3} - target: {fileID: 3011360593699687250, guid: a8cc81ed2c5736a46a14628d8d489ac4, type: 3}
propertyPath: m_AnchoredPosition.x propertyPath: m_AnchoredPosition.x
value: 0 value: 300
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3011360593699687250, guid: a8cc81ed2c5736a46a14628d8d489ac4, type: 3} - target: {fileID: 3011360593699687250, guid: a8cc81ed2c5736a46a14628d8d489ac4, type: 3}
propertyPath: m_AnchoredPosition.y propertyPath: m_AnchoredPosition.y
value: 0 value: -366.5
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3011360593729086421, guid: a8cc81ed2c5736a46a14628d8d489ac4, type: 3} - target: {fileID: 3011360593729086421, guid: a8cc81ed2c5736a46a14628d8d489ac4, type: 3}
propertyPath: m_Sprite propertyPath: m_Sprite
@ -101109,7 +101154,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 0 m_IsActive: 1
--- !u!224 &1073200880 --- !u!224 &1073200880
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -101143,7 +101188,13 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: ec0bc6b6d3f7fd044847aebc4ea31592, type: 3} m_Script: {fileID: 11500000, guid: ec0bc6b6d3f7fd044847aebc4ea31592, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
count: 0 count: 1
balance: {fileID: 1360804702}
intro_text: {fileID: 587456892}
surpluscount_text: {fileID: 1434357695}
Tourubtn: {fileID: 1594695428}
TimeText: {fileID: 1716546489}
Fishing: {fileID: 99292841}
--- !u!1 &1073869858 --- !u!1 &1073869858
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -103461,6 +103512,83 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1100736960} m_GameObject: {fileID: 1100736960}
m_CullTransparentMesh: 1 m_CullTransparentMesh: 1
--- !u!1 &1101304899
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1101304900}
- component: {fileID: 1101304902}
- component: {fileID: 1101304901}
m_Layer: 5
m_Name: daojishi
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1101304900
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1101304899}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1716546488}
m_Father: {fileID: 1544898928}
m_RootOrder: 9
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 1}
m_AnchorMax: {x: 0.5, y: 1}
m_AnchoredPosition: {x: 0, y: -266}
m_SizeDelta: {x: 763.4908, y: 60}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1101304901
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1101304899}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: fc36952022af4a042ac094f7fed9b017, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &1101304902
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1101304899}
m_CullTransparentMesh: 1
--- !u!1 &1103599566 --- !u!1 &1103599566
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -127540,35 +127668,35 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4284489241791779464, guid: cb107975b9c5d0340b2b96ff946e1b93, type: 3} - target: {fileID: 4284489241791779464, guid: cb107975b9c5d0340b2b96ff946e1b93, type: 3}
propertyPath: m_AnchorMax.y propertyPath: m_AnchorMax.y
value: 1 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4284489241791779464, guid: cb107975b9c5d0340b2b96ff946e1b93, type: 3} - target: {fileID: 4284489241791779464, guid: cb107975b9c5d0340b2b96ff946e1b93, type: 3}
propertyPath: m_AnchorMin.y propertyPath: m_AnchorMin.y
value: 1 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4284489241791779464, guid: cb107975b9c5d0340b2b96ff946e1b93, type: 3} - target: {fileID: 4284489241791779464, guid: cb107975b9c5d0340b2b96ff946e1b93, type: 3}
propertyPath: m_AnchoredPosition.x propertyPath: m_AnchoredPosition.x
value: 284 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4284489241791779464, guid: cb107975b9c5d0340b2b96ff946e1b93, type: 3} - target: {fileID: 4284489241791779464, guid: cb107975b9c5d0340b2b96ff946e1b93, type: 3}
propertyPath: m_AnchoredPosition.y propertyPath: m_AnchoredPosition.y
value: -43 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4284489241841894086, guid: cb107975b9c5d0340b2b96ff946e1b93, type: 3} - target: {fileID: 4284489241841894086, guid: cb107975b9c5d0340b2b96ff946e1b93, type: 3}
propertyPath: m_AnchorMax.y propertyPath: m_AnchorMax.y
value: 1 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4284489241841894086, guid: cb107975b9c5d0340b2b96ff946e1b93, type: 3} - target: {fileID: 4284489241841894086, guid: cb107975b9c5d0340b2b96ff946e1b93, type: 3}
propertyPath: m_AnchorMin.y propertyPath: m_AnchorMin.y
value: 1 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4284489241841894086, guid: cb107975b9c5d0340b2b96ff946e1b93, type: 3} - target: {fileID: 4284489241841894086, guid: cb107975b9c5d0340b2b96ff946e1b93, type: 3}
propertyPath: m_AnchoredPosition.x propertyPath: m_AnchoredPosition.x
value: 428 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4284489241841894086, guid: cb107975b9c5d0340b2b96ff946e1b93, type: 3} - target: {fileID: 4284489241841894086, guid: cb107975b9c5d0340b2b96ff946e1b93, type: 3}
propertyPath: m_AnchoredPosition.y propertyPath: m_AnchoredPosition.y
value: -43 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4284489242025471100, guid: cb107975b9c5d0340b2b96ff946e1b93, type: 3} - target: {fileID: 4284489242025471100, guid: cb107975b9c5d0340b2b96ff946e1b93, type: 3}
propertyPath: m_IsActive propertyPath: m_IsActive
@ -127601,6 +127729,17 @@ RectTransform:
m_CorrespondingSourceObject: {fileID: 4284489241738703987, guid: cb107975b9c5d0340b2b96ff946e1b93, type: 3} m_CorrespondingSourceObject: {fileID: 4284489241738703987, guid: cb107975b9c5d0340b2b96ff946e1b93, type: 3}
m_PrefabInstance: {fileID: 1360804700} m_PrefabInstance: {fileID: 1360804700}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!114 &1360804702 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 4284489241406162018, guid: cb107975b9c5d0340b2b96ff946e1b93, type: 3}
m_PrefabInstance: {fileID: 1360804700}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1360971595 --- !u!1 &1360971595
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -144358,6 +144497,7 @@ RectTransform:
- {fileID: 847345530} - {fileID: 847345530}
- {fileID: 1722191221} - {fileID: 1722191221}
- {fileID: 109792510} - {fileID: 109792510}
- {fileID: 1101304900}
m_Father: {fileID: 1073200880} m_Father: {fileID: 1073200880}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -162239,6 +162379,86 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1715483371} m_GameObject: {fileID: 1715483371}
m_CullTransparentMesh: 1 m_CullTransparentMesh: 1
--- !u!1 &1716546487
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1716546488}
- component: {fileID: 1716546490}
- component: {fileID: 1716546489}
m_Layer: 5
m_Name: Text (Legacy)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1716546488
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1716546487}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1101304900}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 468.5312, y: 60}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1716546489
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1716546487}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 25
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 2
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: "\u667A\u6167\u7684\u963F\u91CC\u9493\u5230\u4E00\u76F4\u8D85\u7EA7\u5927\u9C7C"
--- !u!222 &1716546490
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1716546487}
m_CullTransparentMesh: 1
--- !u!1 &1716889737 --- !u!1 &1716889737
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -6,31 +6,51 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
using Newtonsoft.Json; using Newtonsoft.Json;
using UnityEngine.UI;
using System.Net;
using System.Reflection;
public class WebJoinroom : MonoBehaviour public class WebJoinroom : MonoBehaviour
{ {
private ClientWebSocket _webSocket; private ClientWebSocket _webSocket;
private const string WebSocketUri = "ws://47.95.201.243:9527/api/ws"; private const string WebSocketUri = "ws://47.95.201.243:9527/api/ws";
private const string AuthorizationValue = "Bearer VH8XwWuu_iVjEPYQmCq1E2rITTg"; private string AuthorizationValue;
public int count = 0; public int count = 0;
//界面元素
public Text balance;
public Text intro_text;
public Text surpluscount_text;
public Button Tourubtn;
private float lastCallTime = 0f;
float remainingTime = 0f;
public Text TimeText;
private float interval = 1f; // 每秒调用一次
public Button Fishing;
FishJoinroomData fishJoinroomData;
private async void Start() private async void Start()
{ {
TimeText.gameObject.transform.parent.gameObject.SetActive(false);
Debug.Log(PlayerPrefs.GetString("UserToken"));
AuthorizationValue = PlayerPrefs.GetString("UserToken");
await ConnectWebSocket(); await ConnectWebSocket();
// 准备 JSON 数据 Tourubtn.onClick.AddListener(async () =>
var message = new
{ {
code = "FISHING", await SendJsonMessage(1);
content = "{\\\"action\\\":\\\"INFO\\\"}" });
}; Fishing.onClick.AddListener(() =>
{
// 将对象序列化为 JSON 字符串
string jsonMessage = JsonUtility.ToJson(message);
fish();
});
// 调用发送方法 // 调用发送方法
await SendJsonMessage("{ \"code\": \"FISHING\", \"content\": \"{\\\"action\\\":\\\"INFO\\\"}\" }"); await SendJsonMessage("{ \"code\": \"FISHING\", \"content\": \"{\\\"action\\\":\\\"INFO\\\"}\" }");
await SendJsonMessage(count);
await SendJsonMessage("{ \"code\": \"FISHING\", \"content\": \"{\\\"action\\\":\\\"FISHING\\\"}\" }"); //await SendJsonMessage("{ \"code\": \"FISHING\", \"content\": \"{\\\"action\\\":\\\"FISHING\\\"}\" }");
//await SendJsonMessage("{\"code\": \"BALANCE\"}");
} }
private async Task ConnectWebSocket() private async Task ConnectWebSocket()
@ -38,7 +58,8 @@ public class WebJoinroom : MonoBehaviour
_webSocket = new ClientWebSocket(); _webSocket = new ClientWebSocket();
// 添加 Authorization 头 // 添加 Authorization 头
_webSocket.Options.SetRequestHeader("Authorization", AuthorizationValue); _webSocket.Options.SetRequestHeader("Authorization", "Bearer "+ AuthorizationValue);
// _webSocket.Options.SetRequestHeader("client-info",);
try try
{ {
@ -76,7 +97,7 @@ public class WebJoinroom : MonoBehaviour
Debug.Log($"接收到消息:{message}"); Debug.Log($"接收到消息:{message}");
var baseResponse = JsonConvert.DeserializeObject<BaseResponse>(message); var baseResponse = JsonConvert.DeserializeObject<BaseResponse>(message);
Promptmgr.Instance.PromptBubble(baseResponse.message);
if (baseResponse != null) if (baseResponse != null)
{ {
switch (baseResponse.code) switch (baseResponse.code)
@ -85,15 +106,20 @@ public class WebJoinroom : MonoBehaviour
case "FISHING_INFO": case "FISHING_INFO":
// 解析为 FishJoinroomresponse 类型 // 解析为 FishJoinroomresponse 类型
FishJoinroomresponse fishResponse = JsonConvert.DeserializeObject<FishJoinroomresponse>(message); FishJoinroomresponse fishResponse = JsonConvert.DeserializeObject<FishJoinroomresponse>(message);
fishJoinroomData= fishResponse.data;
if (fishResponse?.data != null) if (fishResponse?.data != null)
{ {
disbalance(fishResponse.data.balance);
Debug.Log($"余额: {fishResponse.data.balance}"); Debug.Log($"余额: {fishResponse.data.balance}");
Debug.Log($"价格: {fishResponse.data.price}"); Debug.Log($"价格: {fishResponse.data.price}");
dissurplus(fishResponse.data.surplus_count, fishResponse.data.price);
count = fishResponse.data.surplus_count;
Debug.Log($"剩余数量: {fishResponse.data.surplus_count}"); Debug.Log($"剩余数量: {fishResponse.data.surplus_count}");
intro_text.text = fishResponse.data.intro_text;
Debug.Log($"玩法介绍: {fishResponse.data.intro_text}"); Debug.Log($"玩法介绍: {fishResponse.data.intro_text}");
foreach (var item in fishResponse.data.items) foreach (var item in fishResponse.data.items)
{ {
Debug.Log($"物品ID: {item.id}, 物品名称: {item.name}, 类型: {item.type}"); Debug.Log($"物品ID: {item.id}, 物品名称: {item.name}, {item.grade}{item.intro}");
} }
} }
break; break;
@ -105,8 +131,11 @@ public class WebJoinroom : MonoBehaviour
// 检查是否成功反序列化 // 检查是否成功反序列化
if (fishResponse1 != null && fishResponse1.data != null) if (fishResponse1 != null && fishResponse1.data != null)
{ {
disbalance(fishResponse1.data.balance);
Debug.Log($"余额: {fishResponse1.data.balance}"); Debug.Log($"余额: {fishResponse1.data.balance}");
Debug.Log($"价格: {fishResponse1.data.price}"); Debug.Log($"价格: {fishResponse1.data.price}");
count = fishResponse1.data.surplus_count;
dissurplus(fishResponse1.data.surplus_count, fishResponse1.data.price);
Debug.Log($"剩余数量: {fishResponse1.data.surplus_count}"); Debug.Log($"剩余数量: {fishResponse1.data.surplus_count}");
} }
else else
@ -122,17 +151,30 @@ public class WebJoinroom : MonoBehaviour
// 检查是否成功反序列化 // 检查是否成功反序列化
if (fishResponse2 != null && fishResponse2.data != null) if (fishResponse2 != null && fishResponse2.data != null)
{ {
disbalance(fishResponse2.data.balance);
Debug.Log($"余额: {fishResponse2.data.balance}"); Debug.Log($"余额: {fishResponse2.data.balance}");
Debug.Log($"价格: {fishResponse2.data.price}"); Debug.Log($"价格: {fishResponse2.data.price}");
dissurplus(fishResponse2.data.surplus_count, fishResponse2.data.price);
count = fishResponse2.data.surplus_count;
Debug.Log($"剩余数量: {fishResponse2.data.surplus_count}"); Debug.Log($"剩余数量: {fishResponse2.data.surplus_count}");
Debug.Log($"余额: {fishResponse2.data.prize.id}"); Debug.Log($"余额: {fishResponse2.data.prize.id}");
Debug.Log($"余额: {fishResponse2.data.prize.name}"); Debug.Log($"余额: {fishResponse2.data.prize.name}");
Debug.Log($"余额: {fishResponse2.data.prize.type}"); Debug.Log($"余额: {fishResponse2.data.prize.type}");
foreach(var item in fishJoinroomData.items)
{
if(fishResponse2.data.prize.id==item.id)
{
Promptmgr.Instance.PromptBubble(item.intro);
}
}
} }
else else
{ {
Debug.LogWarning("收到的消息无法解析为 Fishresponse 对象。"); Debug.LogWarning("收到的消息无法解析为 Fishresponse 对象。");
} }
break;
case "BALANCE":
break; break;
} }
} }
@ -147,6 +189,25 @@ public class WebJoinroom : MonoBehaviour
Debug.LogError($"接收消息时出错:{e.Message}"); Debug.LogError($"接收消息时出错:{e.Message}");
} }
} }
public async void fish()
{
TimeText.gameObject.transform.parent.gameObject.SetActive(true); remainingTime = 5f;
// 生成一个随机时间,假设在 1 到 5 秒之间
float randomDelay = UnityEngine.Random.Range(1f, 5f);
// 延迟随机时间
await Task.Delay(TimeSpan.FromSeconds(randomDelay));
// 延迟结束后发送消息
await SendJsonMessage("{ \"code\": \"FISHING\", \"content\": \"{\\\"action\\\":\\\"FISHING\\\"}\" }");
TimeText.gameObject.transform.parent.gameObject.SetActive(false); remainingTime = 0f;
Debug.Log("消息已发送");
if(count>=1)
{
fish();
}
}
public async Task SendJsonMessage(int count) public async Task SendJsonMessage(int count)
{ {
@ -208,6 +269,51 @@ public class WebJoinroom : MonoBehaviour
Debug.Log("WebSocket 连接已关闭。"); Debug.Log("WebSocket 连接已关闭。");
} }
} }
public void disbalance(float detail)
{
balance.text=detail.ToString();
}
public void dissurplus(float detail,int p)
{
surpluscount_text.text = (p*(int)detail).ToString()+"金币";
}
void UpdateCountdownText(float remainingTime)
{
// 将剩余时间转换为小时、分钟和秒
int hours = Mathf.FloorToInt(remainingTime / 3600);
int minutes = Mathf.FloorToInt((remainingTime % 3600) / 60);
int seconds = Mathf.FloorToInt(remainingTime % 60);
// 使用格式化字符串显示倒计时00:00:00
TimeText.text = string.Format("{0:D2}:{1:D2}:{2:D2}", hours, minutes, seconds);
}
private void Update()
{
if (Time.time - lastCallTime >= interval)
{
// 每秒调用一次的代码
if (remainingTime > 0)
{
remainingTime -= 1;
UpdateCountdownText(remainingTime);
Debug.Log("进入倒计时");
}
if (remainingTime <= 0)
{
TimeText.gameObject.transform.parent.gameObject.SetActive(false);
}
// 更新上次调用时间
lastCallTime = Time.time;
}
}
} }
public class BaseResponse public class BaseResponse
{ {
@ -235,7 +341,8 @@ public class FishJoinroom
{ {
public int id { get; set; } public int id { get; set; }
public string name { get; set; } public string name { get; set; }
public int type { get; set; } public int grade { get; set; }
public string intro { get; set; }
} }
public class Fishingresponse public class Fishingresponse
{ {