_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/LqUiScripts/EditPanel.cs

125 lines
4.1 KiB
C#
Raw Normal View History

2024-12-10 12:01:29 +08:00
using Newtonsoft.Json;
2024-11-25 22:18:57 +08:00
using System.Collections;
using System.Collections.Generic;
2024-12-10 12:01:29 +08:00
using TMPro;
2024-11-25 22:18:57 +08:00
using UnityEngine;
2024-12-10 12:01:29 +08:00
using UnityEngine.SceneManagement;
2024-11-25 22:18:57 +08:00
using UnityEngine.UI;
2024-12-10 12:01:29 +08:00
public class EditPanel : Base
2024-11-25 22:18:57 +08:00
{
2024-12-10 12:01:29 +08:00
public UserInfomation14 userInfomation14;
public InputField UserInputField;
public Text username;
public PerSonalCenterPanel perSonalCenterPanel;
2024-12-13 09:59:41 +08:00
public Button avatar;
2024-11-25 22:18:57 +08:00
// Start is called before the first frame update
2024-12-10 12:01:29 +08:00
async void Start()
2024-11-25 22:18:57 +08:00
{
2024-12-10 12:01:29 +08:00
Dictionary<string, string> head14 = new Dictionary<string, string>
{
{ "Authorization", Global.global.serverResponse.data.token }
};
// <20><EFBFBD><ECB2BD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
string response14 = await web.SendRequest(web.URL + "/snail/user/queryUserInfo", "POST", "{}", head14);
Debug.Log("1.4<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ" + response14);
userInfomation14 = JsonConvert.DeserializeObject<UserInfomation14>(response14);
username.text = "" + userInfomation14.data.nickName;
2024-12-13 09:59:41 +08:00
avatar.onClick.AddListener(selectavatar);
}
void selectavatar()
{
PickImage(512);
2024-11-25 22:18:57 +08:00
}
2024-12-13 09:59:41 +08:00
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;
}
2024-11-25 22:18:57 +08:00
2024-12-13 09:59:41 +08:00
// 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);
}
2024-11-25 22:18:57 +08:00
// Update is called once per frame
void Update()
{
}
2024-12-10 12:01:29 +08:00
public async void SetEditPanel()
2024-11-25 22:18:57 +08:00
{
2024-12-10 12:01:29 +08:00
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("<22><><EFBFBD><EFBFBD>"+ 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<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>Ϣ"+ loginResponse);
perSonalCenterPanel.GetPlayerInfo();
2024-12-10 12:16:31 +08:00
Global.global.scene_Main_Jiekou.getPlayerInfo();
2024-12-10 12:01:29 +08:00
}
else
{
addEventPopUp(response.message);
}
Debug.Log(response);
2024-11-25 22:18:57 +08:00
transform.gameObject.SetActive(false);
}
}
2024-12-10 12:01:29 +08:00
public class ChangeDetailbody//<2F><>¼<EFBFBD><C2BC>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
{
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;
}