接口调通

This commit is contained in:
GL 2024-11-15 23:31:54 +08:00
parent 5eefcbb365
commit c5056becc6
29 changed files with 711 additions and 907 deletions

View File

@ -311,9 +311,13 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 92c223077499d6f4cb08b107d23cc36b, type: 3}
m_Name:
m_EditorClassIdentifier:
escapeId: 0
roomNo: 0
roomBeansCoin: 0
btn: {fileID: 0}
Mask: {fileID: 0}
door: {fileID: 1239105052}
text: {fileID: 1341881301}
DoorIsOpen: 0
--- !u!114 &20259222
MonoBehaviour:
@ -1086,6 +1090,11 @@ MonoBehaviour:
- {fileID: 715869104}
- {fileID: 1049673032}
- {fileID: 708679840}
roomNo: 0
escapeId: -1
text: {fileID: 1632850610}
detailsText: {fileID: 1543732512}
house: {fileID: 0}
--- !u!114 &142654724
MonoBehaviour:
m_ObjectHideFlags: 0
@ -1360,6 +1369,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
Money: 1000
AllBetCoins: 0
--- !u!1 &197030554
GameObject:
m_ObjectHideFlags: 0
@ -3740,9 +3750,13 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 92c223077499d6f4cb08b107d23cc36b, type: 3}
m_Name:
m_EditorClassIdentifier:
escapeId: 0
roomNo: 0
roomBeansCoin: 0
btn: {fileID: 0}
Mask: {fileID: 0}
door: {fileID: 1996718643}
text: {fileID: 1057682373}
DoorIsOpen: 0
--- !u!114 &708679842
MonoBehaviour:
@ -4051,9 +4065,13 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 92c223077499d6f4cb08b107d23cc36b, type: 3}
m_Name:
m_EditorClassIdentifier:
escapeId: 0
roomNo: 0
roomBeansCoin: 0
btn: {fileID: 0}
Mask: {fileID: 0}
door: {fileID: 2143809077}
text: {fileID: 1130954133}
DoorIsOpen: 0
--- !u!114 &715869105
MonoBehaviour:
@ -5363,9 +5381,13 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 92c223077499d6f4cb08b107d23cc36b, type: 3}
m_Name:
m_EditorClassIdentifier:
escapeId: 0
roomNo: 0
roomBeansCoin: 0
btn: {fileID: 0}
Mask: {fileID: 0}
door: {fileID: 1501690016}
text: {fileID: 1099774253}
DoorIsOpen: 0
--- !u!114 &898215880
MonoBehaviour:
@ -5651,6 +5673,7 @@ MonoBehaviour:
- {fileID: 1341881301}
- {fileID: 1099774253}
- {fileID: 231143271}
bg: {fileID: 142654718}
--- !u!1 &953766737
GameObject:
m_ObjectHideFlags: 0
@ -6115,9 +6138,13 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 92c223077499d6f4cb08b107d23cc36b, type: 3}
m_Name:
m_EditorClassIdentifier:
escapeId: 0
roomNo: 0
roomBeansCoin: 0
btn: {fileID: 0}
Mask: {fileID: 0}
door: {fileID: 1275337683}
text: {fileID: 364052607}
DoorIsOpen: 0
--- !u!114 &1049673033
MonoBehaviour:
@ -7151,7 +7178,19 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 1227559358}
m_OnClick:
m_PersistentCalls:
m_Calls: []
m_Calls:
- m_Target: {fileID: 935748554}
m_TargetAssemblyTypeName: BettingBtn, Assembly-CSharp
m_MethodName: OnClickBetBtnAsync
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &1227559358
MonoBehaviour:
m_ObjectHideFlags: 0
@ -8730,6 +8769,10 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4075030775632783689, guid: a030fef0719b2504ba325e558ca3651c, type: 3}
propertyPath: m_Maskable
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4075030775632783691, guid: a030fef0719b2504ba325e558ca3651c, type: 3}
propertyPath: m_Name
value: TextBox (2)
@ -9331,9 +9374,13 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 92c223077499d6f4cb08b107d23cc36b, type: 3}
m_Name:
m_EditorClassIdentifier:
escapeId: 0
roomNo: 0
roomBeansCoin: 0
btn: {fileID: 0}
Mask: {fileID: 0}
door: {fileID: 1726520800}
text: {fileID: 0}
DoorIsOpen: 0
--- !u!1 &1565478602
GameObject:
@ -12314,7 +12361,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 2127674356}
- component: {fileID: 2127674358}
- component: {fileID: 2127674361}
- component: {fileID: 2127674362}
m_Layer: 5
@ -12344,18 +12390,6 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &2127674358
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2127674355}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8ee1a43c8ad7f8c41bad48013bf5af49, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &2127674361
MonoBehaviour:
m_ObjectHideFlags: 0
@ -12368,26 +12402,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: e861ed692e9579d44968fc5f4e3a7b37, type: 3}
m_Name:
m_EditorClassIdentifier:
gameEscapeId: 0
carrySeconds: 0
gameNo:
demonMode: 0
startTime:
betTime:
countTime:
settleTime:
status: 0
roomNoKill:
roomNoRemain:
beansCoinAll: 0
beansCoinKill: 0
beansCoinRemain: 0
beansCoinFee: 0
beansCoinRank: 0
beansCoinDivide: 0
escapeId: 0
roomNo: 0
roomBeansCoin: 0
--- !u!114 &2127674362
MonoBehaviour:
m_ObjectHideFlags: 0
@ -12406,6 +12420,12 @@ MonoBehaviour:
HouseLu: {fileID: 2143530050}
HouseHuang: {fileID: 20259221}
HouseFen: {fileID: 715869104}
PurText: {fileID: 0}
LuText: {fileID: 0}
HuText: {fileID: 0}
FenText: {fileID: 0}
QinText: {fileID: 0}
LanText: {fileID: 0}
--- !u!1 &2135586305
GameObject:
m_ObjectHideFlags: 0
@ -12792,9 +12812,13 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 92c223077499d6f4cb08b107d23cc36b, type: 3}
m_Name:
m_EditorClassIdentifier:
escapeId: 0
roomNo: 0
roomBeansCoin: 0
btn: {fileID: 0}
Mask: {fileID: 0}
door: {fileID: 577253061}
text: {fileID: 231143271}
DoorIsOpen: 0
--- !u!114 &2143530051
MonoBehaviour:

View File

@ -3982,6 +3982,68 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1230797779
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1230797780}
- component: {fileID: 1230797781}
m_Layer: 0
m_Name: Global
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1230797780
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1230797779}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 960.40076, y: 1284.435, z: -10.213597}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1230797781
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1230797779}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 761bde84815251c42a1d655b4e8c2b0d, type: 3}
m_Name:
m_EditorClassIdentifier:
serverResponse:
code: 0
message:
data:
userId: 0
userName:
token:
nickName:
headImg:
gender:
birthday:
idCard:
inviteCodeMy:
inviteCodeBind:
bindTime:
station:
cuteNo:
memberTime:
--- !u!1 &1358692575
GameObject:
m_ObjectHideFlags: 0
@ -4652,63 +4714,6 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1747590301}
m_CullTransparentMesh: 1
--- !u!1 &1789203778
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1789203781}
- component: {fileID: 1789203783}
- component: {fileID: 1789203782}
m_Layer: 0
m_Name: GameObject
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1789203781
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1789203778}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 641.01117, y: 1158.3336, z: -9.646636}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1789203782
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1789203778}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b7936430f01cc8343a1e62fc2052a12b, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &1789203783
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1789203778}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8ee1a43c8ad7f8c41bad48013bf5af49, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1850703526
GameObject:
m_ObjectHideFlags: 0
@ -5269,7 +5274,19 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 2003261319}
m_OnClick:
m_PersistentCalls:
m_Calls: []
m_Calls:
- m_Target: {fileID: 2113932593}
m_TargetAssemblyTypeName: logoPanel, Assembly-CSharp
m_MethodName: OnClickLoginBtnAsync
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &2003261319
MonoBehaviour:
m_ObjectHideFlags: 0

View File

@ -1,16 +1,122 @@
using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
using static UnityEditor.Progress;
using static UnityEngine.UIElements.UxmlAttributeDescription;
public class AllHouseContro : MonoBehaviour
{
public List<HouseBtn> HouseBtnList=new List<HouseBtn>();
public int roomNo = -1;
public int escapeId = -1;
public GameObject text;
public GameObject detailsText;
public HouseBtn house;
// Start is called before the first frame update
void Start()
async void Start()
{
battleRoyaleGameDetails();
InvokeRepeating("checkOutAllTheEscapeRoomsAsync", 2,2);
}
void OnDestroy()
{
CancelInvoke("checkOutAllTheEscapeRoomsAsync");
}
public async Task battleRoyaleGameDetails()//5.1.1
{
foreach (HouseBtn item in HouseBtnList)
{
item.gameObject.GetComponentInChildren<Button>().onClick.RemoveAllListeners();
}
Dictionary<string, string> head511 = new Dictionary<string, string>
{
{ "Authorization", Global.global.serverResponse.data.token }
};
string response511 = await web.SendRequest(web.URL + "/snail/gameEscape/queryLatest", "POST", "{}", head511);
Debug.Log("5.1.1查询最近一场大屠杀" + response511);
// 解析服务器返回的数据
Global.global.response = JsonConvert.DeserializeObject<Response>(response511);
escapeId = Global.global.response.data.gameEscapeModel.id;
int index = 0;
foreach (GameEscapeRoomResponseVo item in Global.global.response.data.gameEscapeRoomResponseVoList)
{
HouseBtnList[index].escapeId = item.escapeId;
HouseBtnList[index].roomNo = item.roomNo;
HouseBtnList[index].roomBeansCoin = item.roomBeansCoin;
HouseBtn a = HouseBtnList[index];
HouseBtnList[index].gameObject.GetComponentInChildren<Button>().onClick.AddListener(() => {
roomNo = item.roomNo;
Debug.Log(a.gameObject.name);
house = a;
Debug.Log("=====-----" + item.roomNo.ToString());
});
HouseBtnList[index].gameObject.GetComponentInChildren<Button>().onClick.AddListener(HouseBtnList[index].OnClickBtn);
index++;
}
is_jisha_jiesuan = false;
is_jisha = false;
}
public bool is_jisha = false;
public bool is_jisha_jiesuan = false;
public async void checkOutAllTheEscapeRoomsAsync()//5.1.2
{
//Debug.Log("===");
userIDgameId body = new userIDgameId();
body.userId = Global.global.serverResponse.data.userId;
body.escapeId = escapeId;
string response = await web.SendRequest(web.URL+"/snail/gameEscape/queryEscapeRoomList", "POST", JsonUtility.ToJson(body), Global.global.CreateHeaders());
//Debug.Log("5.1.2查询逃亡房间详情响应: " + response);
ServerResponse serverResponse = JsonConvert.DeserializeObject<ServerResponse>(response);
int index = 0;
foreach (var item in serverResponse.data.gameEscapeRoomResponseVoList){
HouseBtnList[index].text.GetComponentInChildren<TextBox>().SetText(item.roomBeansCoin);
index++;
}
if(serverResponse.data.carrySeconds == -1)
{
detailsText.GetComponentInChildren<Text>().text = "游戏结束了";
battleRoyaleGameDetails();
}
else if (serverResponse.data.carrySeconds < 45){
text.GetComponentInChildren<Text>().text = (60 - serverResponse.data.carrySeconds).ToString();
detailsText.GetComponentInChildren<Text>().text = "秒后霸主出现";
await Task.Delay(1000);
text.GetComponentInChildren<Text>().text = (60 - serverResponse.data.carrySeconds - 1).ToString();
}
else if (serverResponse.data.carrySeconds > 45 && serverResponse.data.carrySeconds < 50)
{
text.GetComponentInChildren<Text>().text = "";
detailsText.GetComponentInChildren<Text>().text = "霸主出现了";
if (!is_jisha){
is_jisha = true;
response = await web.SendRequest(web.URL + "/snail/gameEscape/queryKill", "POST", JsonUtility.ToJson(body), Global.global.CreateHeaders());
Debug.Log("5.1.4: " + response);
}
}
else if (serverResponse.data.carrySeconds > 50) {
text.GetComponentInChildren<Text>().text = "";
detailsText.GetComponentInChildren<Text>().text = "结算";
if (!is_jisha_jiesuan)
{
is_jisha_jiesuan = true;
response = await web.SendRequest(web.URL + "/snail/gameEscape/queryUserBetResult", "POST", JsonUtility.ToJson(body), Global.global.CreateHeaders());
Debug.Log("5.1.5: " + response);
}
}
}
public void ControAllDoorOpen()
{

View File

@ -1,7 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using Unity.VisualScripting.Antlr3.Runtime;
using UnityEngine;
using UnityEngine.UI;
using static BettingBtn;
using static UnityEditor.PlayerSettings;
public class BettingBtn : MonoBehaviour
{
@ -30,7 +34,6 @@ public class BettingBtn : MonoBehaviour
instance = this;
BetList.SetActive(false);
NumBtn.onClick.AddListener(OnClickNumBtn);
BetButton.onClick.AddListener(OnClickBetBtn);
BetValue = 50;//ĬÈÏ50
SetBet();
}
@ -40,68 +43,29 @@ public class BettingBtn : MonoBehaviour
BetList.SetActive(true);
}
void OnClickBetBtn()
[System.Serializable]
public class RequestData
{
if (HegemonTime.instance.timeNum>20)
{
switch (PlayerMovePos.instance.HouseId)
{
case 1:
if (PlayerInfo.instance.SetMoney(-BetValue))
{
text1.GetComponent<TextBox>().SetText(BetValue);
AllBetValue += BetValue;
}
break;
case 2:
if (PlayerInfo.instance.SetMoney(-BetValue))
{
text2.GetComponent<TextBox>().SetText(BetValue);
AllBetValue += BetValue;
}
break;
case 3:
if (PlayerInfo.instance.SetMoney(-BetValue))
{
text3.GetComponent<TextBox>().SetText(BetValue);
AllBetValue += BetValue;
}
break;
case 4:
if (PlayerInfo.instance.SetMoney(-BetValue))
{
text4.GetComponent<TextBox>().SetText(BetValue);
AllBetValue += BetValue;
}
break;
case 5:
if (PlayerInfo.instance.SetMoney(-BetValue))
{
text5.GetComponent<TextBox>().SetText(BetValue);
AllBetValue += BetValue;
}
break;
case 6:
if (PlayerInfo.instance.SetMoney(-BetValue))
{
text6.GetComponent<TextBox>().SetText(BetValue);
AllBetValue += BetValue;
}
break;
default:
Debug.Log("请选择房间");
break;
}
}
else
{
Debug.Log("现在无法投注");
}
public int userId;
public int escapeId;
public float bet;
public int roomNo;
}
public GameObject bg;
public async void OnClickBetBtnAsync()
{
RequestData body = new RequestData();
body.escapeId = bg.GetComponentInChildren<AllHouseContro>().escapeId;
body.bet = BetValue;
body.roomNo = bg.GetComponentInChildren<AllHouseContro>().roomNo;
body.userId = Global.global.serverResponse.data.userId;
bg.GetComponentInChildren<AllHouseContro>().house.text.GetComponentInChildren< TextBox >().AddText(BetValue);
string response = await web.SendRequest(web.URL + "/snail/gameEscape/userBet", "POST", JsonUtility.ToJson(body), Global.global.CreateHeaders());
Debug.Log("Óû§ÏÂ×¢ÏìÓ¦: " + response);
bg.GetComponentInChildren<AllHouseContro>().battleRoyaleGameDetails();
}
void SetBet()

View File

@ -1,5 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;
using UnityEngine.UI;
@ -11,14 +13,19 @@ public class HegemonTime : MonoBehaviour
public int carrySeconds;
public GameObject InfoObject;
public AllHouseContro allHouseContro;
public DateTime StartDateTime;
public DateTime BetDateTime;
// Start is called before the first frame update
void Start()
{
instance = this;
//StartCoroutine(StartGame());
//StartGame();
}
private void Update()
@ -26,36 +33,51 @@ public class HegemonTime : MonoBehaviour
//Debug.Log("carrySeconds:" + InfoObject.GetComponent<selectGameEscape512>().carrySeconds);
}
public IEnumerator StartGame()
{
allHouseContro.ControAllDoorOpen();
while (timeNum >=0)
{
timeText.text = (timeNum).ToString(); // 显示整数秒数
yield return new WaitForSeconds(1f); // 等待1秒
timeNum -= 1;
if (timeNum<= int.Parse(InfoObject.GetComponent<selectLatest511>().betTime)&&InfoObject.GetComponent<selectLatest511>().status==1)//停止下注,关门
{
allHouseContro.ControAllDoorClose();
MaskContro.instance.SetMask(true);
}
if (timeNum<20- int.Parse(InfoObject.GetComponent<selectLatest511>().countTime))//boos出现
{
Debug.Log("Boos来了");
BossContro.instance.BossMove();
}
}
//public IEnumerator StartGame()
//{
//timeNum = 60;
}
// //allHouseContro.ControAllDoorOpen();
// //while (timeNum >=0)
// //{
// // timeNum = 60 - QueryRoomdetails512.Instance.latestCarrySeconds;
// // timeText.text = (timeNum).ToString();// 显示整数秒数
// // yield return new WaitForSeconds(1f);// 等待1秒
// // timeText.text = (timeNum-1).ToString();
// // if ( selectLatest511.instance.status == 1)//停止下注,关门
// // {
// // //Gamber513.Instance.roomNo=PlayerMovePos.instance.HouseId;//确定下注房间id
// // //Gamber513.Instance.UserBet();
// // allHouseContro.ControAllDoorClose();
// // MaskContro.instance.SetMask(true);
// // }
// // //if (timeNum < 20)//boos出现
// // //{
// // // Debug.Log("Boos来了");
// // // BossContro.instance.BossMove();
// // //}
// //}
// //timeNum = 60;
//}
public void HadInfAndStartGame()//Æô¶¯µ¹¼Æʱ
{
timeNum =int.Parse(InfoObject.GetComponent<selectLatest511>().startTime);
StartCoroutine(StartGame());
//DateTime StartDateTime = DateTime.ParseExact(
// selectLatest511.instance.startTime, // 输入字符串
// "yyyy-MM-dd HH:mm:ss", // 格式
// CultureInfo.InvariantCulture // 使用不变的区域信息
// );
//timeNum =60- QueryRoomdetails512.Instance.latestCarrySeconds;
//StartCoroutine(StartGame());
}
public void GetcarrySeconds()
{
carrySeconds=QueryRoomdetails512.Instance.latestCarrySeconds;
}
}

View File

@ -5,10 +5,14 @@ using UnityEngine.UI;
public class HouseBtn : MonoBehaviour
{
public int escapeId;//游戏id
public int roomNo;//房间号
public float roomBeansCoin;//房间里面的钱
public Button btn;
public GameObject Mask;
public RectTransform door;
public GameObject text;
//public selectLatest511.GameEscapeRoomResponseVo gameEscapeRoomResponseVo;
public bool DoorIsOpen;
// Start is called before the first frame update
void Start()
@ -16,15 +20,14 @@ public class HouseBtn : MonoBehaviour
if (GetComponent<Button>()!= null)
{
btn=GetComponent<Button>();
btn.onClick.AddListener(OnClickBtn);
//btn.onClick.AddListener(OnClickBtn);
}
}
void OnClickBtn()
public void OnClickBtn()
{
Debug.Log("点击");
transform.GetComponent<PlayerMove>().StartMove();
PlayerMovePos.instance.HadChoise=true;

View File

@ -7,6 +7,7 @@ public class PlayerInfo : MonoBehaviour
public static PlayerInfo instance;
public float Money = 1000;
public int AllBetCoins;//总共下注蛋
// Start is called before the first frame update
void Start()
{

View File

@ -352,7 +352,7 @@ public class PlayerMove : MonoBehaviour
Debug.Log("没有失败和胜利");//胜利
}
HegemonTime.instance.StartCoroutine(HegemonTime.instance.StartGame());//重新计算时间
//HegemonTime.instance.StartCoroutine(HegemonTime.instance.StartGame());//重新计算时间
}
public void Rotate()

View File

@ -1,6 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class RoomInfo : MonoBehaviour
{
@ -11,12 +12,48 @@ public class RoomInfo : MonoBehaviour
public HouseBtn HouseLu;
public HouseBtn HouseHuang;
public HouseBtn HouseFen;
public GameObject PurText;
public GameObject LuText;
public GameObject HuText;
public GameObject FenText;
public GameObject QinText;
public GameObject LanText;
// Start is called before the first frame update
void Awake()
{
instance = this;
}
//public void GetInfoToRooom()
//{
// LanText.GetComponent<TextBox>().numText.text = QueryRoomdetails512.Instance.gameEscapeRoomResponseVoList[0].roomBeansCoin.ToString();
// HouseLan.GetComponent<HouseBtn>().RoomId = QueryRoomdetails512.Instance.gameEscapeRoomResponseVoList[0].roomNo;
// HouseLan.GetComponent<HouseBtn>().coins = QueryRoomdetails512.Instance.gameEscapeRoomResponseVoList[0].roomBeansCoin;
// LuText.GetComponent<TextBox>().numText.text = QueryRoomdetails512.Instance.gameEscapeRoomResponseVoList[1].roomBeansCoin.ToString();
// HouseLu.GetComponent<HouseBtn>().RoomId = QueryRoomdetails512.Instance.gameEscapeRoomResponseVoList[1].roomNo;
// HouseLu.GetComponent<HouseBtn>().coins = QueryRoomdetails512.Instance.gameEscapeRoomResponseVoList[1].roomBeansCoin;
// HuText.GetComponent<TextBox>().numText.text = QueryRoomdetails512.Instance.gameEscapeRoomResponseVoList[2].roomBeansCoin.ToString();
// HouseHuang.GetComponent<HouseBtn>().RoomId = QueryRoomdetails512.Instance.gameEscapeRoomResponseVoList[2].roomNo;
// HouseHuang.GetComponent<HouseBtn>().coins = QueryRoomdetails512.Instance.gameEscapeRoomResponseVoList[2].roomBeansCoin;
// FenText.GetComponent<TextBox>().numText.text = QueryRoomdetails512.Instance.gameEscapeRoomResponseVoList[3].roomBeansCoin.ToString();
// HouseFen.GetComponent<HouseBtn>().RoomId = QueryRoomdetails512.Instance.gameEscapeRoomResponseVoList[3].roomNo;
// HouseFen.GetComponent<HouseBtn>().coins = QueryRoomdetails512.Instance.gameEscapeRoomResponseVoList[3].roomBeansCoin;
// PurText.GetComponent<TextBox>().numText.text = QueryRoomdetails512.Instance.gameEscapeRoomResponseVoList[4].roomBeansCoin.ToString();
// HousePur.GetComponent<HouseBtn>().RoomId = QueryRoomdetails512.Instance.gameEscapeRoomResponseVoList[4].roomNo;
// HousePur.GetComponent<HouseBtn>().coins = QueryRoomdetails512.Instance.gameEscapeRoomResponseVoList[4].roomBeansCoin;
// LanText.GetComponent<TextBox>().numText.text = QueryRoomdetails512.Instance.gameEscapeRoomResponseVoList[5].roomBeansCoin.ToString();
// HouseQin.GetComponent<HouseBtn>().RoomId = QueryRoomdetails512.Instance.gameEscapeRoomResponseVoList[5].roomNo;
// HouseQin.GetComponent<HouseBtn>().coins = QueryRoomdetails512.Instance.gameEscapeRoomResponseVoList[5].roomBeansCoin;
//}
// Update is called once per frame
void Update()
{

View File

@ -17,6 +17,14 @@ public class TextBox : MonoBehaviour
}
public void SetText(float add)
{
float start = ParentHouse.GetComponent<HouseInfo>().Money;
ParentHouse.GetComponent<HouseInfo>().Money = add;
StartCoroutine(Tools.AnimateText(start, ParentHouse.GetComponent<HouseInfo>().Money, 0.5f, numText));
}
public void AddText(float add)
{
float start = ParentHouse.GetComponent<HouseInfo>().Money;
ParentHouse.GetComponent<HouseInfo>().Money += add;

View File

@ -1,322 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
using Newtonsoft.Json;
using UnityEngine.UI;
/*public class gamber : MonoBehaviour
{
public string token = null; // 保存最新的 token初始为 null
public int escapeId = -1; // 保存最新的 escapeId初始为 -1 表示未设置
void Start()
{
// 注册监听事件,当收到 token 时,触发 HandleTokenReceived
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
// 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated但不执行其他方法
selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
}
// 当接收到 token 时触发此方法,仅保存 token
public void HandleTokenReceived(string receivedToken)
{
token = receivedToken; // 保存最新的 token
// 首次调用加载初始数据
LoadInitialData();
//LoadGameEscapeData();
// Debug.Log("接收到新的 token: " + token);
}
// 当游戏逃亡 ID 更新时触发此方法,仅保存最新的 escapeId
public async void HandleGameEscapeIdUpdated(int newGameEscapeId)
{
escapeId = newGameEscapeId; // 保存最新的 escapeId
await UserBet();//=====================================================================放在这里仅因为懒得写触发条件可以放在任何地方比如input.GetKeyDown.....必须改掉,吃服务器
//Debug.Log("接收到新的 GameEscapeId: " + escapeId);
}
// 加载初始数据,使用最新的 token
public async void LoadInitialData()
{
if (string.IsNullOrEmpty(token))
{
Debug.LogWarning("无法加载初始数据token 未设置。");
return;
}
await UserBet();//=====================================================================放在此处只为解除一个黄色报错,看着闹心。但可以不要
}
// 加载游戏逃亡数据,使用最新的 escapeId 和 token
public async void selectQueryKill1()
{
if (string.IsNullOrEmpty(token))
{
Debug.LogWarning("无法加载游戏逃亡数据token 未设置。");
return;
}
if (escapeId == -1)
{
Debug.LogWarning("无法加载游戏逃亡数据escapeId 未设置。");
return;
}
await UserBet();//==========================================================================================================================================================================
}
//===============================================================================================================================================================================================================================
// 用户下注
public async Task UserBet()
{
var headers = CreateHeaders();
string body = $@"
{{
""userId"": 106,
""escapeId"": {escapeId},
""bet"": 100,
""roomNo"": 1
}}";
string response = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/userBet", "POST", body, headers);
Debug.Log("用户下注响应: " + response);
}
//===============================================================================================================================================================================================================================
// 创建请求头,使用最新的 token
public Dictionary<string, string> CreateHeaders()
{
if (string.IsNullOrEmpty(token))
{
Debug.LogWarning("尝试创建请求头时token 未设置。");
return new Dictionary<string, string>();
}
return new Dictionary<string, string>
{
{ "Authorization", token }
};
}
void OnDestroy()
{
// 注销监听事件,避免内存泄漏
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
}
}*/
//解析+单例
public class Gamber513 : MonoBehaviour
{
// 单例模式实现
public static Gamber513 Instance { get; private set; }
// 全局变量,用于存储服务器返回的具体字段
public string token = null; // 保存最新的 token初始为 null
public int escapeId = -1; // 保存最新的 escapeId初始为 -1 表示未设置
public int userId; // 用户 ID
private string lastUserBetResponse = null; // 保存最新的用户下注响应
// 服务器返回的字段,作为全局变量
public int code; // 返回状态码,例如 200 表示成功
public string message; // 提示信息
public object data; // 数据,可能为空
// 假设有一个下注按钮
public Button userBetButton;
void Awake()
{
// 实现单例模式
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject); // 保证此实例在场景切换时不会被销毁
}
else
{
Destroy(gameObject);
}
}
void Start()
{
// 注册监听事件,当收到 token 时,触发 HandleTokenReceived
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
// 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated但不执行其他方法
selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
// 假设下注按钮被点击时调用 OnUserBetButtonClicked
if (userBetButton != null)
{
userBetButton.onClick.AddListener(OnUserBetButtonClicked);
}
}
// 处理接收到 token 时的事件
public void HandleTokenReceived(string receivedToken)
{
token = receivedToken; // 保存最新的 token
Debug.Log("接收到的 token: " + token);
// 可以根据需要调用 LoadInitialData(),比如在 token 更新时自动加载初始数据
LoadInitialData();
}
// 处理游戏逃亡 ID 更新的事件
public async void HandleGameEscapeIdUpdated(int newGameEscapeId)
{
escapeId = newGameEscapeId; // 保存最新的 escapeId
Debug.Log("接收到新的 GameEscapeId: " + escapeId);
// 在这里可以选择手动调用 UserBet()
lastUserBetResponse = await UserBet();
Debug.Log("HandleGameEscapeIdUpdated 处理的 UserBet 响应: " + lastUserBetResponse);
// 解析响应
ParseUserBetResponse(lastUserBetResponse);
}
// 按钮点击后触发下注操作
public async void OnUserBetButtonClicked()
{
// 当按钮被点击时调用 UserBet()
if (string.IsNullOrEmpty(token))
{
Debug.LogWarning("无法进行下注token 未设置。");
return;
}
if (escapeId == -1)
{
Debug.LogWarning("无法进行下注escapeId 未设置。");
return;
}
// 调用 UserBet 并保存响应
lastUserBetResponse = await UserBet();
Debug.Log("用户按钮触发的 UserBet 响应: " + lastUserBetResponse);
// 解析响应
ParseUserBetResponse(lastUserBetResponse);
}
// 用户下注方法
public async Task<string> UserBet()
{
if (string.IsNullOrEmpty(token))
{
Debug.LogWarning("无法进行下注token 未设置。");
return null;
}
if (escapeId == -1)
{
Debug.LogWarning("无法进行下注escapeId 未设置。");
return null;
}
var headers = CreateHeaders();
string body = $@"
{{
""userId"": {userId},
""escapeId"": {escapeId},
""bet"": 100,
""roomNo"": 1
}}";
string response = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/userBet", "POST", body, headers);
Debug.Log("用户下注响应: " + response);
return response; // 返回响应
}
// 创建请求头,使用最新的 token
public Dictionary<string, string> CreateHeaders()
{
if (string.IsNullOrEmpty(token))
{
Debug.LogWarning("尝试创建请求头时token 未设置。");
return new Dictionary<string, string>();
}
return new Dictionary<string, string>
{
{ "Authorization", token }
};
}
// 处理 UserBet 方法的响应,并将解析后的字段保存到全局变量中
private void ParseUserBetResponse(string response)
{
if (string.IsNullOrEmpty(response))
{
Debug.LogWarning("无法解析用户下注响应,响应为空。");
return;
}
try
{
// 使用 Newtonsoft.Json 解析响应
UserBetResponse betResponse = JsonConvert.DeserializeObject<UserBetResponse>(response);
// 将解析后的数据赋值给全局变量
code = betResponse.code;
message = betResponse.message;
data = betResponse.data;
// 输出结果
if (code == 200)
{
Debug.Log($"下注成功!消息: {message}");
}
else
{
Debug.LogWarning($"下注失败,消息: {message}");
}
}
catch (System.Exception e)
{
Debug.LogWarning("解析用户下注响应时出错: " + e.Message);
}
}
void OnDestroy()
{
// 注销监听事件,避免内存泄漏
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
// 取消按钮的点击监听
if (userBetButton != null)
{
userBetButton.onClick.RemoveListener(OnUserBetButtonClicked);
}
}
// 加载初始数据
public async void LoadInitialData()
{
if (string.IsNullOrEmpty(token))
{
Debug.LogWarning("无法加载初始数据token 未设置。");
return;
}
lastUserBetResponse = await UserBet(); // 调用 UserBet 并保存响应
Debug.Log("初始加载的 UserBet 响应: " + lastUserBetResponse);
// 解析响应
ParseUserBetResponse(lastUserBetResponse);
}
}
// 用户下注响应数据类,用于存储解析后的响应数据
public class UserBetResponse
{
public int code { get; set; } // 返回状态码,例如 200 表示成功
public string message { get; set; } // 提示信息
public object data { get; set; } // 数据,可能为空
}

View File

@ -948,7 +948,7 @@ public class QueryRoomdetails512 : MonoBehaviour
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
// 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated
selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
//selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
// 启动协程,每两秒查询一次
queryCoroutine = StartCoroutine(QueryEscapeRoomRoutine());
@ -1019,7 +1019,9 @@ public class QueryRoomdetails512 : MonoBehaviour
// 创建请求头,使用最新的 token
public Dictionary<string, string> CreateHeaders()
{
if (string.IsNullOrEmpty(token))
Debug.Log(Global.global.serverResponse.data.token);
if (string.IsNullOrEmpty(Global.global.serverResponse.data.token))
{
Debug.LogWarning("尝试创建请求头时token 未设置。");
return new Dictionary<string, string>();
@ -1027,7 +1029,7 @@ public class QueryRoomdetails512 : MonoBehaviour
return new Dictionary<string, string>
{
{ "Authorization", token }
{ "Authorization", Global.global.serverResponse.data.token }
};
}
@ -1050,8 +1052,8 @@ public class QueryRoomdetails512 : MonoBehaviour
foreach (var roomDetail in serverResponse.data.gameEscapeRoomResponseVoList)
{
gameEscapeRoomResponseVoList.Add(roomDetail);
Debug.Log($"Escape ID: {roomDetail.escapeId}, Room No: {roomDetail.roomNo}, Room Beans Coin: {roomDetail.roomBeansCoin}");
gameEscapeRoomResponseVoList.Add(roomDetail);//¼ÓÈëÁбí
//Debug.Log($"Escape ID: {roomDetail.escapeId}, Room No: {roomDetail.roomNo}, Room Beans Coin: {roomDetail.roomBeansCoin}");
}
}
}
@ -1080,7 +1082,7 @@ public class QueryRoomdetails512 : MonoBehaviour
{
// 注销监听事件,避免内存泄漏
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
//selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
// 停止查询协程,防止内存泄漏
if (queryCoroutine != null)

View File

@ -307,7 +307,7 @@ public class SelectQueryKill514 : MonoBehaviour
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
// 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated
selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
//selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
// 假设按钮被点击时调用 OnQueryKillButtonClicked
if (queryKillButton != null)
@ -459,7 +459,7 @@ public class SelectQueryKill514 : MonoBehaviour
{
// 注销监听事件,避免内存泄漏
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
//selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
// 取消按钮的点击监听
if (queryKillButton != null)

View File

@ -290,7 +290,7 @@ public class SelectUserInfo14 : MonoBehaviour
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
// 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated
selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
//selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
// 假设按钮被点击时调用 OnSelectUserInfoButtonClicked
if (selectUserInfoButton != null)
@ -438,7 +438,7 @@ public class SelectUserInfo14 : MonoBehaviour
{
// 注销监听事件,避免内存泄漏
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
//selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
// 取消按钮的点击监听
if (selectUserInfoButton != null)

View File

@ -150,7 +150,7 @@ public class UpdateUserInfo13 : MonoBehaviour
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
// 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated
selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
//selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
// 假设按钮被点击时调用 OnUpdateUserInfoButtonClicked
if (updateUserInfoButton != null)
@ -307,7 +307,7 @@ public class UpdateUserInfo13 : MonoBehaviour
{
// 注销监听事件,避免内存泄漏
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
//selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
// 取消按钮的点击监听
if (updateUserInfoButton != null)

View File

@ -146,7 +146,7 @@ public class UserBetResult515 : MonoBehaviour
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
// 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated
selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
//selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
}
// 当接收到 token 时触发此方法,仅保存 token
@ -285,7 +285,7 @@ public class UserBetResult515 : MonoBehaviour
{
// 注销监听事件,避免内存泄漏
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
//selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
}
}

View File

@ -366,7 +366,7 @@ public class LoadMall : MonoBehaviour
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
// 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated
selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
//selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
// 假设按钮被点击时调用 OnLoadMallButtonClicked
if (loadMallButton != null)
@ -513,7 +513,7 @@ public class LoadMall : MonoBehaviour
{
// 注销监听事件,避免内存泄漏
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
//selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
// 取消按钮的点击监听
if (loadMallButton != null)

View File

@ -0,0 +1,97 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Global : MonoBehaviour
{
public logoPanel.ServerResponse serverResponse;
public Response response;
public static Global global ;
// Start is called before the first frame update
void Start()
{
global = this;
DontDestroyOnLoad(this);
}
// 创建请求头,使用最新的 token
public Dictionary<string, string> CreateHeaders()
{
if (string.IsNullOrEmpty(Global.global.serverResponse.data.token))
{
Debug.LogWarning("尝试创建请求头时token 未设置。");
return new Dictionary<string, string>();
}
return new Dictionary<string, string>
{
{ "Authorization", Global.global.serverResponse.data.token }
};
}
}
[Serializable]
public class GameEscapeRoomResponseVo
{
public int escapeId; // 游戏的ID
public int roomNo; // 房间编号
public float roomBeansCoin; // 房间下注欢乐豆
}
[Serializable]
public class userIDgameId
{
public int userId; // 用户id
public int escapeId; // 游戏id
}
[Serializable]
public class Data
{
public int carrySeconds; // 携带时间秒数
public List<GameEscapeRoomResponseVo> gameEscapeRoomResponseVoList; // 房间列表
public GameEscapeModel gameEscapeModel; // 游戏逃亡模型 (目前未处理)
public object gameEscapeUserModel; // 游戏逃亡用户模型 (目前未处理)
}
[Serializable]
public class ServerResponse
{
public int code; // 响应状态码
public string message; // 提示语
public Data data; // 数据对象
}
// 数据类
[Serializable]
public class GameEscapeModel
{
public int id; // 游戏 ID
public string gameNo; // 游戏编号
public int demonMode; // 恶魔模式
public string startTime; // 开始时间
public string betTime; // 下注时间
public string countTime; // 结算时间
public string settleTime; // 最终结算时间
public int status; // 游戏状态
public string roomNoKill; // 无杀房间号
public string roomNoRemain; // 剩余房间号
public float beansCoinAll; // 总豆币数
public float beansCoinKill; // 击杀豆币数
public float beansCoinRemain; // 剩余豆币数
public float beansCoinFee; // 手续费
public float beansCoinRank; // 排名奖励豆币
public float beansCoinDivide; // 分成豆币
}
[Serializable]
public class Response
{
public int code; // 状态码
public string message; // 返回信息
public Data data; // 数据对象
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 265365642b7b8644081cd2ce79416fb3
guid: 761bde84815251c42a1d655b4e8c2b0d
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -6,6 +6,8 @@ using UnityEngine.UI;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
using static LoginAndGetToken;
using System.Threading.Tasks;
@ -17,17 +19,16 @@ public class logoPanel : MonoBehaviour
public InputField mmField;
public InputField qrmmField;
public InputField yqmField;
public Button pwdBtn;
public Button yzmBtn;
public Image regImg;
public GameObject yzm;
public GameObject mm;
public GameObject qrmm;
public GameObject yqm;
public GameObject logBtn;
public Button loginBtn;
public GameObject regbtn;
@ -35,21 +36,17 @@ public class logoPanel : MonoBehaviour
public Button rigBtn;
public delegate void TokenReceivedDelegate(string token);
public static event TokenReceivedDelegate OnTokenReceived;
// Start is called before the first frame update
void Start()
{
yzmBtn.onClick.AddListener(OnClickYzmBtn);
pwdBtn.onClick.AddListener(OnClickPwdBtn);
loginBtn.onClick.AddListener(() => StartCoroutine(OnClickLoginBtn()));
rigistBtn.onClick.AddListener(OnClickRigistBtn);
rigBtn.onClick.AddListener(() => StartCoroutine(OnClickRegBtn()));
}
public IEnumerator OnClickRegBtn()
{
loginbody body = new loginbody
@ -62,25 +59,19 @@ public class logoPanel : MonoBehaviour
string jsonBody = JsonUtility.ToJson(body);
using (UnityWebRequest webRequest = new UnityWebRequest("http://121.40.42.41:8080/snail/user/register", "POST"))
{
// 创建并设置上传和下载处理器
webRequest.uploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(jsonBody));
webRequest.uploadHandler.contentType = "application/json";
webRequest.downloadHandler = new DownloadHandlerBuffer();
// 发送请求
yield return webRequest.SendWebRequest();
// 检查请求结果
if (webRequest.result == UnityWebRequest.Result.Success)
{
string registerResponse = webRequest.downloadHandler.text;
Debug.Log("Register Response: " + registerResponse);
SceneManager.LoadScene(1);
// 可在此处解析注册响应并进行后续处理
// 比如解析返回的token并触发事件
// 可以在此处解析注册响应并进行后续处理
}
else
{
@ -89,6 +80,31 @@ public class logoPanel : MonoBehaviour
}
}
public async void OnClickLoginBtnAsync()
{
//loginbody body = new loginbody
//{
// userName = userNameField.text,
// password = passwordField.text,
// verifyCode = int.Parse(verifyCodeField.text)
//};
loginbody body = new loginbody
{
userName = "15151658596",
password = "123456",
verifyCode = 111111
};
string loginResponse = await web.SendRequest(web.URL+"/snail/user/login", "POST", JsonUtility.ToJson(body));
ServerResponse response = JsonUtility.FromJson<ServerResponse>(loginResponse);
if (response != null && response.code == 200 && response.data != null)
{
Global.global.serverResponse = response;
SceneManager.LoadScene(1);
return;
}
Debug.Log(response.code);
}
private void OnClickRigistBtn()
{
yzm.gameObject.SetActive(true);
@ -102,45 +118,6 @@ public class logoPanel : MonoBehaviour
yzmBtn.gameObject.SetActive(false);
}
//点击登录按钮
private IEnumerator OnClickLoginBtn()
{
loginbody body = new loginbody
{
userName = userNameField.text,
password = passwordField.text,
verifyCode = int.Parse(verifyCodeField.text)
};
string jsonBody = JsonUtility.ToJson(body);
using (UnityWebRequest webRequest = new UnityWebRequest("http://121.40.42.41:8080/snail/user/login", "POST"))
{
// 创建和设置处理程序
webRequest.uploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(jsonBody));
webRequest.uploadHandler.contentType = "application/json";
webRequest.downloadHandler = new DownloadHandlerBuffer();
// 发送请求
yield return webRequest.SendWebRequest();
// 检查请求结果
if (webRequest.result == UnityWebRequest.Result.Success)
{
string loginResponse = webRequest.downloadHandler.text;
Debug.Log("LoginAndGetToken登录:" + loginResponse);
string token = getToken(loginResponse);
OnTokenReceived?.Invoke(token);
}
else
{
Debug.LogError("Error: " + webRequest.error);
}
}
}
//点击验证码登录按钮
private void OnClickYzmBtn()
{
pwdBtn.transform.position -= new Vector3(0f, 26.4f, 0f);
@ -149,7 +126,6 @@ public class logoPanel : MonoBehaviour
mm.gameObject.SetActive(false);
}
//点击密码登录按钮
private void OnClickPwdBtn()
{
pwdBtn.transform.position += new Vector3(0f, 26.4f, 0f);
@ -158,5 +134,36 @@ public class logoPanel : MonoBehaviour
mm.gameObject.SetActive(true);
}
// 服务器返回的数据结构
[System.Serializable]
public class ServerResponse
{
public int code;
public string message;
public Data data;
}
[System.Serializable]
public class Data
{
public int userId;
public string userName;
public string token;
public string nickName;
public string headImg;
public string gender;
public string birthday;
public int? voluteCoin;
public int? beansCoin;
public int? ichorCoin;
public string idCard;
public string inviteCodeMy;
public string inviteCodeBind;
public string bindTime;
public string station;
public string cuteNo;
public string memberTime;
public bool? isMember;
}
}
}

View File

@ -0,0 +1,102 @@
using UnityEngine;
/*public class UserManager : MonoBehaviour
{
private static UserManager _instance;
public static UserManager Instance
{
get
{
if (_instance == null)
{
// 尝试在场景中找到一个已经存在的实例
_instance = FindObjectOfType<UserManager>();
// 如果场景中不存在则创建一个新的GameObject并添加UserManager组件
if (_instance == null)
{
GameObject go = new GameObject("UserManager");
_instance = go.AddComponent<UserManager>();
}
// 确保实例不会在场景切换时销毁
DontDestroyOnLoad(_instance.gameObject);
}
return _instance;
}
}
// 用于存储服务器返回的用户数据
public int UserId { get; private set; }
public string UserName { get; private set; }
public string Token { get; private set; }
// 从服务器响应数据初始化
public void Initialize(UserManagerData data)
{
UserId = data.userId;
UserName = data.userName;
Token = data.token;
Debug.Log("UserManager Initialized with UserId: " + UserId + ", UserName: " + UserName);
}
}*/
//11/15/1851 awake初始化并保证不销毁转换场景
public class UserManager : MonoBehaviour
{
private static UserManager _instance;
public static UserManager Instance
{
get
{
// 如果实例还未被创建,抛出一个错误提示开发者。
if (_instance == null)
{
Debug.LogError("UserManager Instance is requested, but it has not been initialized yet. Make sure the UserManager is in the scene.");
}
return _instance;
}
}
// 确保在场景切换时实例不会被销毁
private void Awake()
{
if (_instance == null)
{
_instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject); // 如果已经存在一个实例,销毁这个新实例,确保单例唯一性
}
}
// 用于存储服务器返回的用户数据
public int UserId { get; private set; }
public string UserName { get; private set; }
public string Token { get; private set; }
// 从服务器响应数据初始化
public void Initialize(UserManagerData data)
{
UserId = data.userId;
UserName = data.userName;
Token = data.token;
Debug.Log("UserManager Initialized with UserId: " + UserId + ", UserName: " + UserName);
}
}
[System.Serializable]
public class UserManagerData
{
public int userId;
public string userName;
public string token;
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: e861ed692e9579d44968fc5f4e3a7b37
guid: 68ec34c8553ce2149b1c254cfb97f662
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -991,7 +991,7 @@ public class WebConnact : MonoBehaviour
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
// 注册监听,当 escapeId 更新时调用 HandleGameEscapeIdUpdated但不执行其他方法
selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
//selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
}
// 当接收到 token 时触发此方法,仅保存 token
@ -1213,7 +1213,7 @@ public class WebConnact : MonoBehaviour
{
// 注销监听事件,避免内存泄漏
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
//selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
}
}

View File

@ -1,316 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
using System.Threading.Tasks;
/*public class selectLatest511 : MonoBehaviour
{
public static selectLatest511 instance;
public int gameEscapeId;
public int carrySeconds;
// 定义一个事件,当 gameEscapeId 被更新时触发
public static event Action<int> OnGameEscapeIdUpdated;
void Start()
{
instance=this;
// 由于除登录注册外的其他方法都需要登录后返回的token
// 因此登录不在此发送请求(同时)
// 采用监听和事件回调的方法只有监听到登录和token返回时才运行其他方法
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
// 订阅事件,当 gameEscapeId 更新时调用 HandleGameEscapeIdUpdated
selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
}
private string token; // 用于保存收到的 token
void HandleTokenReceived(string token)
{
// 使用 token
this.token = token;
Debug.Log("HandleTokenReceived监听:" + token);
StartCoroutine(GameEscapeRoutine(token)); // 启动协程每2秒调用一次gameEscape
}
void HandleGameEscapeIdUpdated(int newGameEscapeId)
{
Debug.Log("GameEscapeId 已更新为: " + newGameEscapeId);
// 在这里添加你想要执行的逻辑
}
// 创建一个IEnumerator的协程
IEnumerator GameEscapeRoutine(string token)
{
while (true) // 无限循环来实现每2秒发送一次请求
{
yield return new WaitForSeconds(2f); // 每2秒暂停一次
yield return LatestGame511(token); // 调用gameEscape方法
}
yield return null;
}
public async Task LatestGame511(string token)
{
// 用来给请求头赋值
string Authorization = token;
//Debug.Log("Loding(Authorization)请求头赋值" + Authorization);
// 5.1查询最近一场大屠杀
Dictionary<string, string> head51 = new Dictionary<string, string>
{
{ "Authorization", Authorization }, // 设置授权头
};
string response51 = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryLatest", "POST", "{}", head51);
Debug.Log("5.1查询最近一场大屠杀(独立)" + response51); // 查询最近一场大逃亡游戏详情:
// 解析JSON数据
string json = response51;
Response response = JsonConvert.DeserializeObject<Response>(json);
if (response != null && response.code == 200 && response.data != null)
{
gameEscapeId = response.data.gameEscapeModel.id;
//Debug.Log("解析成功id为: " + gameEscapeId);
carrySeconds= response.data.carrySeconds;
// 触发事件,通知所有订阅者
OnGameEscapeIdUpdated?.Invoke(gameEscapeId);
}
else
{
Debug.LogError("解析失败或响应错误");
}
}
void OnDestroy()
{
// 取消监听,避免内存泄漏
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
}
// Update is called once per frame
void Update()
{
}
[Serializable]
public class GameEscapeModel
{
public int id; // 解析游戏ID
public string gameNo; // 包括游戏编号
}
[Serializable]
public class GameEscapeRoomResponseVo
{
public int escapeId; // 逃脱游戏的ID
public int roomNo; // 房间号
}
[Serializable]
public class Data
{
public int carrySeconds; // 持续秒数
public GameEscapeModel gameEscapeModel; // 嵌套的GameEscapeModel对象
public List<GameEscapeRoomResponseVo> gameEscapeRoomResponseVoList; // 房间信息列表
public object gameEscapeUserModel; // 用户模型,可以保持为空或根据需要进行定义
}
[Serializable]
public class Response
{
public int code; // 状态码
public string message; // 返回信息
public Data data; // 数据对象
}
}*/
public class selectLatest511 : MonoBehaviour
{
public int gameEscapeId;
public int carrySeconds;
public string gameNo; // 游戏编号
public int demonMode;
public string startTime;
public string betTime;
public string countTime;
public string settleTime;
public int status;
public string roomNoKill;
public string roomNoRemain;
public float beansCoinAll;
public float beansCoinKill;
public float beansCoinRemain;
public float beansCoinFee;
public float beansCoinRank;
public float beansCoinDivide;
public int escapeId; // 逃脱游戏的ID
public int roomNo; // 房间号
public float roomBeansCoin; // 房间中豆币数量
public static event Action<int> OnGameEscapeIdUpdated;
private string token;
void Start()
{
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
}
async void HandleTokenReceived(string token)
{
this.token = token;
Debug.Log("HandleTokenReceived监听:" + token);
// 异步调用,避免阻塞主线程
await LatestGame511(token);
StartCoroutine(GameEscapeRoutine(token));
}
void HandleGameEscapeIdUpdated(int newGameEscapeId)
{
Debug.Log("GameEscapeId 已更新为: " + newGameEscapeId);
}
IEnumerator GameEscapeRoutine(string token)
{
while (true)
{
yield return new WaitForSeconds(30f);//=============================================================================================
yield return LatestGame511(token);
}
}
public async Task LatestGame511(string token)
{
try
{
string Authorization = token;
Dictionary<string, string> head511 = new Dictionary<string, string>
{
{ "Authorization", Authorization }
};
string response511 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", head511);
Debug.Log("5.1.1查询最近一场大屠杀" + response511);
Response response = JsonConvert.DeserializeObject<Response>(response511);
if (response != null && response.code == 200 && response.data != null)
{
gameEscapeId = response.data.gameEscapeModel.id;
carrySeconds = response.data.carrySeconds;
gameNo = response.data.gameEscapeModel.gameNo;
demonMode = response.data.gameEscapeModel.demonMode;
startTime = response.data.gameEscapeModel.startTime;
betTime = response.data.gameEscapeModel.betTime;
countTime = response.data.gameEscapeModel.countTime;
settleTime = response.data.gameEscapeModel.settleTime;
status = response.data.gameEscapeModel.status;
roomNoKill = response.data.gameEscapeModel.roomNoKill;
roomNoRemain = response.data.gameEscapeModel.roomNoRemain;
beansCoinAll = response.data.gameEscapeModel.beansCoinAll;
beansCoinKill = response.data.gameEscapeModel.beansCoinKill;
beansCoinRemain = response.data.gameEscapeModel.beansCoinRemain;
beansCoinFee = response.data.gameEscapeModel.beansCoinFee;
beansCoinRank = response.data.gameEscapeModel.beansCoinRank;
beansCoinDivide = response.data.gameEscapeModel.beansCoinDivide;
HegemonTime.instance.HadInfAndStartGame();
Debug.Log($"Game Escape ID: {gameEscapeId}");
Debug.Log($"Carry Seconds: {carrySeconds}");
Debug.Log($"Game No: {response.data.gameEscapeModel.gameNo}");
Debug.Log($"Beans Coin All: {response.data.gameEscapeModel.beansCoinAll}");
foreach (var room in response.data.gameEscapeRoomResponseVoList)
{
Debug.Log($"Room No: {room.roomNo}, Room Beans Coin: {room.roomBeansCoin}");
}
OnGameEscapeIdUpdated?.Invoke(gameEscapeId);
}
else
{
Debug.LogError("解析失败或响应错误");
}
}
catch (Exception ex)
{
Debug.LogError("发生异常:" + ex.Message);
}
}
void OnDestroy()
{
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
selectLatest511.OnGameEscapeIdUpdated -= HandleGameEscapeIdUpdated;
}
// 数据类
[Serializable]
public class GameEscapeModel
{
public int id; // 游戏 ID
public string gameNo; // 游戏编号
public int demonMode;
public string startTime;
public string betTime;
public string countTime;
public string settleTime;
public int status;
public string roomNoKill;
public string roomNoRemain;
public float beansCoinAll;
public float beansCoinKill;
public float beansCoinRemain;
public float beansCoinFee;
public float beansCoinRank;
public float beansCoinDivide;
}
[Serializable]
public class GameEscapeRoomResponseVo
{
public int escapeId; // 逃脱游戏的ID
public int roomNo; // 房间号
public float roomBeansCoin; // 房间中豆币数量
}
[Serializable]
public class Data
{
public int carrySeconds; // 持续秒数
public GameEscapeModel gameEscapeModel; // 嵌套的GameEscapeModel对象
public List<GameEscapeRoomResponseVo> gameEscapeRoomResponseVoList; // 房间信息列表
public object gameEscapeUserModel; // 用户模型,可以保持为空或根据需要进行定义
}
[Serializable]
public class Response
{
public int code; // 状态码
public string message; // 返回信息
public Data data; // 数据对象
}
}

View File

@ -92,7 +92,7 @@ using UnityEngine.Networking;
public class web : MonoBehaviour
{
//public const string URL = "http://47.109.133.52"; // 被注释掉的服务器地址(常量)
public const string URL = "http://121.40.42.41:8080"; // 被注释掉的服务器地址(常量)
// 存储服务器返回的Cookie
private static Dictionary<string, string> cookieJar = new Dictionary<string, string>();
@ -100,7 +100,7 @@ public class web : MonoBehaviour
// 发送HTTP请求的方法支持GET和POST等不同的请求方式
public static async Task<string> SendRequest(string url, string method = "GET", string jsonData = "{}", Dictionary<string, string> head = null)
{
//Debug.Log(url + "启动web"); // 调试输出,启动网络请求
Debug.Log(url + "启动web"); // 调试输出,启动网络请求
// 使用UnityWebRequest类进行HTTP请求支持自定义请求方法
using (UnityWebRequest request = new UnityWebRequest(url, method))
{
@ -159,7 +159,7 @@ public class web : MonoBehaviour
// 处理返回的Cookie
string setCookieHeader;
string str = request.downloadHandler.text; // 获取服务器返回的文本内容
Debug.Log(str); // 输出返回内容到控制台
//Debug.Log(str); // 输出返回内容到控制台
// 尝试获取响应头中的“Set-Cookie”字段
if (request.GetResponseHeaders().TryGetValue("Set-Cookie", out setCookieHeader))

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
public class Singleton<T> where T : new()
{
private static T ms_instance;
public static T Instance
{
get
{
if (ms_instance == null)
{
ms_instance = new T();
}
return ms_instance;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 16cc4b16faf87d74d9420c2d330ae178
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class User : Singleton<User>
{
public int userId;
public int escapeId;
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4b2224566a2dc9648b9018480a264525
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: