Skip to content

Instantly share code, notes, and snippets.



Last active Sep 23, 2015
What would you like to do?
using UnityEngine;
using System.Collections;
using UnityEditor;
using UnityEngine.Assertions;
using System.Reflection;
public class GetTypeTest {
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;
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