修改调整
This commit is contained in:
parent
ee3e511eee
commit
44ad68fc7f
@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 1478a6e22f3d4f5e8ff645e5272c8b34
|
|
||||||
timeCreated: 1736931429
|
|
@ -1,16 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace AlicizaX.Editor
|
|
||||||
{
|
|
||||||
[AttributeUsage(AttributeTargets.Class)]
|
|
||||||
public class DisplayNameAttribute:Attribute
|
|
||||||
{
|
|
||||||
public string DisplayName;
|
|
||||||
|
|
||||||
public DisplayNameAttribute(string displayName)
|
|
||||||
{
|
|
||||||
DisplayName = displayName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 15a53446355a45549c7060c581d194ac
|
|
||||||
timeCreated: 1737013039
|
|
@ -1,90 +0,0 @@
|
|||||||
using AlicizaX;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using UnityEditor;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace AlicizaX.Editor
|
|
||||||
{
|
|
||||||
public sealed class HelperInfo<T> where T : MonoBehaviour
|
|
||||||
{
|
|
||||||
private const string CustomOptionName = "<Custom>";
|
|
||||||
|
|
||||||
private readonly string m_Name;
|
|
||||||
|
|
||||||
private SerializedProperty m_HelperTypeName;
|
|
||||||
private SerializedProperty m_CustomHelper;
|
|
||||||
private string[] m_HelperTypeNames;
|
|
||||||
private int m_HelperTypeNameIndex;
|
|
||||||
|
|
||||||
public HelperInfo(string name)
|
|
||||||
{
|
|
||||||
m_Name = name;
|
|
||||||
|
|
||||||
m_HelperTypeName = null;
|
|
||||||
m_CustomHelper = null;
|
|
||||||
m_HelperTypeNames = null;
|
|
||||||
m_HelperTypeNameIndex = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Init(SerializedObject serializedObject)
|
|
||||||
{
|
|
||||||
m_HelperTypeName = serializedObject.FindProperty(Utility.Text.Format("m_{0}HelperTypeName", m_Name));
|
|
||||||
m_CustomHelper = serializedObject.FindProperty(Utility.Text.Format("m_Custom{0}Helper", m_Name));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Draw()
|
|
||||||
{
|
|
||||||
string displayName = FieldNameForDisplay(m_Name);
|
|
||||||
int selectedIndex = EditorGUILayout.Popup(Utility.Text.Format("{0} Helper", displayName), m_HelperTypeNameIndex, m_HelperTypeNames);
|
|
||||||
if (selectedIndex != m_HelperTypeNameIndex)
|
|
||||||
{
|
|
||||||
m_HelperTypeNameIndex = selectedIndex;
|
|
||||||
m_HelperTypeName.stringValue = selectedIndex <= 0 ? null : m_HelperTypeNames[selectedIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_HelperTypeNameIndex <= 0)
|
|
||||||
{
|
|
||||||
EditorGUILayout.PropertyField(m_CustomHelper);
|
|
||||||
if (m_CustomHelper.objectReferenceValue == null)
|
|
||||||
{
|
|
||||||
EditorGUILayout.HelpBox(Utility.Text.Format("You must set Custom {0} Helper.", displayName), MessageType.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Refresh()
|
|
||||||
{
|
|
||||||
List<string> helperTypeNameList = new List<string>
|
|
||||||
{
|
|
||||||
CustomOptionName
|
|
||||||
};
|
|
||||||
|
|
||||||
helperTypeNameList.AddRange(Utility.Assembly.GetRuntimeTypeNames(typeof(T)));
|
|
||||||
m_HelperTypeNames = helperTypeNameList.ToArray();
|
|
||||||
|
|
||||||
m_HelperTypeNameIndex = 0;
|
|
||||||
if (!string.IsNullOrEmpty(m_HelperTypeName.stringValue))
|
|
||||||
{
|
|
||||||
m_HelperTypeNameIndex = helperTypeNameList.IndexOf(m_HelperTypeName.stringValue);
|
|
||||||
if (m_HelperTypeNameIndex <= 0)
|
|
||||||
{
|
|
||||||
m_HelperTypeNameIndex = 0;
|
|
||||||
m_HelperTypeName.stringValue = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private string FieldNameForDisplay(string fieldName)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(fieldName))
|
|
||||||
{
|
|
||||||
return string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
string str = Regex.Replace(fieldName, @"^m_", string.Empty);
|
|
||||||
str = Regex.Replace(str, @"((?<=[a-z])[A-Z]|[A-Z](?=[a-z]))", @" $1").TrimStart();
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 7ff85bf9d2c44a14d90f78221024499e
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -1,194 +1,108 @@
|
|||||||
// using System;
|
using System;
|
||||||
// using System.Reflection;
|
using UnityEditor;
|
||||||
// using AlicizaX.Runtime;
|
using System.Reflection;
|
||||||
// using UnityEditor;
|
using System.Text.RegularExpressions;
|
||||||
// using UnityEngine;
|
using UnityEditor.Callbacks;
|
||||||
//
|
using UnityEditorInternal;
|
||||||
// namespace AlicizaX.Editor
|
using UnityEngine;
|
||||||
// {
|
|
||||||
// public static class LogEditor
|
namespace AlicizaX.Editor
|
||||||
// {
|
{
|
||||||
// private class LogEditorConfig
|
public static class OpenAssetLogLine
|
||||||
// {
|
{
|
||||||
// public string logScriptPath = "";
|
[OnOpenAsset(0)]
|
||||||
// public string logTypeName = "";
|
private static bool OnOpenAsset(int instanceID, int line)
|
||||||
// public int instanceID = 0;
|
{
|
||||||
//
|
if (line <= 0)
|
||||||
// public LogEditorConfig(string logScriptPath, System.Type logType)
|
{
|
||||||
// {
|
return false;
|
||||||
// this.logScriptPath = logScriptPath;
|
}
|
||||||
// this.logTypeName = logType.FullName;
|
// 获取资源路径
|
||||||
// }
|
string assetPath = AssetDatabase.GetAssetPath(instanceID);
|
||||||
// }
|
|
||||||
//
|
// 判断资源类型
|
||||||
//
|
if (!assetPath.EndsWith(".cs"))
|
||||||
// private static LogEditorConfig[] _logEditorConfig = new LogEditorConfig[]
|
{
|
||||||
// {
|
return false;
|
||||||
// new LogEditorConfig("Packages/com.alicizax.unity/Runtime/Base/Log/Log.cs", typeof(Log))
|
}
|
||||||
// };
|
|
||||||
//
|
bool autoFirstMatch = assetPath.Contains("Log.cs");
|
||||||
//
|
|
||||||
// [UnityEditor.Callbacks.OnOpenAssetAttribute(-1)]
|
var stackTrace = GetStackTrace();
|
||||||
// private static bool OnOpenAsset(int instanceID, int line)
|
if (!string.IsNullOrEmpty(stackTrace) && stackTrace.Contains("Log.cs"))
|
||||||
// {
|
|
||||||
// for (int i = _logEditorConfig.Length - 1; i >= 0; --i)
|
{
|
||||||
// {
|
if (!autoFirstMatch)
|
||||||
// var configTmp = _logEditorConfig[i];
|
{
|
||||||
// UpdateLogInstanceID(configTmp);
|
var fullPath = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf("Assets", StringComparison.Ordinal));
|
||||||
// if (instanceID == configTmp.instanceID)
|
fullPath = $"{fullPath}{assetPath}";
|
||||||
// {
|
// 跳转到目标代码的特定行
|
||||||
// var statckTrack = GetStackTrace();
|
InternalEditorUtility.OpenFileAtLineExternal(fullPath.Replace('/', '\\'), line);
|
||||||
// if (!string.IsNullOrEmpty(statckTrack))
|
return true;
|
||||||
// {
|
}
|
||||||
// var fileNames = statckTrack.Split('\n');
|
|
||||||
// var fileName = GetCurrentFullFileName(fileNames);
|
// 使用正则表达式匹配at的哪个脚本的哪一行
|
||||||
// var fileLine = LogFileNameToFileLine(fileName);
|
var matches = Regex.Match(stackTrace, @"\(at (.+)\)",
|
||||||
// fileName = GetRealFileName(fileName);
|
RegexOptions.IgnoreCase);
|
||||||
//
|
while (matches.Success)
|
||||||
// AssetDatabase.OpenAsset(AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(fileName), fileLine);
|
{
|
||||||
// return true;
|
var pathLine = matches.Groups[1].Value;
|
||||||
// }
|
|
||||||
//
|
if (!pathLine.Contains("Log.cs"))
|
||||||
// break;
|
{
|
||||||
// }
|
var splitIndex = pathLine.LastIndexOf(":", StringComparison.Ordinal);
|
||||||
// }
|
// 脚本路径
|
||||||
//
|
var path = pathLine.Substring(0, splitIndex);
|
||||||
// return false;
|
// 行号
|
||||||
// }
|
line = Convert.ToInt32(pathLine.Substring(splitIndex + 1));
|
||||||
//
|
var fullPath = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf("Assets", StringComparison.Ordinal));
|
||||||
// private static string GetStackTrace()
|
fullPath = $"{fullPath}{path}";
|
||||||
// {
|
// 跳转到目标代码的特定行
|
||||||
// var consoleWindowType = typeof(EditorWindow).Assembly.GetType("UnityEditor.ConsoleWindow");
|
InternalEditorUtility.OpenFileAtLineExternal(fullPath.Replace('/', '\\'), line);
|
||||||
// var fieldInfo = consoleWindowType.GetField("ms_ConsoleWindow", BindingFlags.Static | BindingFlags.NonPublic);
|
break;
|
||||||
// var consoleWindowInstance = fieldInfo.GetValue(null);
|
}
|
||||||
//
|
|
||||||
// if (null != consoleWindowInstance)
|
matches = matches.NextMatch();
|
||||||
// {
|
}
|
||||||
// if ((object)EditorWindow.focusedWindow == consoleWindowInstance)
|
|
||||||
// {
|
return true;
|
||||||
// // Get ListViewState in ConsoleWindow
|
}
|
||||||
// // var listViewStateType = typeof(EditorWindow).Assembly.GetType("UnityEditor.ListViewState");
|
|
||||||
// // fieldInfo = consoleWindowType.GetField("m_ListView", BindingFlags.Instance | BindingFlags.NonPublic);
|
return false;
|
||||||
// // var listView = fieldInfo.GetValue(consoleWindowInstance);
|
}
|
||||||
//
|
|
||||||
// // Get row in listViewState
|
/// <summary>
|
||||||
// // fieldInfo = listViewStateType.GetField("row", BindingFlags.Instance | BindingFlags.Public);
|
/// 获取当前日志窗口选中的日志的堆栈信息。
|
||||||
// // int row = (int)fieldInfo.GetValue(listView);
|
/// </summary>
|
||||||
//
|
/// <returns>选中日志的堆栈信息实例。</returns>
|
||||||
// // Get m_ActiveText in ConsoleWindow
|
private static string GetStackTrace()
|
||||||
// fieldInfo = consoleWindowType.GetField("m_ActiveText", BindingFlags.Instance | BindingFlags.NonPublic);
|
{
|
||||||
// string activeText = fieldInfo.GetValue(consoleWindowInstance).ToString();
|
// 通过反射获取ConsoleWindow类
|
||||||
//
|
var consoleWindowType = typeof(EditorWindow).Assembly.GetType("UnityEditor.ConsoleWindow");
|
||||||
// return activeText;
|
// 获取窗口实例
|
||||||
// }
|
var fieldInfo = consoleWindowType.GetField("ms_ConsoleWindow",
|
||||||
// }
|
BindingFlags.Static |
|
||||||
//
|
BindingFlags.NonPublic);
|
||||||
// return "";
|
if (fieldInfo != null)
|
||||||
// }
|
{
|
||||||
//
|
var consoleInstance = fieldInfo.GetValue(null);
|
||||||
// private static void UpdateLogInstanceID(LogEditorConfig config)
|
if (consoleInstance != null)
|
||||||
// {
|
if (EditorWindow.focusedWindow == (EditorWindow)consoleInstance)
|
||||||
// if (config.instanceID > 0)
|
{
|
||||||
// {
|
// 获取m_ActiveText成员
|
||||||
// return;
|
fieldInfo = consoleWindowType.GetField("m_ActiveText",
|
||||||
// }
|
BindingFlags.Instance |
|
||||||
//
|
BindingFlags.NonPublic);
|
||||||
// var assetLoadTmp = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(config.logScriptPath);
|
// 获取m_ActiveText的值
|
||||||
// if (null == assetLoadTmp)
|
if (fieldInfo != null)
|
||||||
// {
|
{
|
||||||
// throw new System.Exception("not find asset by path=" + config.logScriptPath);
|
var activeText = fieldInfo.GetValue(consoleInstance).ToString();
|
||||||
// }
|
return activeText;
|
||||||
//
|
}
|
||||||
// config.instanceID = assetLoadTmp.GetInstanceID();
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// private static string GetCurrentFullFileName(string[] fileNames)
|
return null;
|
||||||
// {
|
}
|
||||||
// string retValue = "";
|
}
|
||||||
// int findIndex = -1;
|
}
|
||||||
//
|
|
||||||
// for (int i = fileNames.Length - 1; i >= 0; --i)
|
|
||||||
// {
|
|
||||||
// bool isCustomLog = false;
|
|
||||||
// for (int j = _logEditorConfig.Length - 1; j >= 0; --j)
|
|
||||||
// {
|
|
||||||
// if (fileNames[i].Contains(_logEditorConfig[j].logTypeName))
|
|
||||||
// {
|
|
||||||
// isCustomLog = true;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (isCustomLog)
|
|
||||||
// {
|
|
||||||
// findIndex = i;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (findIndex >= 0 && findIndex < fileNames.Length - 1)
|
|
||||||
// {
|
|
||||||
// retValue = fileNames[findIndex + 1];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return retValue;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private static string GetRealFileName(string fileName)
|
|
||||||
// {
|
|
||||||
// int indexStart = fileName.IndexOf("(at ") + "(at ".Length;
|
|
||||||
// int indexEnd = ParseFileLineStartIndex(fileName) - 1;
|
|
||||||
//
|
|
||||||
// fileName = fileName.Substring(indexStart, indexEnd - indexStart);
|
|
||||||
// return fileName;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private static int LogFileNameToFileLine(string fileName)
|
|
||||||
// {
|
|
||||||
// int findIndex = ParseFileLineStartIndex(fileName);
|
|
||||||
// string stringParseLine = "";
|
|
||||||
// for (int i = findIndex; i < fileName.Length; ++i)
|
|
||||||
// {
|
|
||||||
// var charCheck = fileName[i];
|
|
||||||
// if (!IsNumber(charCheck))
|
|
||||||
// {
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// stringParseLine += charCheck;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return int.Parse(stringParseLine);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private static int ParseFileLineStartIndex(string fileName)
|
|
||||||
// {
|
|
||||||
// int retValue = -1;
|
|
||||||
// for (int i = fileName.Length - 1; i >= 0; --i)
|
|
||||||
// {
|
|
||||||
// var charCheck = fileName[i];
|
|
||||||
// bool isNumber = IsNumber(charCheck);
|
|
||||||
// if (isNumber)
|
|
||||||
// {
|
|
||||||
// retValue = i;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// if (retValue != -1)
|
|
||||||
// {
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return retValue;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private static bool IsNumber(char c)
|
|
||||||
// {
|
|
||||||
// return c >= '0' && c <= '9';
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
using System;
|
|
||||||
using AlicizaX;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace AlicizaX.Editor
|
|
||||||
{
|
|
||||||
public static class ScriptableSingletonUtil
|
|
||||||
{
|
|
||||||
public static T Get<T>() where T : ScriptableObject
|
|
||||||
{
|
|
||||||
string assetType = typeof(T).Name;
|
|
||||||
T globalSetting = default;
|
|
||||||
string[] globalAssetPaths = UnityEditor.AssetDatabase.FindAssets($"t:{assetType}");
|
|
||||||
if (globalAssetPaths.Length > 1)
|
|
||||||
{
|
|
||||||
foreach (var assetPath in globalAssetPaths)
|
|
||||||
{
|
|
||||||
Debug.LogError($"Could not had Multiple {assetType}. Repeated Path: {UnityEditor.AssetDatabase.GUIDToAssetPath(assetPath)}");
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Exception($"Could not had Multiple {assetType}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (globalAssetPaths.Length == 1)
|
|
||||||
{
|
|
||||||
string path = UnityEditor.AssetDatabase.GUIDToAssetPath(globalAssetPaths[0]);
|
|
||||||
globalSetting = UnityEditor.AssetDatabase.LoadAssetAtPath<T>(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (globalSetting == null)
|
|
||||||
{
|
|
||||||
Debug.LogError($"Could not found {assetType} asset");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return globalSetting;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 7544b657bf904330859e64362e5098a8
|
|
||||||
timeCreated: 1737536609
|
|
@ -122,6 +122,26 @@ namespace AlicizaX
|
|||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Type> GetRuntimeTypes(Type typeBase)
|
||||||
|
{
|
||||||
|
var types = GetTypes();
|
||||||
|
List<Type> results = new List<Type>();
|
||||||
|
foreach (var t in types)
|
||||||
|
{
|
||||||
|
if (t.IsAbstract || !t.IsClass)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t.IsSubclassOf(typeBase) || t.IsImplWithInterface(typeBase))
|
||||||
|
{
|
||||||
|
results.Add(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user