Last active
August 15, 2019 07:13
-
-
Save GameEgg/eae63c82d1af9bee2f3064f71846fab2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using UnityEditor; | |
using UnityEngine; | |
using System.Linq; | |
using AnimationImporter; | |
using System.IO; | |
[CustomEditor(typeof(DefaultAsset))] | |
public class AseFileInspector: Editor | |
{ | |
DefaultAsset[] assets = new DefaultAsset[1]; | |
bool isAseFile; | |
AssetImporter importer; | |
string targetPath; | |
Vector2 scrollPosition; | |
void OnEnable() | |
{ | |
var path = AssetDatabase.GetAssetPath(target); | |
if (path.EndsWith(".ase")) | |
{ | |
importer = AssetImporter.GetAtPath(path); | |
targetPath = path; | |
isAseFile = true; | |
} | |
} | |
public override void OnHeaderGUI() | |
{ | |
base.OnHeaderGUI(); | |
if(!isAseFile) | |
{ | |
return; | |
} | |
if(string.IsNullOrEmpty(targetPath)) | |
return; | |
var importer = AnimationImporter.AnimationImporter.Instance; | |
EditorGUI.BeginDisabledGroup(!importer.canImportAnimations); | |
EditorGUILayout.LabelField($"file path : {targetPath}"); | |
assets[0] = AssetDatabase.LoadAssetAtPath<DefaultAsset>(targetPath); | |
if(GUILayout.Button("애니메이션 생성")) | |
{ | |
importer.ImportAssets(assets); | |
} | |
if(GUILayout.Button("애니메이션 + 애니메이션 컨트롤러 생성")) | |
{ | |
importer.ImportAssets(assets, ImportAnimatorController.AnimatorController); | |
} | |
if(GUILayout.Button("부모 폴더로 이동")) | |
{ | |
var path = targetPath; | |
path = path.Replace(path.Split('/').Last(),""); | |
if (path[path.Length -1] == '/') | |
path = path.Substring(0, path.Length -1); | |
UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(targetPath, typeof(UnityEngine.Object)); | |
Selection.activeObject = obj; | |
EditorGUIUtility.PingObject(obj); | |
} | |
EditorGUI.EndDisabledGroup(); | |
scrollPosition = GUILayout.BeginScrollView(scrollPosition); | |
var aseFileDir = Path.GetDirectoryName(targetPath); | |
var spriteDir = Path.Combine(aseFileDir,"Sprites"); | |
var spritePaths = AssetDatabase.FindAssets("t:texture2D",new string[1]{spriteDir}); | |
var filename = Path.GetFileNameWithoutExtension(targetPath); | |
foreach(var guid in spritePaths){ | |
var texturePath = AssetDatabase.GUIDToAssetPath(guid); | |
var texutreName = Path.GetFileNameWithoutExtension(texturePath); | |
var cond1 = texutreName.CompareTo(filename) == 0; | |
var cond2 = texutreName.Replace(filename,"").StartsWith("__"); | |
if(cond1 || cond2){ | |
var t = AssetDatabase.LoadAssetAtPath<Texture2D>(texturePath); | |
GUILayout.Box(t); | |
} | |
} | |
GUILayout.EndScrollView(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment