From dc22e595c968fbc6018a69bd36f0587b4b427b0f Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Mon, 23 Oct 2023 11:41:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=93=E5=B1=95=E6=94=AF=E6=8C=81AssetInspec?= =?UTF-8?q?tor=EF=BC=8C=E6=94=AF=E6=8C=81=E6=9B=B4=E5=A4=9A=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=B1=BB=E5=9E=8B=E5=9C=A8Inspector=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 拓展支持AssetInspector,支持更多文件类型在Inspector显示 --- .../TEngine/Editor/Inspector/Asset.meta | 8 +++ .../Inspector/Asset/DefaultAssetInspector.cs | 52 ++++++++++++++++++ .../Asset/DefaultAssetInspector.cs.meta | 11 ++++ .../Inspector/Asset/TextAssetInspector.cs | 53 +++++++++++++++++++ .../Asset/TextAssetInspector.cs.meta | 11 ++++ 5 files changed, 135 insertions(+) create mode 100644 UnityProject/Assets/TEngine/Editor/Inspector/Asset.meta create mode 100644 UnityProject/Assets/TEngine/Editor/Inspector/Asset/DefaultAssetInspector.cs create mode 100644 UnityProject/Assets/TEngine/Editor/Inspector/Asset/DefaultAssetInspector.cs.meta create mode 100644 UnityProject/Assets/TEngine/Editor/Inspector/Asset/TextAssetInspector.cs create mode 100644 UnityProject/Assets/TEngine/Editor/Inspector/Asset/TextAssetInspector.cs.meta diff --git a/UnityProject/Assets/TEngine/Editor/Inspector/Asset.meta b/UnityProject/Assets/TEngine/Editor/Inspector/Asset.meta new file mode 100644 index 00000000..ad882a4e --- /dev/null +++ b/UnityProject/Assets/TEngine/Editor/Inspector/Asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1d6f43591dfb9c54fbbebda60c1210fa +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityProject/Assets/TEngine/Editor/Inspector/Asset/DefaultAssetInspector.cs b/UnityProject/Assets/TEngine/Editor/Inspector/Asset/DefaultAssetInspector.cs new file mode 100644 index 00000000..58d309e0 --- /dev/null +++ b/UnityProject/Assets/TEngine/Editor/Inspector/Asset/DefaultAssetInspector.cs @@ -0,0 +1,52 @@ +using UnityEngine; +using UnityEditor; +using System.IO; + +[CanEditMultipleObjects, CustomEditor(typeof(DefaultAsset), false)] +public class DefaultAssetInspector : Editor +{ + private const int MaxColum = 10240; + + private GUIStyle _textStyle; + + public override void OnInspectorGUI() + { + base.OnInspectorGUI(); + if (_textStyle == null) + { + _textStyle = "ScriptText"; + } + + bool enabled = GUI.enabled; + GUI.enabled = true; + string assetPath = AssetDatabase.GetAssetPath(target); + if (assetPath.EndsWith(".lua") || + assetPath.EndsWith(".properties") || + assetPath.EndsWith(".gradle") + ) + { + string luaFile = File.ReadAllText(assetPath); + string text; + if (targets.Length > 1) + { + text = Path.GetFileName(assetPath); + } + else + { + text = luaFile; + if (text.Length > MaxColum) + { + text = text.Substring(0, MaxColum) + "...\n\n<...etc...>"; + } + } + + Rect rect = GUILayoutUtility.GetRect(new GUIContent(text), _textStyle); + rect.x = 0f; + rect.y -= 3f; + rect.width = EditorGUIUtility.currentViewWidth + 1f; + GUI.Box(rect, text, _textStyle); + } + + GUI.enabled = enabled; + } +} \ No newline at end of file diff --git a/UnityProject/Assets/TEngine/Editor/Inspector/Asset/DefaultAssetInspector.cs.meta b/UnityProject/Assets/TEngine/Editor/Inspector/Asset/DefaultAssetInspector.cs.meta new file mode 100644 index 00000000..3fe57bdc --- /dev/null +++ b/UnityProject/Assets/TEngine/Editor/Inspector/Asset/DefaultAssetInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 83f53d2e775d0ff449616ff946f1be55 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityProject/Assets/TEngine/Editor/Inspector/Asset/TextAssetInspector.cs b/UnityProject/Assets/TEngine/Editor/Inspector/Asset/TextAssetInspector.cs new file mode 100644 index 00000000..b2e7ea4f --- /dev/null +++ b/UnityProject/Assets/TEngine/Editor/Inspector/Asset/TextAssetInspector.cs @@ -0,0 +1,53 @@ +using UnityEngine; +using UnityEditor; +using System.IO; + +[CanEditMultipleObjects, CustomEditor(typeof(TextAsset))] +public class TextAssetInspector : Editor +{ + private const int MaxColum = 10240; + + private GUIStyle _textStyle; + + public override void OnInspectorGUI() + { + if (_textStyle == null) + { + _textStyle = "ScriptText"; + } + + bool enabled = GUI.enabled; + GUI.enabled = true; + string assetPath = AssetDatabase.GetAssetPath(target); + if (assetPath.EndsWith(".md") + || assetPath.EndsWith(".xml") + || assetPath.EndsWith(".txt") + || assetPath.EndsWith(".html") + || assetPath.EndsWith(".csv") + ) + { + string luaFile = File.ReadAllText(assetPath); + string text; + if (base.targets.Length > 1) + { + text = Path.GetFileName(assetPath); + } + else + { + text = luaFile; + if (text.Length > MaxColum) + { + text = text.Substring(0, MaxColum) + "...\n\n<...etc...>"; + } + } + + Rect rect = GUILayoutUtility.GetRect(new GUIContent(text), _textStyle); + rect.x = 0f; + rect.y -= 3f; + rect.width = EditorGUIUtility.currentViewWidth + 1f; + GUI.Box(rect, text, _textStyle); + } + + GUI.enabled = enabled; + } +} \ No newline at end of file diff --git a/UnityProject/Assets/TEngine/Editor/Inspector/Asset/TextAssetInspector.cs.meta b/UnityProject/Assets/TEngine/Editor/Inspector/Asset/TextAssetInspector.cs.meta new file mode 100644 index 00000000..7d2cb6fc --- /dev/null +++ b/UnityProject/Assets/TEngine/Editor/Inspector/Asset/TextAssetInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ad0327765273616459117746a53a35e6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: