登录连接服务器

This commit is contained in:
五条悟 2024-11-11 19:48:32 +08:00
parent 63f26053e4
commit 64c766ebd9
32 changed files with 3727 additions and 651 deletions

View File

@ -0,0 +1,378 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 9
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 0
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 12
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings:
serializedVersion: 12
m_Resolution: 2
m_BakeResolution: 40
m_AtlasSize: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_ExtractAmbientOcclusion: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 1
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 512
m_PVRBounces: 2
m_PVREnvironmentSampleCount: 256
m_PVREnvironmentReferencePointCount: 2048
m_PVRFilteringMode: 1
m_PVRDenoiserTypeDirect: 1
m_PVRDenoiserTypeIndirect: 1
m_PVRDenoiserTypeAO: 1
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVREnvironmentMIS: 1
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ExportTrainingData: 0
m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 0}
m_LightingSettings: {fileID: 0}
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
maxJobWorkers: 0
preserveTilesOutsideBounds: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &359877816
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 359877818}
- component: {fileID: 359877817}
m_Layer: 0
m_Name: Directional Light
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!108 &359877817
Light:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 359877816}
m_Enabled: 1
serializedVersion: 10
m_Type: 1
m_Shape: 0
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Intensity: 1
m_Range: 10
m_SpotAngle: 30
m_InnerSpotAngle: 21.80208
m_CookieSize: 10
m_Shadows:
m_Type: 2
m_Resolution: -1
m_CustomResolution: -1
m_Strength: 1
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_CullingMatrixOverride:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
m_UseCullingMatrixOverride: 0
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingLayerMask: 1
m_Lightmapping: 4
m_LightShadowCasterMode: 0
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_UseViewFrustumForShadowCasterCull: 1
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &359877818
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 359877816}
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1001 &951530164
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 100000, guid: c48b72e627b270f47bf78fdbf3fe5f9e, type: 3}
propertyPath: m_StaticEditorFlags
value: 4294967295
objectReference: {fileID: 0}
- target: {fileID: 100002, guid: c48b72e627b270f47bf78fdbf3fe5f9e, type: 3}
propertyPath: m_StaticEditorFlags
value: 4294967295
objectReference: {fileID: 0}
- target: {fileID: 100004, guid: c48b72e627b270f47bf78fdbf3fe5f9e, type: 3}
propertyPath: m_StaticEditorFlags
value: 4294967295
objectReference: {fileID: 0}
- target: {fileID: 100006, guid: c48b72e627b270f47bf78fdbf3fe5f9e, type: 3}
propertyPath: m_StaticEditorFlags
value: 4294967295
objectReference: {fileID: 0}
- target: {fileID: 400000, guid: c48b72e627b270f47bf78fdbf3fe5f9e, type: 3}
propertyPath: m_RootOrder
value: 2
objectReference: {fileID: 0}
- target: {fileID: 400000, guid: c48b72e627b270f47bf78fdbf3fe5f9e, type: 3}
propertyPath: m_LocalScale.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 400000, guid: c48b72e627b270f47bf78fdbf3fe5f9e, type: 3}
propertyPath: m_LocalPosition.x
value: 10.24
objectReference: {fileID: 0}
- target: {fileID: 400000, guid: c48b72e627b270f47bf78fdbf3fe5f9e, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 400000, guid: c48b72e627b270f47bf78fdbf3fe5f9e, type: 3}
propertyPath: m_LocalPosition.z
value: 10.183
objectReference: {fileID: 0}
- target: {fileID: 400000, guid: c48b72e627b270f47bf78fdbf3fe5f9e, type: 3}
propertyPath: m_LocalRotation.w
value: 0.7071071
objectReference: {fileID: 0}
- target: {fileID: 400000, guid: c48b72e627b270f47bf78fdbf3fe5f9e, type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 400000, guid: c48b72e627b270f47bf78fdbf3fe5f9e, type: 3}
propertyPath: m_LocalRotation.y
value: -0.7071065
objectReference: {fileID: 0}
- target: {fileID: 400000, guid: c48b72e627b270f47bf78fdbf3fe5f9e, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 400000, guid: c48b72e627b270f47bf78fdbf3fe5f9e, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: -90
objectReference: {fileID: 0}
- target: {fileID: 400002, guid: c48b72e627b270f47bf78fdbf3fe5f9e, type: 3}
propertyPath: m_LocalScale.y
value: 0.9794112
objectReference: {fileID: 0}
- target: {fileID: 400004, guid: c48b72e627b270f47bf78fdbf3fe5f9e, type: 3}
propertyPath: m_LocalScale.y
value: 0.9794112
objectReference: {fileID: 0}
- target: {fileID: 400006, guid: c48b72e627b270f47bf78fdbf3fe5f9e, type: 3}
propertyPath: m_LocalScale.y
value: 0.9794112
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: c48b72e627b270f47bf78fdbf3fe5f9e, type: 3}
--- !u!1 &1058063114
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1058063117}
- component: {fileID: 1058063116}
- component: {fileID: 1058063115}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &1058063115
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1058063114}
m_Enabled: 1
--- !u!20 &1058063116
Camera:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1058063114}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 0
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!4 &1058063117
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1058063114}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8a8dfa839c09d3c458d35f15166a698a
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9a6fbcb25f39d6640a46b7c511ba064b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 332c5a804d0c33a45a339e85003564f3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,105 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Threading.Tasks;
using System;
public class LoginAndGetToken : MonoBehaviour
{
public delegate void TokenReceivedDelegate(string token);
public static event TokenReceivedDelegate OnTokenReceived;
private void OnEnable()
{
Login();
}
public async void Login()
{
// ... 登录逻辑 ...
loginbody body = new loginbody();
body.userName = "15151658596";// + 15151658596;
body.password = "123456";// + 123456;
body.verifyCode = 111111;
string loginResponse = await web.SendRequest("http://121.40.42.41:8080/snail/user/login", "POST", JsonUtility.ToJson(body));
Debug.Log("LoginAndGetToken登录:"+loginResponse);
string token = getToken(loginResponse);
OnTokenReceived?.Invoke(token);
//登录请求//已通过
}
public static string getToken(string json)
{
try
{
// 解析JSON字符串为JObject
JObject parsedJson = JObject.Parse(json);
// 从JObject中提取token字段的值
string token = parsedJson["data"]?["token"]?.ToString();
// 返回token
return token;
}
catch (Exception ex)
{
// 处理解析过程中可能出现的异常
Console.WriteLine("An error occurred while parsing the JSON: " + ex.Message);
return null;
}
}
[Serializable]
public class loginbody//登录和注册用
{
public string userName;
public string password;
public int verifyCode;
}
}
/*public class LoginAndGetToken : MonoBehaviour
{
private static LoginAndGetToken _instance;
public static LoginAndGetToken Instance
{
get
{
if (_instance == null)
{
GameObject obj = new GameObject("LoginAndGetToken");
_instance = obj.AddComponent<LoginAndGetToken>();
DontDestroyOnLoad(obj); // 确保单例在场景加载时不会被销毁
}
return _instance;
}
}
private string _token;
public async void Login()
{
loginbody body = new loginbody();
body.userName = "15151658596";
body.password = "123456";
body.verifyCode = 111111;
string loginResponse = await web.SendRequest("http://121.40.42.41:8080/snail/user/login", "POST", JsonUtility.ToJson(body));
Debug.Log(loginResponse);
_token = getToken(loginResponse);
}
public static string GetToken()
{
return Instance._token;
}
public static string getToken(string loginResponse)
{
JObject jsonObject = JObject.Parse(loginResponse);
string token = (string)jsonObject["data"]?["token"];
Debug.Log(token);
return token;
}
}*/

View File

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

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 03022718ac185d44aa0456004971c927
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,91 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using static LoginAndGetToken;
public class logoPanel : MonoBehaviour
{
public Button pwdBtn;
public Button yzmBtn;
public GameObject sjh;
public GameObject yzm;
public GameObject mm;
public GameObject zh;
public Button loginBtn;
public Button rigistBtn;
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);
}
private void OnClickRigistBtn()
{
}
//点击登录按钮
private IEnumerator OnClickLoginBtn()
{
loginbody body = new loginbody
{
userName = "15151658596",
password = "123456",
verifyCode = 111111
};
string jsonBody = JsonUtility.ToJson(body);
using (UnityWebRequest webRequest = UnityWebRequest.Post("http://121.40.42.41:8080/snail/user/login", jsonBody))
{
webRequest.SetRequestHeader("Content-Type", "application/json");
webRequest.uploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(jsonBody));
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);
yzmBtn.transform.position += new Vector3(0f, 26.4f, 0f);
sjh.gameObject.SetActive(true);
yzm.gameObject.SetActive(true);
mm.gameObject.SetActive(false);
zh.gameObject.SetActive(false);
}
//点击密码按钮
private void OnClickPwdBtn()
{
pwdBtn.transform.position += new Vector3(0f, 26.4f, 0f);
yzmBtn.transform.position -= new Vector3(0f, 26.4f, 0f);
sjh.gameObject.SetActive(false);
yzm.gameObject.SetActive(false);
mm.gameObject.SetActive(true);
zh.gameObject.SetActive(true);
}
}

View File

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

View File

@ -0,0 +1,193 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml.Linq;
using UnityEngine;
using UnityEngine.Networking;
using System.Threading.Tasks;
public class WebConnact : MonoBehaviour
{
void Start()
{
//由于除登录注册外的其他方法都需要登录后返回的token
//因此登录不在此发送请求(同时)
//采用监听和事件回调的方法只有监听到登录和token返回时才运行其他方法
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
//Loding();
}
void HandleTokenReceived(string token)
{
// 使用 token
//string loginToken=token;
Debug.Log("HandleTokenReceived:"+token);
Loding(token);
}
public async void Loding(string token)
{
//用来给请求头赋值
string Authorization = token;
Debug.Log("Loding(Authorization)"+Authorization);
//loginbody body = new loginbody();
//body.userName = "15151658596";// + 15151658596;
//body.password = "123456";// + 123456;
//body.verifyCode = 111111;
//string regisestrespose = await web.SendRequest("http://121.40.42.41:8080/snail/user/register", "POST", JsonUtility.ToJson(body));
//Debug.Log(regisestrespose);
//注册请求 //已通过
//loginbody body = new loginbody();
//body.userName = "15151658596";// + 15151658596;
//body.password = "123456";// + 123456;
//body.verifyCode = 111111;
//string loginResponse = await web.SendRequest("http://121.40.42.41:8080/snail/user/login", "POST", JsonUtility.ToJson(body));
//Debug.Log(loginResponse);
//登录请求//已通过
//1.3,完善用户信息
// User_InformationHead user = new User_InformationHead();
// Dictionary<string, string> head13 = new Dictionary<string, string>
//{
// { "Authorization", Authorization }, // 设置授权头
// };
// user.nickName = "wulongxiao";
// user.headImg = "https://fantasymonster-app.oss-cn-hangzhou.aliyuncs.com/upload/imgs/127e4e42d7c0405aab53359c1b278a9c.png";
// user.gender = "男";
// user.birthday = "20010506";
// string UserNewInfoBody = "{\"nickName\":\"wulongxiao\",\"headImg\":\"https://fantasymonster-app.oss-cn-hangzhou.aliyuncs.com/upload/imgs/127e4e42d7c0405aab53359c1b278a9c.png\",\"gender\":\"男\",\"birthday\":\"20010506\"}";
// string response13 = await web.SendRequest("http://121.40.42.41:8080/snail/user/update", "POST", UserNewInfoBody, head13);
// Debug.Log(response13);
//Mall_List mall_virtual = new Mall_List();
//mall_virtual.productType = 0;
//mall_virtual.pageNo = 1;
//mall_virtual.pageSize = 20;
//string mall_virtualponse = await web.SendRequest("http://121.40.42.41:8080/snail/product/page", "POST", JsonUtility.ToJson(mall_virtual));
//Debug.Log(mall_virtualponse);
//Mall_List mall = new Mall_List();
//mall.productType = 1;
////mall.pageNo = 1;
////mall.pageSize = 20;//这两个属性是默认值可以省略不写默认是1跟20
//string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/page", "POST", JsonUtility.ToJson(mall));
//Debug.Log(response);
//Product_Details product = new Product_Details();
//product.productId = 1;
//string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/info", "POST", JsonUtility.ToJson(product));
//Debug.Log(response);
// Mall_buy mall_Buy = new Mall_buy();
//string Authorization = "7083e9cb0de74c9dbb3c02f37ec339b8";
// mall_Buy.userId = 106;
// mall_Buy.productId = 1;
// string response = await web.SendRequest("http://121.40.42.41:8080/snail/product/buy", "POST", JsonUtility.ToJson(mall_Buy),Authorization);
// Debug.Log(response);
//Query_Announcement query_Announcement = new Query_Announcement();
//query_Announcement.userId = 106;
//query_Announcement.pageNo = 1;
//query_Announcement.pageSize = 20;
//string response = await web.SendRequest("http://121.40.42.41:8080/snail/notice/page", "POST", JsonUtility.ToJson(query_Announcement));
//Debug.Log(response);
//string response = await web.SendRequest($"http://121.40.42.41:8080/snail/notice/info?noticeId=${公告id}", "Get");
//Debug.Log(response);
//5.1查询最近一场大屠杀
// Dictionary<string, string> head51 = new Dictionary<string, string>
//{
// { "Authorization", Authorization }, // 设置授权头
// };
// //head.Add("Authorization", token);
// string response51 = await web.SendRequest("http://121.40.42.41:8080/snail/gameEscape/queryLatest", "POST", "{}", head51);
// Debug.Log(response51);//查询最近一场大逃亡游戏详情:
//已通过
//===========================================getToken================================================================================
}
void OnDestroy()
{
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
}
// Update is called once per frame
void Update()
{
}
}
[Serializable]
public class Search_room//登录和注册用
{
public int userId;
}
//[Serializable]
//public class loginbody//登录和注册用
//{
// public string userName;
// public string password;
// public int verifyCode;
//}
[System.Serializable]
public class User_InformationHead //完善用户信息
{
public string nickName;
public string headImg;
public string gender;
public string birthday;
}
[Serializable]
public class Query_Announcement //查询公告分页
{
public int userId;
public int pageNo;
public int pageSize;
}
[Serializable]
public class Mall_List //获取商城列表
{
public int productType;
public int pageNo;
public int pageSize;
}
[Serializable]
public class Product_Details//商品详情,有问题
{
public int productId;
}
[Serializable]
public class Mall_buy
{ public int productId;
public int userId;
}

View File

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

View File

@ -0,0 +1,188 @@
using Newtonsoft.Json.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Unity.VisualScripting.Antlr3.Runtime;
using UnityEngine;
using UnityEngine.Networking;
/*public class web : MonoBehaviour
{
//public const string URL = "http://47.109.133.52";
// 存储服务器返回的Cookie
private static Dictionary<string, string> cookieJar = new Dictionary<string, string>();
public static async Task<string> SendRequest(string url,string method = "GET",string jsonData = "{}", Dictionary<string,string> head = null)
{
//Debug.Log(url + "启动web");
using (UnityWebRequest request = new UnityWebRequest(url, method))
{
// 设置下载处理器
request.downloadHandler = new DownloadHandlerBuffer();
// 如果是POST请求设置请求体
if (method == "POST" && jsonData != null)
{
byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonData);
request.uploadHandler = new UploadHandlerRaw(bodyRaw);
request.SetRequestHeader("Content-Type", "application/json");
}
//设置请求头
if (head != null)
foreach (string key in head.Keys)
{
//request.SetRequestHeader("Authorization", token);
request.SetRequestHeader(key, head[key]);
}
// 设置已存储的 Cookie
if (cookieJar.Count > 0)
{
string cookieHeader = "";
foreach (var cookie in cookieJar)
{
cookieHeader += $"{cookie.Key}={cookie.Value}; ";
}
request.SetRequestHeader("Cookie", cookieHeader);
}
// 发送请求并等待响应
var operation = request.SendWebRequest();
while (!operation.isDone)
await Task.Yield();
if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError)
{
Debug.LogError($"Error: {request.error}" + url);
//Promptmgr.Instance.PromptBubble(request.error, Color.black,Color.red);
return null;
}
else
{
// 处理返回的Cookie
string setCookieHeader;
string str = request.downloadHandler.text;
Debug.Log(str);
if (request.GetResponseHeaders().TryGetValue("Set-Cookie", out setCookieHeader))
{
string[] cookies = setCookieHeader.Split(';');
foreach (var cookie in cookies)
{
var cookieParts = cookie.Split('=');
if (cookieParts.Length == 2)
{
string key = cookieParts[0].Trim();
string value = cookieParts[1].Trim();
cookieJar[key] = value;
}
}
}
// 返回响应内容
return request.downloadHandler.text;
}
}
}
}*/
public class web : MonoBehaviour
{
//public const string URL = "http://47.109.133.52"; // 被注释掉的服务器地址(常量)
// 存储服务器返回的Cookie
private static Dictionary<string, string> cookieJar = new Dictionary<string, string>();
// 发送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"); // 调试输出,启动网络请求
// 使用UnityWebRequest类进行HTTP请求支持自定义请求方法
using (UnityWebRequest request = new UnityWebRequest(url, method))
{
// 设置下载处理器,用于处理服务器响应的数据
request.downloadHandler = new DownloadHandlerBuffer();
// 如果是POST请求设置请求体
if (method == "POST" && jsonData != null)
{
// 将JSON字符串转换为字节数组
byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonData);
// 设置上传处理器,用于发送请求体数据
request.uploadHandler = new UploadHandlerRaw(bodyRaw);
// 设置请求头指定请求体内容类型为JSON
request.SetRequestHeader("Content-Type", "application/json");
}
// 如果请求头部存在,添加请求头部信息
if (head != null)
foreach (string key in head.Keys)
{
// 遍历传入的头部字典,逐项设置请求头部
request.SetRequestHeader(key, head[key]);
}
// 设置已存储的 Cookie
if (cookieJar.Count > 0)
{
// 用于存储多个cookie值的字符串
string cookieHeader = "";
foreach (var cookie in cookieJar)
{
// 格式化每个cookie为“键=值”的形式,并附加到字符串中,以分号分隔
cookieHeader += $"{cookie.Key}={cookie.Value}; ";
}
// 设置请求头中的Cookie字段
request.SetRequestHeader("Cookie", cookieHeader);
}
// 发送请求并等待响应
var operation = request.SendWebRequest();
while (!operation.isDone)
await Task.Yield(); // 等待请求完成使用await以非阻塞的方式处理
// 检查是否存在网络错误或协议错误
if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError)
{
// 如果有错误输出错误信息并返回null
Debug.LogError($"Error: {request.error}" + url);
// 可以自定义弹窗提示用户错误信息,代码被注释掉了
// Promptmgr.Instance.PromptBubble(request.error, Color.black,Color.red);
return null;
}
else
{
// 处理返回的Cookie
string setCookieHeader;
string str = request.downloadHandler.text; // 获取服务器返回的文本内容
Debug.Log(str); // 输出返回内容到控制台
// 尝试获取响应头中的“Set-Cookie”字段
if (request.GetResponseHeaders().TryGetValue("Set-Cookie", out setCookieHeader))
{
// 将“Set-Cookie”字段的内容按分号分隔为多个部分
string[] cookies = setCookieHeader.Split(';');
foreach (var cookie in cookies)
{
// 将每个cookie分为“键=值”的形式
var cookieParts = cookie.Split('=');
if (cookieParts.Length == 2)
{
string key = cookieParts[0].Trim(); // 去掉键的空格
string value = cookieParts[1].Trim(); // 去掉值的空格
// 存储到cookieJar中以备后续请求使用
cookieJar[key] = value;
}
}
}
// 返回响应内容(文本形式)
return request.downloadHandler.text;
}
}
}
}

View File

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

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 02e9e3f632102f84f80ba083f2dd5793
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2a62834044b6301478aca6c588d8e3e1
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 1078258c1c6aa234784686e9cd39744c
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,21 @@
fileFormatVersion: 2
guid: bf1c9e1bcf09e2a4dba44bbe6cc2ba38
TrueTypeFontImporter:
externalObjects: {}
serializedVersion: 4
fontSize: 16
forceTextureCase: -2
characterSpacing: 0
characterPadding: 1
includeFontData: 1
fontNames:
- Alibaba PuHuiTi 3.0
fallbackFontReferences: []
customCharacters:
fontRenderingMode: 0
ascentCalculationMode: 1
useLegacyBoundsCalculation: 0
shouldRoundAdvanceValue: 1
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,21 @@
fileFormatVersion: 2
guid: 2b9a1661cb3817f4aa386a4f9407956c
TrueTypeFontImporter:
externalObjects: {}
serializedVersion: 4
fontSize: 16
forceTextureCase: -2
characterSpacing: 0
characterPadding: 1
includeFontData: 1
fontNames:
- Alibaba PuHuiTi 3.0
fallbackFontReferences: []
customCharacters:
fontRenderingMode: 0
ascentCalculationMode: 1
useLegacyBoundsCalculation: 0
shouldRoundAdvanceValue: 1
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 6e3a21febf4715d42a7a7be596b0c9d1
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8433bcc513ef3d64fad0efca0651c882
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 739ca9371694ff246af9ea688326b481
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1 @@
验证码手机号登录密码登录手机号验证码立刻登录获取验证码没有账号?立即点击注册

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 85b31773c781d2647a4923cd4dbd508b
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: