43 lines
1.8 KiB
C#
43 lines
1.8 KiB
C#
using UnityEngine;
|
||
|
||
// 内网联调:发现失败时的开发机 IP 输入框(纯 IMGUI,风格同热更层 DevServerSwitchUI)。
|
||
// 只负责输入与三态状态机,不做网络/文件 IO——探测与写配置由 LoadDll.CoLocalDiscoverThenDownload 编排:
|
||
// [确定] → Confirmed,外部拿 InputIp 去探测;失败则外部调 ResetToWaiting(错误文案) 拨回弹框;
|
||
// [跳过] → Skipped,外部走 127.0.0.1 回退。
|
||
public sealed class DevServerPrompt : MonoBehaviour
|
||
{
|
||
public enum PromptState { Waiting, Confirmed, Skipped }
|
||
|
||
public PromptState State { get; private set; } = PromptState.Waiting;
|
||
public string InputIp = "";
|
||
public string Error = ""; // 非空则红字显示
|
||
|
||
// 外部探测失败后调用:显示错误并回到可输入状态。
|
||
public void ResetToWaiting(string error)
|
||
{
|
||
Error = error ?? "";
|
||
State = PromptState.Waiting;
|
||
}
|
||
|
||
private void OnGUI()
|
||
{
|
||
if (State != PromptState.Waiting) return;
|
||
const int W = 560, H = 190;
|
||
GUILayout.BeginArea(new Rect((Screen.width - W) / 2, (Screen.height - H) / 3, W, H), GUI.skin.box);
|
||
GUILayout.Label("内网发现失败:请输入开发机 IP(网关须 --lan --devToken xw-dev)");
|
||
InputIp = GUILayout.TextField(InputIp ?? "", GUILayout.Height(44));
|
||
if (!string.IsNullOrEmpty(Error))
|
||
{
|
||
GUI.color = new Color(1f, 0.4f, 0.3f);
|
||
GUILayout.Label(Error);
|
||
GUI.color = Color.white;
|
||
}
|
||
GUILayout.FlexibleSpace();
|
||
GUILayout.BeginHorizontal();
|
||
if (GUILayout.Button("确定", GUILayout.Height(44))) { Error = ""; State = PromptState.Confirmed; }
|
||
if (GUILayout.Button("跳过", GUILayout.Height(44), GUILayout.Width(120))) State = PromptState.Skipped;
|
||
GUILayout.EndHorizontal();
|
||
GUILayout.EndArea();
|
||
}
|
||
}
|