mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
拓展支持AssetInspector,支持更多文件类型在Inspector显示
拓展支持AssetInspector,支持更多文件类型在Inspector显示
This commit is contained in:
8
UnityProject/Assets/TEngine/Editor/Inspector/Asset.meta
Normal file
8
UnityProject/Assets/TEngine/Editor/Inspector/Asset.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d6f43591dfb9c54fbbebda60c1210fa
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83f53d2e775d0ff449616ff946f1be55
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad0327765273616459117746a53a35e6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user