forked from XINCGer/UnityToolchainsTrick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParticleSystemEditorUtilsReflect.cs
128 lines (114 loc) · 4.5 KB
/
ParticleSystemEditorUtilsReflect.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System;
using UnityEngine;
using System.Reflection;
using UnityEditor;
namespace ToolKits
{
public class ParticleSystemEditorUtilsReflect
{
private static Type realType;
private static Type realType2;
private static PropertyInfo property_editorResimulation;
private static PropertyInfo property_editorPlaybackTime;
private static Func<float> getFunc_editorPlaybackTime;
private static PropertyInfo property_editorIsScrubbing;
private static PropertyInfo property_lockedParticleSystem;
private static MethodInfo method_StopEffect;
public static void InitType()
{
if (realType == null)
{
var assembly = Assembly.GetAssembly(typeof(Editor));
realType = assembly.GetType("UnityEditor.ParticleSystemEditorUtils");
#if UNITY_2018_1_OR_NEWER
property_editorResimulation =
realType.GetProperty("resimulation", BindingFlags.Static | BindingFlags.NonPublic);
property_editorPlaybackTime =
realType.GetProperty("playbackTime", BindingFlags.Static | BindingFlags.NonPublic);
getFunc_editorPlaybackTime = (Func<float>) Delegate.CreateDelegate(typeof(Func<float>),
property_editorPlaybackTime.GetGetMethod(true));
property_editorIsScrubbing =
realType.GetProperty("playbackIsScrubbing", BindingFlags.Static | BindingFlags.NonPublic);
property_lockedParticleSystem = realType.GetProperty("lockedParticleSystem",
BindingFlags.Static | BindingFlags.NonPublic);
realType2 = assembly.GetType("UnityEditor.ParticleSystemEffectUtils");
method_StopEffect = realType2.GetMethod("StopEffect", BindingFlags.Static | BindingFlags.NonPublic,
null, new Type[] { }, new ParameterModifier[] { });
#else
property_editorResimulation =
realType.GetProperty("editorResimulation", BindingFlags.Static | BindingFlags.NonPublic);
property_editorPlaybackTime =
realType.GetProperty("editorPlaybackTime", BindingFlags.Static | BindingFlags.NonPublic);
getFunc_editorPlaybackTime =
(Func<float>)Delegate.CreateDelegate(typeof(Func<float>), property_editorPlaybackTime.GetGetMethod(true));
property_editorIsScrubbing =
realType.GetProperty("editorIsScrubbing", BindingFlags.Static | BindingFlags.NonPublic);
property_lockedParticleSystem =
realType.GetProperty("lockedParticleSystem", BindingFlags.Static | BindingFlags.NonPublic);
method_StopEffect =
realType.GetMethod("StopEffect", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[] { }, new ParameterModifier[] { });
#endif
}
}
public static bool editorResimulation
{
set
{
InitType();
property_editorResimulation.SetValue(null, value, null);
}
}
public static float editorPlaybackTime
{
get
{
InitType();
return getFunc_editorPlaybackTime();
}
set
{
InitType();
property_editorPlaybackTime.SetValue(null, value, null);
}
}
public static bool editorIsScrubbing
{
set
{
InitType();
property_editorIsScrubbing.SetValue(null, value, null);
}
}
public static ParticleSystem lockedParticleSystem
{
get
{
InitType();
return (ParticleSystem) property_lockedParticleSystem.GetValue(null, null);
}
set
{
InitType();
property_lockedParticleSystem.SetValue(null, value, null);
}
}
public static void StopEffect()
{
InitType();
method_StopEffect.Invoke(null, null);
}
public static ParticleSystem GetRoot(ParticleSystem ps)
{
if (ps == null)
{
return null;
}
Transform transform = ps.transform;
while (transform.parent && transform.parent.gameObject.GetComponent<ParticleSystem>() != null)
{
transform = transform.parent;
}
return transform.gameObject.GetComponent<ParticleSystem>();
}
}
}