81 lines
2.1 KiB
C#
81 lines
2.1 KiB
C#
using System;
|
||
using System.IO;
|
||
using UnityEditor;
|
||
using UnityEngine;
|
||
|
||
[CustomEditor(typeof(DefaultAsset))]
|
||
public class DefaultAssetInspector : Editor
|
||
{
|
||
private Editor editor;
|
||
private static Type[] customAssetTypes;
|
||
|
||
/// <summary>
|
||
/// 확장자에 따른 CustomAsset 속성이 붙은 클래스를 얻어옵니다
|
||
/// </summary>
|
||
/// <param name="extension">확장자(예시: .zip)</param>
|
||
private Type GetCustomAssetEditorType(string extension)
|
||
{
|
||
switch (extension)
|
||
{
|
||
case ".ini":
|
||
return typeof(INIEditor);
|
||
default:
|
||
return typeof(DefaultAsset);
|
||
}
|
||
}
|
||
|
||
string data;
|
||
private void OnEnable()
|
||
{
|
||
var assetPath = AssetDatabase.GetAssetPath(target);
|
||
var extension = Path.GetExtension(assetPath);
|
||
var customAssetEditorType = GetCustomAssetEditorType(extension);
|
||
if (customAssetEditorType == typeof(DefaultAsset))
|
||
return;
|
||
editor = CreateEditor(target, customAssetEditorType);
|
||
if(editor!=null)
|
||
{
|
||
data = File.ReadAllText(assetPath);
|
||
switch(editor)
|
||
{
|
||
case INIEditor ie:
|
||
ie.data = data;
|
||
ie.assetPath = assetPath;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
public override void OnInspectorGUI()
|
||
{
|
||
if (editor != null)
|
||
{
|
||
GUI.enabled = true;
|
||
editor.OnInspectorGUI();
|
||
}
|
||
}
|
||
|
||
public override bool HasPreviewGUI()
|
||
{
|
||
return editor != null ? editor.HasPreviewGUI() : base.HasPreviewGUI();
|
||
}
|
||
|
||
public override void OnPreviewGUI(Rect r, GUIStyle background)
|
||
{
|
||
if (editor != null)
|
||
editor.OnPreviewGUI(r, background);
|
||
}
|
||
|
||
public override void OnPreviewSettings()
|
||
{
|
||
if (editor != null)
|
||
editor.OnPreviewSettings();
|
||
}
|
||
|
||
public override string GetInfoString()
|
||
{
|
||
return editor != null ? editor.GetInfoString() : base.GetInfoString();
|
||
}
|
||
|
||
//아래로는 임의로 다루고 싶은 Editor 클래스의 확장을 실행합니다
|
||
} |