Skip to content

Instantly share code, notes, and snippets.

@whaison
Last active September 11, 2018 10:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whaison/b38402a7f1d69489df43 to your computer and use it in GitHub Desktop.
Save whaison/b38402a7f1d69489df43 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Reflection;
using System.IO;
using System.Text;
using System.Runtime.CompilerServices;
//namespace UnityEditor{
//public class AnimationWindowExtends : UnityEditor.AnimationWindow {
//Assets/SD_Chara/Editor/AnimationWindowExtends.cs(10,59): error CS0234: The type or namespace name `AnimationWindow' does not exist in the namespace `UnityEditor'. Are you missing an assembly reference?
public class AnimationWindowExtends : UnityEditor.EditorWindow {
////// [assembly: AssemblyVersion ("0.0.0.0")]
// [assembly: InternalsVisibleTo ("UnityEditor.Tizen.Extensions")]
// [assembly: InternalsVisibleTo ("Unity.PackageManager")]
// [assembly: InternalsVisibleTo ("Unity.Automation")]
// [assembly: InternalsVisibleTo ("Unity.PureCSharpTests")]
// [assembly: InternalsVisibleTo ("Unity.IntegrationTests")]
// [assembly: InternalsVisibleTo ("UnityEditor.Graphs")]
// [assembly: InternalsVisibleTo ("UnityEditor.WP8.Extensions")]
// [assembly: InternalsVisibleTo ("UnityEditor.Metro.Extensions")]
// [assembly: InternalsVisibleTo ("UnityEditor.iOS.Extensions")]
// [assembly: InternalsVisibleTo ("UnityEditor.Xbox360.Extensions")]
// [assembly: InternalsVisibleTo ("UnityEditor.BB10.Extensions")]
// [assembly: InternalsVisibleTo ("UnityEditor.Android.Extensions")]
// [assembly: InternalsVisibleTo ("UnityEditor.PS3.Extensions")]
// [assembly: InternalsVisibleTo ("UnityEditor.SamsungTV.Extensions")]
// [assembly: InternalsVisibleTo ("UnityEditor.XboxOne.Extensions")]
// [assembly: InternalsVisibleTo ("UnityEditor.PSP2.Extensions")]
// [assembly: InternalsVisibleTo ("UnityEditor.PS4.Extensions")]
// [assembly: InternalsVisibleTo ("UnityEditor.PSM.Extensions")]
// [assembly: InternalsVisibleTo ("UnityEditor.WebGL.Extensions")]
// [assembly: InternalsVisibleTo ("UnityEditor.LinuxStandalone.Extensions")]
// [assembly: InternalsVisibleTo ("UnityEditor.WindowsStandalone.Extensions")]
// [assembly: InternalsVisibleTo ("UnityEditor.OSXStandalone.Extensions")]
// [assembly: InternalsVisibleTo ("UnityEngine.Networking")]
// [assembly: InternalsVisibleTo ("UnityEditor.Advertisements")]
// [assembly: RuntimeCompatibility (WrapNonExceptionThrows = true)]
// [assembly: AssemblyIsEditorAssembly]
void OnGUI ()
{
GUILayout.Label ("UnityEditor.EditorWindow AnimationWindowExtends ", EditorStyles.boldLabel);
GUILayout.Space (10f);
GUILayout.Space (20f);
if (GUILayout.Button ("01 : AnimationWindowExtendsFunc", GUILayout.Width (300f))) {
AnimationWindowExtendsFunc ();
//countTime = 0;
}
}
void AnimationWindowExtendsFunc(){
Debug.Log ("AnimationWindowExtendsFunc");
Init0 ();
//Init1 ();
//Init2 ();
}
public List<string> fileWriterLine_List = new List<string>();
void Init0(){
EditorWindow[] windows = Resources.FindObjectsOfTypeAll(typeof(EditorWindow)) as EditorWindow[];
foreach (EditorWindow w in windows)
{
//Debug.Log(w.title);
if (w.title == "Animation") {
fileWriterLine_List = new List<string>();
Debug.Log("------------------Animation----------------");
fileWriterLine_List.Add ("------------------Animation----------------START");
Init1 (w);
Debug.Log("------------------Animation-----------------");
fileWriterLine_List.Add ("------------------Animation----------------END");
logSave ();
func(w);
}
}
}
void Init1(EditorWindow w){
Debug.Log("------------------publicメッソドを列挙----------------");
fileWriterLine_List.Add ("------------------publicメッソドを列挙----------------");
//
MethodInfo[] methods = w.GetType().GetMethods(); // w は AnimationWindow
foreach (MethodInfo m in methods)
{
string str = "";
if(m.IsPublic) str += "public ";
if(m.IsStatic) str += "static ";
str += m.ReturnType.ToString() + " ";
str += m.Name + "\n";
// 引数
ParameterInfo[] param = m.GetParameters();
for (int i = 0; i < param.Length; i++)
{
str += param[i].ParameterType.ToString() + " " + param[i].Name + (i < param.Length - 1 ? ", " : "");
}
Debug.Log(str);
fileWriterLine_List.Add (str);
}
Debug.Log("------------------privateメッソドを列挙----------------");
fileWriterLine_List.Add ("------------------privateメッソドを列挙----------------");
//
methods = w.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.InvokeMethod | BindingFlags.Instance);
foreach (MethodInfo m in methods)
{
string str = "";
if (m.IsPrivate) str += "private ";
str += m.ReturnType.ToString() + " ";
str += m.Name + "\n";
// 引数
ParameterInfo[] param = m.GetParameters();
for (int i = 0; i < param.Length; i++)
{
str += param[i].ParameterType.ToString() + " " + param[i].Name + (i < param.Length - 1 ? ", " : "");
}
//Debug.Log(str);
Debug.Log(str);
fileWriterLine_List.Add (str);
}
}
/* output
------------------Animation----------------
----method----
public static System.Collections.Generic.List`1[UnityEditor.AnimationWindow] GetAllAnimationWindows;
public System.Void OnEnable;
public System.Void OnDisable;
public System.Void Update;
public System.Void OnGUI;
public System.Void OnSelectionChange;
public System.Void BeginWindows;
public System.Void EndWindows;
-----Propaty-----
public System.Boolean get_wantsMouseMove;
public System.Void set_wantsMouseMove;
public System.Void ShowNotification;
public System.Void RemoveNotification;
public System.Boolean get_autoRepaintOnSceneChange;
public System.Void set_autoRepaintOnSceneChange;
------------------Animation----------------
*/
//メソッド呼び出し
//以下のコードは、AnimationClipをセットしたGameObjectをHierarchy上で選択した状態であることを前提に動作させています。
void func(EditorWindow w){
System.Type t = w.GetType(); // w は AnimationWindow
// アニメーション編集モード(?)にする
t.InvokeMember("set_autoRepaintOnSceneChange", BindingFlags.InvokeMethod, null, w, new object[] { true });
// タイムラインを 1:00 に合わせる
t.InvokeMember("UpdateTime", BindingFlags.InvokeMethod, null, w, new object[] { 1.0f });
}
/////////////////////////////////////
public void logSave(){
Debug.Log ("///////////////////////////////////////////////");
Debug.Log ("///////////////////////////////////////////////");
Debug.Log ("////////////////LOG SAVE //////////////////");
Debug.Log ("///////////////////////////////////////////////");
Debug.Log ("///////////////////////////////////////////////");
string filepass = "";
filepass="/AnimationWindowClasssaved.txt";
//filepass = saveDirPath;
StreamWriter sw = new StreamWriter (filepass, false, Encoding.UTF8);
//sw.WriteLine ("CN,effectId,assetBundleName,prefabName,assetPass");
//sw.WriteLine ("//,アセットID,アセットバンドル名.unity3d,prefab名,assetのパス");
for (int i = 0; i < fileWriterLine_List.Count; i++) {
//string url = fileWriterLine_List [i];
//string oneline = "1"+","+"id" + "," + url+ "," + "prefab_name"+ "," + "asset_pass";
string oneline=fileWriterLine_List [i];
Debug.Log("oneline= "+oneline);
//Debug.Log (oneline);
sw.WriteLine(oneline);
}
//sw.Fluse();
sw.Close();
Debug.Log ("///////////////////////////////////////////////");
Debug.Log ("///////////////////////////////////////////////");
Debug.Log ("////////////////LOG SAVE //////////////////");
Debug.Log ("///////////////////////////////////////////////");
Debug.Log ("///////////////////////////////////////////////");
}
//////////////////////////////////////////
#region Static
/// <summary>
/// Open the tool window
/// </summary>
[MenuItem("Windows/AnimationWindowExtends")]
static public void AnimationWindowExtendsOpen ()
{
EditorWindow.GetWindow<AnimationWindowExtends> (true, "UnityEditor.AnimationWindow.Extends", true);
}
#endregion
}
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment