Files
BabyVideo/Assets/Scripts/UI/LoginPanel.cs
2026-02-12 22:15:15 +08:00

84 lines
2.5 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.Collections.Generic;
using FairyGUI;
using UnityEngine;
using NBC;
using UIPanel = NBC.UIPanel;
namespace NBF
{
public partial class LoginPanel : UIPanel
{
private string serverUrl;
private string serverPassword;
private bool autoLogin = true;
protected override void OnInit()
{
this.AutoAddClick(OnClick);
}
protected override void OnShowed()
{
InputServer.Input.promptText = "请输入服务器地址";
InputPass.Input.promptText = "请输入服务器密码";
serverUrl = PlayerPrefs.GetString("serverUrl", string.Empty);
serverPassword = PlayerPrefs.GetString("serverPassword", string.Empty);
InputServer.Input.text = serverUrl;
InputPass.Input.text = serverPassword;
if (!string.IsNullOrEmpty(serverUrl) && !string.IsNullOrEmpty(serverPassword))
{
if (autoLogin) Connect();
}
}
private void OnClick(GComponent btn)
{
if (btn == BtnLogin)
{
if (!string.IsNullOrEmpty(InputPass.Input.text))
{
serverPassword = InputPass.Input.text;
}
if (!string.IsNullOrEmpty(InputServer.Input.text))
{
serverUrl = InputServer.Input.text;
}
Connect();
// Notices.Show("测试========----------的首发式地方");
// MessageBox.ShowMessage("啊撒旦立刻就了",(b =>
// {
// Log.Info($"b={b}");
// }));
}
}
private void Connect()
{
Net.Instance.SetServer(serverUrl, serverPassword);
PlayerPrefs.SetString("serverUrl", serverUrl);
PlayerPrefs.SetString("serverPassword", serverPassword);
// PlayerPanel.Show();
autoLogin = false;
Net.Instance.Tick(0, 0, 0, (ret) =>
{
if (ret.Code == 0)
{
// PlayerPanel.Show();
VideoEditorPanel.Show();
}
else
{
MessageBox.ShowMessage("无法连接服务器,请检查服务器信息\n格式192.168.0.120:9888", null);
}
});
}
}
}