11using System.Collections;
12using System.Collections.Generic;
18 [CanEditMultipleObjects]
19 [CustomEditor(typeof(AnchorableBehaviour))]
29 "matchAnchorMotionWhileAttaching");
32 "_motionlessRangeFraction",
33 "_maxMotionlessRange",
34 "_maxAttachmentAngle");
38 "_tryAnchorNearestOnGraspEnd",
41 "attractionReachByDistance");
45 "attractionReachByDistance");
49 private void drawEventTable(SerializedProperty property) {
50 if (_tableEditor ==
null) {
58 drawWarningMessages();
60 drawAttachmentHelperButtons();
62 base.OnInspectorGUI();
65 private void drawWarningMessages() {
69 int expectedMinimumActionListeners = EditorApplication.isPlaying ? 2 : 1;
71 bool hasInvalidPostGraspEndCallback = !
target.tryAnchorNearestOnGraspEnd
72 && (
target.OnPostTryAnchorOnGraspEnd.GetInvocationList().Length > expectedMinimumActionListeners
73 || (_tableEditor !=
null &&
75 if (hasInvalidPostGraspEndCallback) {
76 EditorGUILayout.HelpBox(
"This object's OnPostObjectGraspEnd is subscribed to, but the event will never "
77 +
"fire because tryAnchorNearestOnGraspEnd is disabled.",
82 private void drawAttachmentHelperButtons() {
83 if (!EditorApplication.isPlaying) {
85 EditorGUILayout.BeginHorizontal();
87 var anyTargetsCanAnchor =
targets.Query().Any(t => t.anchor !=
null && !
target.isAttached);
89 EditorGUI.BeginDisabledGroup(!anyTargetsCanAnchor);
90 if (GUILayout.Button(
new GUIContent(
"Attach Object" + (
targets.Length > 1 ?
"s" :
""),
91 "Will attach the object to its anchor. If the object is not currently at its anchor, "
92 +
"currently at its anchor, it will begin move to it when play mode begins."))) {
93 Undo.IncrementCurrentGroup();
94 foreach (var singleTarget
in targets) {
95 Undo.RecordObject(singleTarget,
"Try Attach Object");
96 singleTarget.TryAttach(ignoreRange:
true);
99 EditorGUI.EndDisabledGroup();
101 var anyTargetsCanDetach =
targets.Query().Any(t => t.isAttached);
103 EditorGUI.BeginDisabledGroup(!anyTargetsCanDetach);
104 if (GUILayout.Button(
new GUIContent(
"Detach Object" + (
targets.Length > 1 ?
"s" :
""),
105 "Will detach the object from its anchor. AnchorableBehaviours won't seek out an anchor "
106 +
"until they are specifically told to attach to one."))) {
107 Undo.IncrementCurrentGroup();
108 foreach (var singleTarget
in targets) {
109 Undo.RecordObject(singleTarget,
"Try Detach Object");
110 singleTarget.Detach();
113 EditorGUI.EndDisabledGroup();
115 EditorGUILayout.EndHorizontal();
119 bool anyTranslatedFromAnchor =
false;
120 bool anyRotatedFromAnchor =
false;
122 foreach (var singleTarget
in targets) {
123 anyTranslatedFromAnchor |= singleTarget.anchor !=
null &&
Vector3.Distance(singleTarget.transform.position, singleTarget.anchor.transform.position) > 0.0001F;
124 anyRotatedFromAnchor |= singleTarget.anchor !=
null && singleTarget.anchorRotation
125 &&
Quaternion.Angle(singleTarget.transform.rotation, singleTarget.anchor.transform.rotation) > 0.1F;
128 if (anyTranslatedFromAnchor || anyRotatedFromAnchor) {
129 if (GUILayout.Button(
new GUIContent(
"Move Object" + (
targets.Length > 1 ?
"s" :
"") +
" To Anchor",
130 "Detected that the object is not currently at its anchor, but upon pressing play, "
131 +
"the object will move to to match its anchor. If you'd like the object to move to "
132 +
"its anchor now, click this button."))) {
133 Undo.IncrementCurrentGroup();
134 foreach (var singleTarget
in targets) {
135 Undo.RecordObject(singleTarget.transform,
"Move Target Transform to Anchor");
136 singleTarget.transform.position = singleTarget.anchor.transform.position;
137 if (singleTarget.anchorRotation) singleTarget.transform.rotation = singleTarget.anchor.transform.rotation;
void specifyConditionalDrawing(string conditionalName, params string[] dependantProperties)
Specify a list of properties that should only be displayed if the conditional property has a value of...
void deferProperty(string propertyName)
Defer rendering of a property until the end of the inspector. Deferred properties are drawn in the RE...
void specifyCustomDrawer(string propertyName, Action< SerializedProperty > propertyDrawer)
Specify a callback to be used to draw a specific named property. Should be called in OnEnable.
bool HasAnyCallbacks(int enumValue)
override void OnInspectorGUI()
AnchorableBehaviours mix well with InteractionBehaviours you'd like to be able to pick up and place i...