126 lines
3.8 KiB
C#
126 lines
3.8 KiB
C#
|
using System.Collections.Generic;
|
|||
|
using System.Text;
|
|||
|
using UnityEditor;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace Thousandto.DIY.UniScene
|
|||
|
{
|
|||
|
public class GMSenderEditor : EditorWindow
|
|||
|
{
|
|||
|
private static List<string> _cacheTexts = new List<string>();
|
|||
|
|
|||
|
[MenuItem("Funcell/MiniEasyTools/GM指令工具")]
|
|||
|
[MenuItem("Ares/GM指令")]
|
|||
|
static void Init()
|
|||
|
{
|
|||
|
if (!Application.isPlaying)
|
|||
|
{
|
|||
|
UnityEngine.Debug.LogError("运行模式下才能使用!");
|
|||
|
return;
|
|||
|
}
|
|||
|
var win = (GMSenderEditor)EditorWindow.GetWindow(typeof(GMSenderEditor));
|
|||
|
win.titleContent = new GUIContent("GM指令");
|
|||
|
win.Show();
|
|||
|
win.Load();
|
|||
|
}
|
|||
|
|
|||
|
private string _inputText = string.Empty;
|
|||
|
private Vector2 _scrollPos = Vector2.zero;
|
|||
|
private void OnGUI()
|
|||
|
{
|
|||
|
var newText = EditorGUILayout.TextField(_inputText);
|
|||
|
if(newText != _inputText)
|
|||
|
{
|
|||
|
_inputText = newText;
|
|||
|
}
|
|||
|
if(!string.IsNullOrEmpty(_inputText) && GUILayout.Button("发送"))
|
|||
|
{
|
|||
|
MSG_Chat.ChatReqCS req = new MSG_Chat.ChatReqCS();
|
|||
|
req.chattype = 0;
|
|||
|
req.recRoleId = 0;
|
|||
|
req.condition = _inputText;
|
|||
|
req.chatchannel = 0;
|
|||
|
req.Send();
|
|||
|
|
|||
|
if(_inputText.StartsWith("&") && _inputText.Length >= 2)
|
|||
|
{
|
|||
|
var cmd = string.Empty;
|
|||
|
var spaceIndex = _inputText.IndexOf(' ');
|
|||
|
if (spaceIndex > 0)
|
|||
|
{
|
|||
|
cmd = _inputText.Substring(0, spaceIndex);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
cmd = _inputText;
|
|||
|
}
|
|||
|
|
|||
|
var isHave = false;
|
|||
|
for (int i = 0; i < _cacheTexts.Count; ++i)
|
|||
|
{
|
|||
|
if (_cacheTexts[i] == cmd)
|
|||
|
{
|
|||
|
isHave = true;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
if (!isHave)
|
|||
|
{
|
|||
|
_cacheTexts.Add(cmd);
|
|||
|
Save();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
_scrollPos = EditorGUILayout.BeginScrollView(_scrollPos);
|
|||
|
for(int i = 0; _cacheTexts != null && i < _cacheTexts.Count; ++i)
|
|||
|
{
|
|||
|
if(GUILayout.Button(_cacheTexts[i]))
|
|||
|
{
|
|||
|
_inputText = _cacheTexts[i];
|
|||
|
}
|
|||
|
}
|
|||
|
EditorGUILayout.EndScrollView();
|
|||
|
}
|
|||
|
|
|||
|
private void OnEnable()
|
|||
|
{
|
|||
|
Load();
|
|||
|
}
|
|||
|
|
|||
|
private void Load()
|
|||
|
{
|
|||
|
var cacheText = PlayerPrefs.GetString("GMSenderEditorText", "");
|
|||
|
if(!string.IsNullOrEmpty(cacheText))
|
|||
|
{
|
|||
|
var array = cacheText.Split('|');
|
|||
|
for(int i = 0; i < array.Length; ++i)
|
|||
|
{
|
|||
|
if(!_cacheTexts.Contains(array[i]))
|
|||
|
{
|
|||
|
_cacheTexts.Add(array[i]);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
private void Save()
|
|||
|
{
|
|||
|
Load();
|
|||
|
StringBuilder strBuilder = new StringBuilder(1024 * 1024);
|
|||
|
for(int i = 0; i < _cacheTexts.Count; ++i)
|
|||
|
{
|
|||
|
if(i == 0)
|
|||
|
{
|
|||
|
strBuilder.Append(_cacheTexts[i]);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
strBuilder.AppendFormat("|{0}", _cacheTexts[i]);
|
|||
|
}
|
|||
|
}
|
|||
|
PlayerPrefs.SetString("GMSenderEditorText", strBuilder.ToString());
|
|||
|
PlayerPrefs.Save();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|