mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Init TEngine4.0.0
Init TEngine4.0.0
This commit is contained in:
41
UnityProject/Assets/TEngine/Editor/Utility/GetAssetHelper.cs
Normal file
41
UnityProject/Assets/TEngine/Editor/Utility/GetAssetHelper.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取资源路径相关的实用函数。
|
||||
/// </summary>
|
||||
public static class GetAssetHelper
|
||||
{
|
||||
[MenuItem("Assets/Get Asset Path", priority = 3)]
|
||||
static void GetAssetPath()
|
||||
{
|
||||
UnityEngine.Object selObj = Selection.activeObject;
|
||||
|
||||
if (selObj != null)
|
||||
{
|
||||
string assetPath = AssetDatabase.GetAssetPath(selObj);
|
||||
EditorGUIUtility.systemCopyBuffer = assetPath;
|
||||
Debug.Log($"Asset path is {assetPath}");
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("Assets/Get Addressable Path", priority = 3)]
|
||||
static void GetAddressablePath()
|
||||
{
|
||||
UnityEngine.Object selObj = Selection.activeObject;
|
||||
|
||||
if (selObj != null)
|
||||
{
|
||||
string assetPath = AssetDatabase.GetAssetPath(selObj);
|
||||
var split = assetPath.Split('/');
|
||||
var name = split.Last();
|
||||
assetPath = name.Split('.').First();
|
||||
EditorGUIUtility.systemCopyBuffer = assetPath;
|
||||
Debug.Log($"Addressable path is {assetPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cda2f3725dfe964a94ccdc9218e8ebc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
89
UnityProject/Assets/TEngine/Editor/Utility/HelperInfo.cs
Normal file
89
UnityProject/Assets/TEngine/Editor/Utility/HelperInfo.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine.Editor
|
||||
{
|
||||
internal 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(Type.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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e1e932beb704b8d855ada90d41d6b56
|
||||
timeCreated: 1695116209
|
@@ -0,0 +1,83 @@
|
||||
using System.Diagnostics;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 打开文件夹相关的实用函数。
|
||||
/// </summary>
|
||||
public static class OpenFolderHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 打开 Data Path 文件夹。
|
||||
/// </summary>
|
||||
[MenuItem("TEngine/Open Folder/Data Path", false, 10)]
|
||||
public static void OpenFolderDataPath()
|
||||
{
|
||||
Execute(Application.dataPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开 Persistent Data Path 文件夹。
|
||||
/// </summary>
|
||||
[MenuItem("TEngine/Open Folder/Persistent Data Path", false, 11)]
|
||||
public static void OpenFolderPersistentDataPath()
|
||||
{
|
||||
Execute(Application.persistentDataPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开 Streaming Assets Path 文件夹。
|
||||
/// </summary>
|
||||
[MenuItem("TEngine/Open Folder/Streaming Assets Path", false, 12)]
|
||||
public static void OpenFolderStreamingAssetsPath()
|
||||
{
|
||||
Execute(Application.streamingAssetsPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开 Temporary Cache Path 文件夹。
|
||||
/// </summary>
|
||||
[MenuItem("TEngine/Open Folder/Temporary Cache Path", false, 13)]
|
||||
public static void OpenFolderTemporaryCachePath()
|
||||
{
|
||||
Execute(Application.temporaryCachePath);
|
||||
}
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
|
||||
/// <summary>
|
||||
/// 打开 Console Log Path 文件夹。
|
||||
/// </summary>
|
||||
[MenuItem("TEngine/Open Folder/Console Log Path", false, 14)]
|
||||
public static void OpenFolderConsoleLogPath()
|
||||
{
|
||||
Execute(System.IO.Path.GetDirectoryName(Application.consoleLogPath));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// 打开指定路径的文件夹。
|
||||
/// </summary>
|
||||
/// <param name="folder">要打开的文件夹的路径。</param>
|
||||
public static void Execute(string folder)
|
||||
{
|
||||
folder = $"\"{folder}\"";
|
||||
switch (Application.platform)
|
||||
{
|
||||
case RuntimePlatform.WindowsEditor:
|
||||
Process.Start("Explorer.exe", folder.Replace('/', '\\'));
|
||||
break;
|
||||
|
||||
case RuntimePlatform.OSXEditor:
|
||||
Process.Start("open", folder);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new System.Exception($"Not support open folder on '{Application.platform}' platform.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce4febf89f4174a46be07146ae57de86
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
103
UnityProject/Assets/TEngine/Editor/Utility/ShellHelper.cs
Normal file
103
UnityProject/Assets/TEngine/Editor/Utility/ShellHelper.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
public static class ShellHelper
|
||||
{
|
||||
public static void Run(string cmd, string workDirectory, List<string> environmentVars = null)
|
||||
{
|
||||
System.Diagnostics.Process process = new();
|
||||
try
|
||||
{
|
||||
#if UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX
|
||||
string app = "bash";
|
||||
string splitChar = ":";
|
||||
string arguments = "-c";
|
||||
#elif UNITY_EDITOR_WIN
|
||||
string app = "cmd.exe";
|
||||
string splitChar = ";";
|
||||
string arguments = "/c";
|
||||
#endif
|
||||
ProcessStartInfo start = new ProcessStartInfo(app);
|
||||
|
||||
if (environmentVars != null)
|
||||
{
|
||||
foreach (string var in environmentVars)
|
||||
{
|
||||
start.EnvironmentVariables["PATH"] += (splitChar + var);
|
||||
}
|
||||
}
|
||||
|
||||
process.StartInfo = start;
|
||||
start.Arguments = arguments + " \"" + cmd + "\"";
|
||||
start.CreateNoWindow = true;
|
||||
start.ErrorDialog = true;
|
||||
start.UseShellExecute = false;
|
||||
start.WorkingDirectory = workDirectory;
|
||||
|
||||
if (start.UseShellExecute)
|
||||
{
|
||||
start.RedirectStandardOutput = false;
|
||||
start.RedirectStandardError = false;
|
||||
start.RedirectStandardInput = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
start.RedirectStandardOutput = true;
|
||||
start.RedirectStandardError = true;
|
||||
start.RedirectStandardInput = true;
|
||||
start.StandardOutputEncoding = System.Text.Encoding.UTF8;
|
||||
start.StandardErrorEncoding = System.Text.Encoding.UTF8;
|
||||
}
|
||||
|
||||
bool endOutput = false;
|
||||
bool endError = false;
|
||||
|
||||
process.OutputDataReceived += (sender, args) =>
|
||||
{
|
||||
if (args.Data != null)
|
||||
{
|
||||
UnityEngine.Debug.Log(args.Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
endOutput = true;
|
||||
}
|
||||
};
|
||||
|
||||
process.ErrorDataReceived += (sender, args) =>
|
||||
{
|
||||
if (args.Data != null)
|
||||
{
|
||||
UnityEngine.Debug.LogError(args.Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
endError = true;
|
||||
}
|
||||
};
|
||||
|
||||
process.Start();
|
||||
process.BeginOutputReadLine();
|
||||
process.BeginErrorReadLine();
|
||||
|
||||
while (!endOutput || !endError)
|
||||
{
|
||||
}
|
||||
|
||||
process.CancelOutputRead();
|
||||
process.CancelErrorRead();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UnityEngine.Debug.LogException(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
process.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a1d4e955485549fcbcc754c333953255
|
||||
timeCreated: 1695193247
|
83
UnityProject/Assets/TEngine/Editor/Utility/Type.cs
Normal file
83
UnityProject/Assets/TEngine/Editor/Utility/Type.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace TEngine.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 类型相关的实用函数。
|
||||
/// </summary>
|
||||
internal static class Type
|
||||
{
|
||||
private static readonly string[] RuntimeAssemblyNames =
|
||||
{
|
||||
"TEngine.Runtime",
|
||||
"Assembly-CSharp",
|
||||
"GameMain.Runtime",
|
||||
"GameMain",
|
||||
};
|
||||
|
||||
private static readonly string[] RuntimeOrEditorAssemblyNames =
|
||||
{
|
||||
"TEngine.Runtime",
|
||||
"Assembly-CSharp",
|
||||
"TEngine.Editor",
|
||||
"Assembly-CSharp-Editor",
|
||||
"GameMain",
|
||||
"GameMain.Editor"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 在运行时程序集中获取指定基类的所有子类的名称。
|
||||
/// </summary>
|
||||
/// <param name="typeBase">基类类型。</param>
|
||||
/// <returns>指定基类的所有子类的名称。</returns>
|
||||
internal static string[] GetRuntimeTypeNames(System.Type typeBase)
|
||||
{
|
||||
return GetTypeNames(typeBase, RuntimeAssemblyNames);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在运行时或编辑器程序集中获取指定基类的所有子类的名称。
|
||||
/// </summary>
|
||||
/// <param name="typeBase">基类类型。</param>
|
||||
/// <returns>指定基类的所有子类的名称。</returns>
|
||||
internal static string[] GetRuntimeOrEditorTypeNames(System.Type typeBase)
|
||||
{
|
||||
return GetTypeNames(typeBase, RuntimeOrEditorAssemblyNames);
|
||||
}
|
||||
|
||||
private static string[] GetTypeNames(System.Type typeBase, string[] assemblyNames)
|
||||
{
|
||||
List<string> typeNames = new List<string>();
|
||||
foreach (string assemblyName in assemblyNames)
|
||||
{
|
||||
Assembly assembly = null;
|
||||
try
|
||||
{
|
||||
assembly = Assembly.Load(assemblyName);
|
||||
}
|
||||
catch
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (assembly == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
System.Type[] types = assembly.GetTypes();
|
||||
foreach (System.Type type in types)
|
||||
{
|
||||
if (type.IsClass && !type.IsAbstract && typeBase.IsAssignableFrom(type))
|
||||
{
|
||||
typeNames.Add(type.FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typeNames.Sort();
|
||||
return typeNames.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
11
UnityProject/Assets/TEngine/Editor/Utility/Type.cs.meta
Normal file
11
UnityProject/Assets/TEngine/Editor/Utility/Type.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a791d3891e3eeb40b35602635e8093b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user