-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrivateRevert.cs
77 lines (47 loc) · 1.97 KB
/
PrivateRevert.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
using UnityEngine;
using System.IO;
using System.Collections;
public class PrivateRevert : MonoBehaviour
{
public static FieldInfo GetField(Type classtypetochange, string fieldName)
{
return classtypetochange.GetField(fieldName, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
}
public static object GetPrivateVarible(Type classtypetochange, string fieldName, object InstanceOfScript)
{
FieldInfo field = classtypetochange.GetField(fieldName, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
Debug.Log(field);
Debug.Log(field.GetValue(InstanceOfScript));
object obj = field.GetValue(InstanceOfScript);
return obj;
}
public static void SetPrivateVarible(Type classtypetochange, string fieldName, object changeto, object InstanceOfScript)
{
FieldInfo field = classtypetochange.GetField(fieldName, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
//Debug.Log(field);
//Debug.Log(field.GetValue(container.GetComponent(classtypetochange)));
field.SetValue(InstanceOfScript, changeto); //1 Instance of Script // changeto
}
public static object RunPrivateFunction(Type classtypetochange, string methodName, object[] arguments)
{
MethodInfo mi = classtypetochange.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);//.Invoke(classtypetochange, null);
//Debug.Log(mi);
var instance = Activator.CreateInstance(classtypetochange, null);
//Debug.Log(instance);
object o = new object();
try
{
o = mi.Invoke(instance, arguments);
}
catch
{
Debug.LogError("wrong arguments");
}
return o;
}
}