Skip to content

Instantly share code, notes, and snippets.

@NNNIC
Last active July 31, 2018 04:49
Show Gist options
  • Save NNNIC/1f2aca93679a08f078996eb0ff0ad841 to your computer and use it in GitHub Desktop.
Save NNNIC/1f2aca93679a08f078996eb0ff0ad841 to your computer and use it in GitHub Desktop.
List up all animation clips in all fbx files under the selected folder
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEditor;
public class ListAllAnimartionClipsInFolde {
[MenuItem("Assets/list all animation clip (fbx) in the folder")]
static void List()
{
if (Selection.assetGUIDs==null || Selection.assetGUIDs.Length!=1 )
{
Debug.LogError("Select a folder in the project window");
return;
}
var buf = string.Empty;
var path = AssetDatabase.GUIDToAssetPath(Selection.assetGUIDs[0]);
var assetroot = Path.Combine( Application.dataPath ,".." );
var folderpath = Path.GetFullPath( Path.Combine(assetroot,path) );
foreach(var fi in (new DirectoryInfo(folderpath)).GetFiles("*.fbx"))
{
//Debug.Log(fi.Name);
var assetlist = AssetDatabase.LoadAllAssetsAtPath(path +"/" + fi.Name );
if (assetlist!=null)
{
foreach(var a in assetlist)
{
var clip = a as AnimationClip;
if (clip!=null)
{
if (clip.name.StartsWith("__")) continue;
//Debug.Log("-" + a.name);
if (!string.IsNullOrEmpty(buf)) buf += System.Environment.NewLine;
buf += a.name;
}
}
}
}
Debug.Log(buf);
Debug.Log("! the result exists in the clipboad !");
GUIUtility.systemCopyBuffer = buf;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class test : MonoBehaviour {
public string m_animation_folder="Assets/UnityChan/Animations";
#if UNITY_EDITOR
[ContextMenu("Setup")]
void SetupSimpleAnimationComponent()
{
/*
※自動化での利用例
  本コンポネントから、EditorScriptの ListAllAnimartionClipsInFolde.List を呼び出し、アニメーションクリップ名リストを取得する。
*/
var folderasset = AssetDatabase.LoadAssetAtPath(m_animation_folder, typeof(UnityEngine.Object));
Selection.SetActiveObjectWithContext(folderasset,null);
var listupType = System.Type.GetType("ListAllAnimationClipsInFolder, Assembly-CSharp-Editor");
var api = listupType.GetMethod("List");
api.Invoke(null,new object[]{});
Debug.Log(GUIUtility.systemCopyBuffer);
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment