-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathMeshColliderEditor.cs
85 lines (69 loc) · 3.31 KB
/
MeshColliderEditor.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
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System.Net.Mime;
using UnityEngine;
namespace UnityEditor
{
[CustomEditor(typeof(MeshCollider))]
[CanEditMultipleObjects]
internal class MeshColliderEditor : Collider3DEditorBase
{
private SerializedProperty m_Mesh;
private SerializedProperty m_Convex;
private SerializedProperty m_CookingOptions;
private static class Styles
{
public static readonly GUIContent isTriggerText = EditorGUIUtility.TrTextContent("Is Trigger", "Is this collider a trigger? Triggers are only supported on convex colliders.");
public static readonly GUIContent convexText = EditorGUIUtility.TrTextContent("Convex", "Is this collider convex?");
public static readonly GUIContent cookingOptionsText = EditorGUIUtility.TrTextContent("Cooking Options", "Options affecting the result of the mesh processing by the physics engine.");
public static readonly GUIContent meshText = EditorGUIUtility.TrTextContent("Mesh", "Reference to the Mesh to use for collisions.");
}
public override void OnEnable()
{
base.OnEnable();
m_Mesh = serializedObject.FindProperty("m_Mesh");
m_Convex = serializedObject.FindProperty("m_Convex");
m_CookingOptions = serializedObject.FindProperty("m_CookingOptions");
}
private MeshColliderCookingOptions GetCookingOptions()
{
return (MeshColliderCookingOptions)m_CookingOptions.intValue;
}
private void SetCookingOptions(MeshColliderCookingOptions cookingOptions)
{
m_CookingOptions.intValue = (int)cookingOptions;
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_Convex, Styles.convexText);
if (EditorGUI.EndChangeCheck() && m_Convex.boolValue == false)
{
m_IsTrigger.boolValue = false;
}
EditorGUI.indentLevel++;
using (new EditorGUI.DisabledScope(!m_Convex.boolValue))
{
EditorGUILayout.PropertyField(m_IsTrigger, Styles.isTriggerText);
}
EditorGUI.indentLevel--;
EditorGUILayout.PropertyField(m_ProvidesContacts, BaseStyles.providesContacts);
using (var horizontal = new EditorGUILayout.HorizontalScope())
{
using (var propertyScope = new EditorGUI.PropertyScope(horizontal.rect, GUIContent.none, m_CookingOptions))
{
EditorGUI.BeginChangeCheck();
var newOptions = (MeshColliderCookingOptions)EditorGUILayout.EnumFlagsField(Styles.cookingOptionsText, GetCookingOptions());
if (EditorGUI.EndChangeCheck())
SetCookingOptions(newOptions);
}
}
EditorGUILayout.PropertyField(m_Material, BaseStyles.materialContent);
EditorGUILayout.PropertyField(m_Mesh, Styles.meshText);
ShowLayerOverridesProperties();
serializedObject.ApplyModifiedProperties();
}
}
}