-
Notifications
You must be signed in to change notification settings - Fork 0
/
SceneViewColliders2DOverlay.cs
50 lines (43 loc) · 1.45 KB
/
SceneViewColliders2DOverlay.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
using System;
using JetBrains.Annotations;
using UnityEditor;
using UnityEditor.Overlays;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace Game.Plugins.mitaywalle.Physical2D.QualityOfLife.Editor
{
[UsedImplicitly]
[Overlay(typeof(SceneView), "Colliders 2D", true)]
public class SceneViewColliders2DOverlay : Overlay
{
public override VisualElement CreatePanelContent()
{
const string path = "ProjectSettings/Physics2DSettings.asset";
SerializedObject manager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath(path)[0]);
SerializedProperty property = manager.FindProperty("m_GizmoOptions");
GizmoOptions value = (GizmoOptions)property.enumValueFlag;
var root = new VisualElement() { name = "My Toolbar Root" };
var flags = new EnumFlagsField(value);
root.Add(flags);
flags.RegisterCallback<ChangeEvent<Enum>>((context) =>
{
const string path = "ProjectSettings/Physics2DSettings.asset";
SerializedObject manager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath(path)[0]);
SerializedProperty property = manager.FindProperty("m_GizmoOptions");
property.enumValueFlag = (int)(GizmoOptions)context.newValue;
manager.ApplyModifiedProperties();
});
return root;
}
[Flags]
private enum GizmoOptions
{
AllColliders = 1,
CollidersOutlined = 2,
CollidersFilled = 4,
CollidersSleeping = 8,
ColliderContacts = 16,// 0x00000010
ColliderBounds = 32,// 0x00000020
}
}
}