-
Notifications
You must be signed in to change notification settings - Fork 1
/
PhysicsEditorMode
43 lines (37 loc) · 1.06 KB
/
PhysicsEditorMode
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
using UnityEditor;
using UnityEngine;
// allow physic to work in unity while in editor mode :)
public class PhysicsEditorMode : EditorWindow {
private void OnGUI() {
if (GUILayout.Button("Start")) {
EnablePhysic();
}
if (GUILayout.Button("Stop")) {
DisablePhysic();
}
}
private void EnablePhysic() {
#if UNITY_EDITOR
Physics.autoSimulation = false;
EditorApplication.update += OnEditorUpdate;
#endif
}
private void DisablePhysic() {
#if UNITY_EDITOR
EditorApplication.update -= OnEditorUpdate;
Physics.autoSimulation = true;
#endif
}
protected virtual void OnEditorUpdate() {
StepPhysics();
}
private void StepPhysics() {
Physics.autoSimulation = false;
Physics.Simulate(Time.fixedDeltaTime);
Physics.autoSimulation = true;
}
[MenuItem("Tools/Scene Physics")]
private static void OpenWindow() {
GetWindow<PhysicsEditorMode>(false, "Physics", true);
}
}