Last active
September 23, 2015 04:45
-
-
Save tsubaki/a0c400a0ed9d7901eaa1 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 UnityEngine; | |
using System.Collections; | |
using UnityEditor; | |
using UnityEngine.Assertions; | |
using System.Reflection; | |
public class GetTypeTest { | |
[MenuItem("Test/Test")] | |
static void Test () { | |
// SceneViewタイプを取得しインスタンス化 | |
System.Type sceneViewType = Types.GetType ("UnityEditor.SceneView", "UnityEditor.dll"); | |
Assert.IsNotNull (sceneViewType, "not found service type"); | |
System.Object window = ScriptableObject.CreateInstance (sceneViewType); | |
// Showメソッドを取得し呼び出す。オーバーロードしているので、一覧から一致するものを選択 | |
MethodInfo shoeMethod = null; | |
MethodInfo[] sceneViewMethods = sceneViewType.GetMethods (BindingFlags.NonPublic | BindingFlags.Instance); | |
foreach (var method in sceneViewMethods) { | |
if( method.Name == "Show" && method.GetParameters().Length == 0 ){ | |
shoeMethod = method; | |
break; | |
} | |
} | |
Assert.IsNotNull (shoeMethod, "not found Show method"); | |
shoeMethod.Invoke (window, null); | |
// Cameraオブジェクトを取得する | |
FieldInfo cameraField = sceneViewType.GetField ("m_Camera", BindingFlags.NonPublic | BindingFlags.Instance); | |
Assert.IsNotNull (cameraField, "not found camera field"); | |
System.Object camera = cameraField.GetValue (window); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment