Files
plugin-library/Assets/00.BuildOriginality/Editor/Login/LoginAssetWindow.cs
zhangzheng f055116d4d 111
2026-01-05 18:26:50 +08:00

121 lines
3.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Threading.Tasks;
using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;
using Stary.Evo.BuildOriginality;
using Stary.Evo.Editor;
using UnityEditor;
using UnityEngine;
namespace Stary.Evo
{
[InitializeOnLoad]
public class LoginAssetWindow : OdinEditorWindow
{
[MenuItem("Evo/登录", false, 0)]
static void Init()
{
var window = (LoginAssetWindow)EditorWindow.GetWindow(typeof(LoginAssetWindow));
window.Show();
}
[ShowIf("IsLogin")] [BoxGroup("Login", showLabel: false)] [OnValueChanged("SetWebRequestInfo")]
public string ip, userName, password;
private HotfixMainResDomain hotfixMainResDomain;
private BuildAssetType buildAssetType;
private string message;
protected override async void Initialize()
{
base.Initialize();
//初始化读取资源配置表
hotfixMainResDomain = Resources.Load<HotfixMainResDomain>("HotfixMainResDomain");
if (hotfixMainResDomain == null)
{
Debug.LogError($"UnityEvo:读取资源配置表失败【HotfixMainResDomain】...表在Resources下不存在请创建");
}
else
{
ip = hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig;
EditorPrefs.SetString("ip", ip);
userName = hotfixMainResDomain.hotfixMainResDomainEntity.username;
password = hotfixMainResDomain.hotfixMainResDomainEntity.password;
}
bool isValidateToken = await WebRequestSystem.GetValidateToken(ip + "/Authentication/validateToken");
if (isValidateToken)
{
buildAssetType = BuildAssetType.Build;
message = "已登录";
return;
}
buildAssetType = BuildAssetType.Login;
message = "未登录";
}
[ShowIf("IsLogin")]
[BoxGroup("Login", showLabel: false)]
[Button("登录", ButtonSizes.Large)]
[InfoBox("@ message", InfoMessageType.Info)]
public async void LoginButton()
{
string url = ip + "/Authentication/login";
EditorUtility.DisplayProgressBar("提示", $"登陆中~", 0f);
bool islogin = await WebRequestSystem.Login(url, userName, password);
float progress = 0f;
while (progress >= 1f)
{
progress += 0.1f;
EditorUtility.DisplayProgressBar("提示", $"登陆中~", progress);
await Task.Delay(TimeSpan.FromSeconds(0.2f));
}
if (islogin)
{
buildAssetType = BuildAssetType.Build;
message = "已登录";
}
else
{
buildAssetType = BuildAssetType.Login;
message = "未登录";
}
EditorUtility.ClearProgressBar();
}
[HideIf("IsLogin")]
[Button("退出登录", ButtonSizes.Large)]
[InfoBox("@ message", InfoMessageType.Info)]
public void ExitLoginButton()
{
buildAssetType = BuildAssetType.Login;
message = "未登录";
EditorPrefs.DeleteKey("Authorization");
}
private void SetWebRequestInfo()
{
if (hotfixMainResDomain != null)
{
hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig = ip;
hotfixMainResDomain.hotfixMainResDomainEntity.username = userName;
hotfixMainResDomain.hotfixMainResDomainEntity.password = password;
EditorPrefs.SetString("ip", ip);
EditorUtility.SetDirty(hotfixMainResDomain);
AssetDatabase.SaveAssets();
}
}
private bool IsLogin()
{
return buildAssetType == BuildAssetType.Login;
}
}
}