212 lines
4.8 KiB
C#
212 lines
4.8 KiB
C#
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading;
|
||
using taurus.client;
|
||
using UnityEditor;
|
||
using UnityEngine;
|
||
using System.IO;
|
||
|
||
public class TestToolWindow : EditorWindow
|
||
{
|
||
static string uid = "";
|
||
static string diamo = "";
|
||
string errMsg = "";
|
||
static TaurusClient client;
|
||
|
||
//[MenuItem("Windows tools/test tool %_e")]
|
||
static public void Init()
|
||
{
|
||
TestToolWindow window = (TestToolWindow)EditorWindow.GetWindow(typeof(TestToolWindow), false, "测试工具", true);
|
||
window.ShowAuxWindow();
|
||
}
|
||
|
||
protected void OnGUI()
|
||
{
|
||
VerticalZone(() =>
|
||
{
|
||
GUI.contentColor = Color.green;
|
||
Label("注:Unity运行时使用该工具会停止Unity。", 400f);
|
||
GUI.contentColor = Color.white;
|
||
Space();
|
||
HorizontalZone(() =>
|
||
{
|
||
Label("玩家ID:");
|
||
Text(ref uid);
|
||
});
|
||
|
||
Space(25f);
|
||
Label("设置玩家权限:");
|
||
HorizontalZone(() =>
|
||
{
|
||
Space(25f);
|
||
Button("普通玩家", ()=> { SetUserAuth(0); });
|
||
Button("圈主", ()=> { SetUserAuth(1); });
|
||
Button("盟主", ()=> { SetUserAuth(2); });
|
||
});
|
||
|
||
Space(25f);
|
||
Label("开关日志:");
|
||
HorizontalZone(() =>
|
||
{
|
||
Space(25f);
|
||
Button("开", () => { SetUserLog(2); });
|
||
Button("关", () => { SetUserLog(0); });
|
||
});
|
||
|
||
Space(25f);
|
||
Label("设置玩家钻石:");
|
||
HorizontalZone(() =>
|
||
{
|
||
Space(25f);
|
||
Label("钻石数");
|
||
Text(ref diamo);
|
||
Button("确定", () => { SetUserDiamon(); });
|
||
});
|
||
|
||
Space();
|
||
GUI.contentColor = Color.yellow;
|
||
Label(errMsg, 200f);
|
||
});
|
||
|
||
}
|
||
|
||
void VerticalZone(Action callback)
|
||
{
|
||
GUILayout.BeginVertical();
|
||
callback();
|
||
GUILayout.EndVertical();
|
||
}
|
||
|
||
void HorizontalZone(Action callback)
|
||
{
|
||
GUILayout.BeginHorizontal();
|
||
callback();
|
||
GUILayout.EndHorizontal();
|
||
}
|
||
|
||
void Space(float len = 10f)
|
||
{
|
||
GUILayout.Space(len);
|
||
}
|
||
|
||
void Label(string content, float len = 80f)
|
||
{
|
||
GUILayout.Label(content, GUILayout.Width(len));
|
||
}
|
||
|
||
void Text(ref string content, float len = 80f)
|
||
{
|
||
content = GUILayout.TextField(content, GUILayout.Width(len));
|
||
}
|
||
|
||
void Button(string content, Action callback, float len = 80f)
|
||
{
|
||
if (GUILayout.Button(content, GUILayout.Width(len)))
|
||
{
|
||
callback();
|
||
}
|
||
}
|
||
|
||
void SetUserLog(int s)
|
||
{
|
||
int id = GetUserID();
|
||
if (!CheckNumber(id))
|
||
return;
|
||
|
||
DoAction("type", id, s);
|
||
}
|
||
|
||
void SetUserAuth(int auth)
|
||
{
|
||
int id = GetUserID();
|
||
if (!CheckNumber(id))
|
||
return;
|
||
|
||
DoAction("mng", id, auth);
|
||
}
|
||
|
||
void SetUserDiamon()
|
||
{
|
||
int id = GetUserID();
|
||
if (!CheckNumber(id))
|
||
return;
|
||
|
||
int dia = GetDiamon();
|
||
if (!CheckNumber(dia))
|
||
return;
|
||
|
||
DoAction("diamo", id, dia);
|
||
}
|
||
|
||
int GetUserID()
|
||
{
|
||
try
|
||
{
|
||
return Convert.ToInt32(uid);
|
||
}
|
||
catch
|
||
{
|
||
errMsg = "ID输入不正确。";
|
||
return -1;
|
||
}
|
||
}
|
||
|
||
int GetDiamon()
|
||
{
|
||
try
|
||
{
|
||
return Convert.ToInt32(diamo);
|
||
}
|
||
catch
|
||
{
|
||
errMsg = "钻石输入不正确。";
|
||
return -1;
|
||
}
|
||
}
|
||
|
||
bool CheckNumber(int num)
|
||
{
|
||
if (num == -1)
|
||
{
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
void DoAction(string key, int uid, int value)
|
||
{
|
||
if (client == null || !client.isConnected())
|
||
{
|
||
client = new TaurusClient("http://192.168.1.236:9091/", "ww", ConnectionProtocol.Web);
|
||
}
|
||
if (EditorApplication.isPlaying)
|
||
{
|
||
//errMsg = "需要先暂停unity";
|
||
EditorApplication.isPlaying = false;
|
||
//return;
|
||
}
|
||
errMsg = "";
|
||
ITObject _data1 = TObject.newInstance();
|
||
_data1.putString("key", key);
|
||
_data1.putInt("uid", uid);
|
||
_data1.putInt("value", value);
|
||
float timer = 5000;
|
||
client.send("cmd/set_user", _data1, (res) =>
|
||
{
|
||
timer = 0;
|
||
if (res.returnCode == 0)
|
||
errMsg = "设置成功";
|
||
else
|
||
errMsg = "设置失败";
|
||
});
|
||
while (timer > 0)
|
||
{
|
||
NetManager.processEvents();
|
||
Thread.Sleep(10);
|
||
timer -= 10;
|
||
}
|
||
}
|
||
} |