208 lines
4.8 KiB
C#
208 lines
4.8 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2020-09-15
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "EditorTools" company="KUNPO"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.IO;
|
|||
|
using UnityEditor;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace G
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 游戏工具
|
|||
|
/// </summary>
|
|||
|
public class EditorTools : MonoBehaviour
|
|||
|
{
|
|||
|
#region Field
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Method
|
|||
|
|
|||
|
[MenuItem("Game/启动游戏", false, 0)]
|
|||
|
private static void LaunchGame()
|
|||
|
{
|
|||
|
if (!UnityEditor.EditorApplication.isPlaying)
|
|||
|
{
|
|||
|
var launchScene = UnityEditor.EditorBuildSettings.scenes[0];
|
|||
|
//var launchScene = UnityEditor.SceneManagement.EditorSceneManager.GetSceneByBuildIndex(0);
|
|||
|
var path = launchScene.path;
|
|||
|
//var name = launchScene.name;
|
|||
|
UnityEditor.SceneManagement.EditorSceneManager.OpenScene(launchScene.path);
|
|||
|
UnityEditor.EditorApplication.ExecuteMenuItem("Edit/Play");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[MenuItem("Tools/记录坐标点")]
|
|||
|
public static void RecodeUIPosition()
|
|||
|
{
|
|||
|
var at = Selection.activeTransform;
|
|||
|
if (at)
|
|||
|
{
|
|||
|
var sb = new System.Text.StringBuilder();
|
|||
|
|
|||
|
for (int i = at.childCount - 1; i >= 0; i--)
|
|||
|
{
|
|||
|
var child = at.GetChild(i);
|
|||
|
var childPos = at.localPosition;
|
|||
|
|
|||
|
sb.Append($"[{(int)childPos.x},{(int)childPos.y}] ");
|
|||
|
sb.Append(child.name);
|
|||
|
sb.AppendLine();
|
|||
|
}
|
|||
|
|
|||
|
Debug.Log(sb.ToString());
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[MenuItem("Tools/重命名动画 %&g")]
|
|||
|
public static void RenameAnimation()
|
|||
|
{
|
|||
|
var ag = Selection.activeGameObject;
|
|||
|
if (ag)
|
|||
|
{
|
|||
|
var agName = ag.name;
|
|||
|
int @index = ag.name.IndexOf('@');
|
|||
|
|
|||
|
if (index >= 0)
|
|||
|
{
|
|||
|
agName = agName.Substring(0, ag.name.IndexOf('@') + 1);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
agName += "@";
|
|||
|
}
|
|||
|
|
|||
|
ag.name = agName + ag.GetComponent<Animation>().clip.name;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[MenuItem("Tools/获取路径")]
|
|||
|
public static void CopyPath()
|
|||
|
{
|
|||
|
var t = Selection.activeTransform;
|
|||
|
if (t)
|
|||
|
{
|
|||
|
string result = t.name;
|
|||
|
while (t.parent)
|
|||
|
{
|
|||
|
result = t.parent.name + "/" + result;
|
|||
|
t = t.parent;
|
|||
|
}
|
|||
|
Debug.Log(result);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[MenuItem("Tools/获取名字ID")]
|
|||
|
public static void GetNameHash()
|
|||
|
{
|
|||
|
var t = Selection.activeTransform;
|
|||
|
if (t)
|
|||
|
{
|
|||
|
Debug.Log(t.name + " " + Animator.StringToHash(t.name));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[MenuItem("Tools/获取UI坐标 %&f")]
|
|||
|
public static void GetUIPosition()
|
|||
|
{
|
|||
|
var rt = Selection.activeTransform as RectTransform;
|
|||
|
if (rt)
|
|||
|
{
|
|||
|
var ap = rt.anchoredPosition;
|
|||
|
var str = $"[{(int)ap.x},{(int)ap.y}]";
|
|||
|
Debug.Log(str);
|
|||
|
TextEditor te = new TextEditor { text = str };
|
|||
|
te.OnFocus();
|
|||
|
te.Copy();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[MenuItem("Tools/更新字符集")]
|
|||
|
public static void SaveFontChar()
|
|||
|
{
|
|||
|
var charSet = new HashSet<char>();
|
|||
|
|
|||
|
//自定义
|
|||
|
var customText = File.ReadAllText(@"Assets\Arts\Fonts\zh_cn_custom.txt");
|
|||
|
foreach (var t in customText)
|
|||
|
{
|
|||
|
charSet.Add(t);
|
|||
|
}
|
|||
|
|
|||
|
// config
|
|||
|
var configFiles = Directory.GetFiles(@"Assets\AGame\Configs\Client", "*json");
|
|||
|
foreach (var file in configFiles)
|
|||
|
{
|
|||
|
var text = File.ReadAllText(file);
|
|||
|
foreach (var t in text)
|
|||
|
{
|
|||
|
charSet.Add(t);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// ui
|
|||
|
var uiFiles = Directory.GetFiles(@"Assets\AGame\Res\UI", "*prefab");
|
|||
|
foreach (var file in uiFiles)
|
|||
|
{
|
|||
|
var text = File.ReadAllText(file);
|
|||
|
Decode(text, charSet);
|
|||
|
}
|
|||
|
|
|||
|
//save
|
|||
|
System.Text.StringBuilder builder = new System.Text.StringBuilder();
|
|||
|
foreach (var item in charSet)
|
|||
|
{
|
|||
|
builder.Append(item);
|
|||
|
}
|
|||
|
File.WriteAllText(@"Assets\Arts\Fonts\zh_cn.txt", builder.ToString());
|
|||
|
|
|||
|
Debug.Log($"更新字符集 共{charSet.Count}字");
|
|||
|
}
|
|||
|
|
|||
|
static System.Text.RegularExpressions.Regex _ReUnicode = new System.Text.RegularExpressions.Regex(@"\\u([0-9a-fA-F]{4})", System.Text.RegularExpressions.RegexOptions.Compiled);
|
|||
|
public static string Decode(string s, HashSet<char> results)
|
|||
|
{
|
|||
|
var collect = _ReUnicode.Matches(s);
|
|||
|
for (int i = 0; i < collect.Count; i++)
|
|||
|
{
|
|||
|
if (short.TryParse(collect[i].Groups[1].Value, System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture, out var c))
|
|||
|
{
|
|||
|
results.Add((char)c);
|
|||
|
}
|
|||
|
}
|
|||
|
return "";
|
|||
|
}
|
|||
|
|
|||
|
[MenuItem("Game/打开存档目录")]
|
|||
|
public static void OpenPersistent()
|
|||
|
{
|
|||
|
Application.OpenURL(Application.persistentDataPath);
|
|||
|
}
|
|||
|
|
|||
|
[MenuItem("Game/清除存档")]
|
|||
|
public static void DeleteArchive()
|
|||
|
{
|
|||
|
foreach (var item in Directory.GetFiles(Application.persistentDataPath, "*.gaz"))
|
|||
|
{
|
|||
|
File.Delete(item);
|
|||
|
};
|
|||
|
|
|||
|
PlayerPrefs.DeleteAll();
|
|||
|
PlayerPrefs.Save();
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|