NLDClient-yudde/ProjectNLD/Assets/Editor/GMTools/GMWindow.cs

171 lines
4.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
using System.IO;
using Cysharp.Threading.Tasks;
using System;
using Luban.Editor;
public class GMWindow : EditorWindow, Gameplay.Net.IAppConfigHandler
{
enum TabType
{
ActorInfo = 0,
AddItem,
CharacterAwake,
CharacterBreak,
CharacterLikely,
CharacterSkill,
SendMail,
TimePass,
Max,
}
private int selectedTab = 0;
private string[] tabNames;
private GMPart[] parts;
private string GMToken = "phxh666";
private int serverSelect;
private string[] ServerNames;
private string[] ServerIps;
private string actorID;
public static void ShowWindow()
{
try
{
GMWindow window = GetWindow(typeof(GMWindow)) as GMWindow;
window.titleContent = new GUIContent("GM工具");
window.maximized = false;
window.minSize = new Vector2(1024, 768);
Rect centerRect = new Rect((Screen.currentResolution.width - 1024) / 2, (Screen.currentResolution.height - 768) / 2, 1024, 768);
window.position = centerRect;
window.Init();
window.Show();
}
catch (Exception e)
{
Debug.LogError("GM工具 ShowWindow catch exception, msg=" + e.Message + ", trace=" + e.StackTrace);
}
}
Gameplay.Net.AppConfig ac;
void Init()
{
parts = new GMPart[(int)TabType.Max];
parts[(int)TabType.ActorInfo] = new GMPartActorInfo();
parts[(int)TabType.AddItem] = new GMPartAddItem();
parts[(int)TabType.CharacterAwake] = new GMPartCharacterAwake();
parts[(int)TabType.CharacterBreak] = new GMPartCharacterBreak();
parts[(int)TabType.CharacterLikely] = new GMPartCharacterLikely();
parts[(int)TabType.CharacterSkill] = new GMPartCharacterSkillLevel();
parts[(int)TabType.SendMail] = new GMPartSendMail();
parts[(int)TabType.TimePass] = new GMPartTimePass();
ac = new Gameplay.Net.AppConfig();
ac.Init();
ac.RequestWithCallback(this);
List<string> names = new List<string>();
for (int i = 0; i < parts.Length; i++)
{
parts[i].Init();
names.Add(parts[i].GetName());
}
tabNames = names.ToArray();
actorID = PlayerPrefs.GetString("LoginActor", "");
}
public void OnAppConfigDone()
{
List<Gameplay.Net.ServerInfo> infos = ac.GetServerInfo();
List<string> names = new List<string>();
List<string> ips = new List<string>();
for(int i = 0; i < infos.Count; i ++)
{
names.Add(infos[i].name);
ips.Add(infos[i].addrs[0].ip + ":8080");
}
ServerNames = names.ToArray();
ServerIps = ips.ToArray();
serverSelect = PlayerPrefs.GetInt("ServerIndex", 0);
if(serverSelect >= ServerNames.Length)
serverSelect = 0;
}
void OnGUI()
{
try
{
OnGUITabs();
EditorGUILayout.Space(10);
parts[selectedTab].OnResGUI();
}
catch(Exception e)
{
EditorGUILayout.LabelField("请关闭窗口重新打开");
Debug.LogError("msg=" + e.Message + "\n, trace=" + e.StackTrace);
}
}
void OnGUITabs()
{
GUILayout.BeginHorizontal();
EditorGUILayout.LabelField("请选择服务器:", GUILayout.Width(100f));
if(ServerNames != null)
{
var select = EditorGUILayout.Popup(serverSelect, ServerNames);
if (select != serverSelect)
{
serverSelect = select;
}
}
GUILayout.EndHorizontal();
var actor = EditorGUILayout.TextField("角色ID", actorID);
if (!string.IsNullOrEmpty(actor) && actor.Trim() != actorID)
{
actorID = actor.Trim();
}
EditorGUILayout.Space(10);
var currentTab = GUILayout.Toolbar(selectedTab, tabNames, GUILayout.Width(100 * tabNames.Length), GUILayout.Height(30));
if(currentTab != selectedTab) {
selectedTab = currentTab;
parts[selectedTab].Init();
}
EditorGUILayout.Space(10);
parts[selectedTab].OnTabGUI();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button("执行", GUILayout.Width(200), GUILayout.Height(40)))
{
parts[selectedTab].Execute(GMToken, ServerIps[serverSelect], actorID);
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
}