拓展支持AssetInspector,支持更多文件类型在Inspector显示

拓展支持AssetInspector,支持更多文件类型在Inspector显示
This commit is contained in:
ALEXTANG
2023-10-23 11:41:33 +08:00
parent 0e70f7d446
commit dc22e595c9
5 changed files with 135 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1d6f43591dfb9c54fbbebda60c1210fa
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 83f53d2e775d0ff449616ff946f1be55
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ad0327765273616459117746a53a35e6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: