This commit is contained in:
MuHua-123
2025-06-23 14:38:10 +08:00
parent 39d9db9c6d
commit 0cc63a7314
51 changed files with 2032 additions and 68 deletions
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 253123fa56cb88f4e969b587327d3f7f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+46
View File
@@ -0,0 +1,46 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 用户
/// </summary>
[Serializable]
public class DataUser {
public string id;
public string username;
public string passwordhash;
}
/// <summary>
/// 注册请求
/// </summary>
[Serializable]
public class DataRegisterRequest {
public string username;
public string password;
}
/// <summary>
/// 登录请求
/// </summary>
[Serializable]
public class DataLoginRequest {
public string username;
public string password;
}
/// <summary>
/// 登录响应,返回JWT。
/// </summary>
[Serializable]
public class DataLoginResponse {
public string token;
}
/// <summary>
/// 修改密码请求。
/// </summary>
[Serializable]
public class DataChangePasswordRequest {
public string username;
public string oldpassword;
public string newpassword;
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 202f1c0d7338943458d837082537020b
guid: febe432c83103fd4fbbc833bc7dd08cd
MonoImporter:
externalObjects: {}
serializedVersion: 2
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ebf768e6a16ccf04da50e6e25559a8f6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,43 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MuHua;
/// <summary>
/// 请求 - 管理器
/// </summary>
public class ManagerRequest : ModuleSingle<ManagerRequest> {
/// <summary> 域名 </summary>
public static string Address => "http://localhost:5086";
protected override void Awake() => NoReplace(false);
#region
/// <summary> 登录 </summary>
public void Login(string username, string password, Action<string> callback) {
string url = Address + "/api/user/login";
DataLoginRequest login = new DataLoginRequest { username = username, password = password };
PostForm(url, login, callback);
}
#endregion
#region
public void PostForm<T>(string url, T data, Action<string> callback) {
string json = JsonTool.ToJson(data);
Debug.Log(json);
DataRequestPost request = new DataRequestPost(url, json);
request.OnError = (json) => { ErrorHandle(url, json); };
request.OnCallback = callback;
NetworkRequestAsync.Execute(request);
}
#endregion
#region
/// <summary> 错误处理 </summary>
private void ErrorHandle(string url, string json) {
Debug.LogError($"{url} \n {json}");
}
#endregion
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 545cbb8d4e1482749bc6b9ae168407c4
guid: 2b4112fa4a2bfe84984b0472be3af46c
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -0,0 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MuHua;
/// <summary>
/// 全局管理器
/// </summary>
public class SingleManager : ModuleSingle<SingleManager> {
protected override void Awake() => NoReplace();
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 50f6b4ec374a86846b626668e0b5627e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+3 -2
View File
@@ -20,11 +20,12 @@ public class ModuleUI : ModuleSingle<ModuleUI> {
protected override void Awake() => NoReplace();
/// <summary> 跳转页面 </summary>
public static void Jump(EnumPage pageType) => OnJumpPage?.Invoke(pageType);
public static void Settings(EnumPage pageType) => OnJumpPage?.Invoke(pageType);
}
/// <summary>
/// 页面
/// </summary>
public enum EnumPage {
None,
Login,
}
@@ -0,0 +1,96 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
using MuHua;
/// <summary>
/// 登录页面
/// </summary>
public class UILoginPage : ModuleUIPage {
private UILoginPanel loginPanel;
private UIRegisterPanel registerPanel;
public override VisualElement Element => root.Q<VisualElement>("LoginPage");
public VisualElement LoginPanel => Q<VisualElement>("LoginPanel");
public VisualElement RegisterPanel => Q<VisualElement>("RegisterPanel");
private void Awake() {
loginPanel = new UILoginPanel(LoginPanel, this);
registerPanel = new UIRegisterPanel(RegisterPanel, this);
ModuleUI.OnJumpPage += ModuleUI_OnJumpPage;
}
private void ModuleUI_OnJumpPage(EnumPage page) {
Element.EnableInClassList("document-page-hide", page != EnumPage.Login);
if (page != EnumPage.Login) { return; }
OpenLoginPanel();
}
public void OpenLoginPanel() {
loginPanel.Resetting(false);
registerPanel.Resetting(true);
}
public void OpenRegisterPanel() {
loginPanel.Resetting(true);
registerPanel.Resetting(false);
}
}
/// <summary>
/// 登录面板
/// </summary>
public class UILoginPanel : ModuleUIPanel {
private string username;
private string password;
public Label Title => Q<Label>("Title");
public UITextField InputField1 => Q<UITextField>("InputField1");
public UITextField InputField2 => Q<UITextField>("InputField2");
public Button Button1 => Q<Button>("Button1");
public Button Button2 => Q<Button>("Button2");
public UILoginPanel(VisualElement element, UILoginPage parent) : base(element) {
InputField1.RegisterCallback<ChangeEvent<string>>(evt => { username = evt.newValue; });
InputField2.RegisterCallback<ChangeEvent<string>>(evt => { password = evt.newValue; });
Button1.clicked += () => parent.OpenRegisterPanel();
Button2.clicked += () => ManagerRequest.I.Login(username, password, (s) => {
ModuleUI.Settings(EnumPage.None);
Debug.Log(s);
});
}
public void Resetting(bool isHide) {
InputField1.value = username = "";
InputField2.value = password = "";
element.EnableInClassList("login-hide", isHide);
}
}
/// <summary>
/// 注册面板
/// </summary>
public class UIRegisterPanel : ModuleUIPanel {
private string username;
private string password;
public Label Title => Q<Label>("Title");
public UITextField InputField1 => Q<UITextField>("InputField1");
public UITextField InputField2 => Q<UITextField>("InputField2");
public Button Button1 => Q<Button>("Button1");
public Button Button2 => Q<Button>("Button2");
public UIRegisterPanel(VisualElement element, UILoginPage parent) : base(element) {
InputField1.RegisterCallback<ChangeEvent<string>>(evt => { username = evt.newValue; });
InputField2.RegisterCallback<ChangeEvent<string>>(evt => { password = evt.newValue; });
Button1.clicked += () => parent.OpenLoginPanel();
Button2.clicked += () => { };
}
public void Resetting(bool isHide) {
InputField1.value = "";
InputField2.value = "";
element.EnableInClassList("login-hide", isHide);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 71f4d873d8595a04b9f0e23ece70c12f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,41 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
using MuHua;
/// <summary>
/// 滚动视图 - 测试页面
/// </summary>
public class UIScrollViewTestPage : ModuleUIPage {
private UIScrollViewV scrollView1;
private UIScrollViewV scrollView2;
private UIScrollViewH scrollView3;
private UIScrollViewH scrollView4;
private UIScrollView scrollView5;
public VisualElement ScrollView1 => Q<VisualElement>("ScrollView1");
public VisualElement ScrollView2 => Q<VisualElement>("ScrollView2");
public VisualElement ScrollView3 => Q<VisualElement>("ScrollView3");
public VisualElement ScrollView4 => Q<VisualElement>("ScrollView4");
public VisualElement ScrollView5 => Q<VisualElement>("ScrollView5");
public override VisualElement Element => root;
private void Awake() {
scrollView1 = new UIScrollViewV(ScrollView1, root, UIScrollViewV.UIDirection.FromTopToBottom);
scrollView2 = new UIScrollViewV(ScrollView2, root, UIScrollViewV.UIDirection.FromBottomToTop);
scrollView3 = new UIScrollViewH(ScrollView3, root, UIScrollViewH.UIDirection.FromLeftToRight);
scrollView4 = new UIScrollViewH(ScrollView4, root, UIScrollViewH.UIDirection.FromRightToLeft);
scrollView5 = new UIScrollView(ScrollView5, root);
}
private void Update() {
scrollView1.Update();
scrollView2.Update();
scrollView3.Update();
scrollView4.Update();
scrollView5.Update();
}
}
@@ -1,36 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
using MuHua;
/// <summary>
/// 滑动条 - 测试页面
/// </summary>
public class UISliderTestPage : ModuleUIPage {
private UISliderH sliderH1;
private UISliderH sliderH2;
private UISliderV sliderV1;
private UISliderV sliderV2;
public VisualElement SliderH1 => Q<VisualElement>("SliderH1");
public VisualElement SliderH2 => Q<VisualElement>("SliderH2");
public VisualElement SliderV1 => Q<VisualElement>("SliderV1");
public VisualElement SliderV2 => Q<VisualElement>("SliderV2");
public override VisualElement Element => root;
private void Awake() {
sliderH1 = new UISliderH(SliderH1, root, UISliderH.UIDirection.FromLeftToRight);
sliderH2 = new UISliderH(SliderH2, root, UISliderH.UIDirection.FromRightToLeft);
sliderV1 = new UISliderV(SliderV1, root, UISliderV.UIDirection.FromTopToBottom);
sliderV2 = new UISliderV(SliderV2, root, UISliderV.UIDirection.FromBottomToTop);
}
private void Update() {
sliderH1.Update();
sliderH2.Update();
sliderV1.Update();
sliderV2.Update();
}
}