_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/LqUiScripts/EditPanel.cs
2024-12-13 09:59:41 +08:00

125 lines
4.1 KiB
C#

using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class EditPanel : Base
{
public UserInfomation14 userInfomation14;
public InputField UserInputField;
public Text username;
public PerSonalCenterPanel perSonalCenterPanel;
public Button avatar;
// Start is called before the first frame update
async void Start()
{
Dictionary<string, string> head14 = new Dictionary<string, string>
{
{ "Authorization", Global.global.serverResponse.data.token }
};
// 异步查询玩家信息
string response14 = await web.SendRequest(web.URL + "/snail/user/queryUserInfo", "POST", "{}", head14);
Debug.Log("1.4查询玩家信息" + response14);
userInfomation14 = JsonConvert.DeserializeObject<UserInfomation14>(response14);
username.text = "" + userInfomation14.data.nickName;
avatar.onClick.AddListener(selectavatar);
}
void selectavatar()
{
PickImage(512);
}
private void PickImage(int maxSize)
{
NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
{
Debug.Log("Image path: " + path);
if (path != null)
{
// Create Texture from selected image
Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize);
if (texture == null)
{
Debug.Log("Couldn't load texture from " + path);
return;
}
// Assign texture to a temporary quad and destroy it after 5 seconds
GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad);
quad.transform.position = Camera.main.transform.position + Camera.main.transform.forward * 2.5f;
quad.transform.forward = Camera.main.transform.forward;
quad.transform.localScale = new Vector3(1f, texture.height / (float)texture.width, 1f);
Material material = quad.GetComponent<Renderer>().material;
if (!material.shader.isSupported) // happens when Standard shader is not included in the build
material.shader = Shader.Find("Legacy Shaders/Diffuse");
material.mainTexture = texture;
Destroy(quad, 5f);
// If a procedural texture is not destroyed manually,
// it will only be freed after a scene change
Destroy(texture, 5f);
}
});
Debug.Log("Permission result: " + permission);
}
// Update is called once per frame
void Update()
{
}
public async void SetEditPanel()
{
Dictionary<string, string> head13 = new Dictionary<string, string>
{
{ "Authorization", Global.global.serverResponse.data.token }
};
ChangeDetailbody body= new ChangeDetailbody();
body.nickName = UserInputField.text;
Debug.Log(UserInputField.text);
body.birthday = userInfomation14.data.birthday;
body.gender= userInfomation14.data.gender;
body.headImg = userInfomation14.data.headImg;
Debug.Log("入参"+ JsonUtility.ToJson(body));
string loginResponse = await web.SendRequest(web.URL + "/snail/user/update", "POST", JsonUtility.ToJson(body), head13);
ChangeReturn response = JsonUtility.FromJson<ChangeReturn>(loginResponse);
if (response.code==200)
{
Debug.Log("1.3完善用户信息"+ loginResponse);
perSonalCenterPanel.GetPlayerInfo();
Global.global.scene_Main_Jiekou.getPlayerInfo();
}
else
{
addEventPopUp(response.message);
}
Debug.Log(response);
transform.gameObject.SetActive(false);
}
}
public class ChangeDetailbody//登录和注册用
{
public string nickName = "";
public string headImg = "";
public int gender = 0;
public string birthday = "";
}
public class ChangeReturn
{
public int code;
public string message;
public bool data;
}