Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Reflection;
- using UnityEditor;
- namespace Midva
- {
- public class InternalClassUtilities
- {
- /// <summary>
- /// Getting from assembly variable and/or method that later can be called
- /// EXAMPLE: Get instance of ScriptableSingleton<GameViewSizes> and delete it so it gets reimported again
- /// </summary>
- private void InternalMethodAndProperty()
- {
- //Get assembly in which class we need is
- Assembly assembly = typeof(UnityEditor.Editor).Assembly;
- //Type of class we need
- System.Type gameViewSizesType = assembly.GetType("UnityEditor.GameViewSizes"); //TODO: Change string to class you need
- //In this example GameViewSizes is ScriptableSingleton<>, so we need to cast it to ScriptableSingleton as generic type GameViewSizes
- System.Type scriptableSingletonType = typeof(ScriptableSingleton<>).MakeGenericType(gameViewSizesType);
- //In this example we need property "instance" of ScriptableSingleton<>
- //Get all available properties in this class and print them
- PropertyInfo[] properties = scriptableSingletonType.GetProperties();
- Debug.LogError("Properties of " + scriptableSingletonType.Name + ":");
- foreach (PropertyInfo property in properties)
- {
- Debug.Log(property.Name);
- }
- //We need a instance property in this class
- PropertyInfo instanceProperty = scriptableSingletonType.GetProperty("instance"); //TODO: Change string to property you need
- //Get all available methods in this class and print them
- MethodInfo[] methods = gameViewSizesType.GetMethods();
- Debug.LogError("Methods of " + gameViewSizesType.Name + ":");
- foreach (MethodInfo method in methods)
- {
- Debug.Log(method.Name);
- }
- //Get one of those method
- MethodInfo methodChanged = gameViewSizesType.GetMethod("Changed"); //TODO: Change string to method you need
- //Get instance value
- object instanceObject = instanceProperty.GetValue(null, null);
- //Invoke method
- methodChanged.Invoke(instanceObject, null);
- //Delete so we regenerate ScriptableSingleton<> in this example
- //DestroyImmediate((Object)instanceObject);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement