You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.8 KiB
66 lines
2.8 KiB
|
1 month ago
|
using Unity.VisualScripting;
|
||
|
|
using UnityEditor;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
namespace UDE_HAND_INTERACTION
|
||
|
|
{
|
||
|
|
[CustomEditor(typeof(FingerPressInteractable))]
|
||
|
|
public class FingerPressInteractableEditor : EditorUtils
|
||
|
|
{
|
||
|
|
private FingerPressInteractable _interactable;
|
||
|
|
|
||
|
|
private SerializedProperty _surfaceProperty;
|
||
|
|
|
||
|
|
private static readonly float DRAW_RADIUS = 0.02f;
|
||
|
|
|
||
|
|
private void Awake()
|
||
|
|
{
|
||
|
|
_interactable = target as FingerPressInteractable;
|
||
|
|
_surfaceProperty = serializedObject.FindProperty("_surfacePatch");
|
||
|
|
}
|
||
|
|
|
||
|
|
public void OnSceneGUI()
|
||
|
|
{
|
||
|
|
Handles.color = new Color(0f, 1f, 1f, 0.5f);
|
||
|
|
ISurfacePatch surfacePatch = _surfaceProperty.objectReferenceValue.GetComponent<ISurfacePatch>();
|
||
|
|
|
||
|
|
if (surfacePatch == null)
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
Transform triggerPlaneTransform = surfacePatch.Transform;
|
||
|
|
|
||
|
|
if (triggerPlaneTransform == null)
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
Vector3 touchPoint = triggerPlaneTransform.position - triggerPlaneTransform.forward * _interactable.EnterHoverNormal;
|
||
|
|
surfacePatch.ClosestSurfacePoint(touchPoint, out SurfaceHit hit);
|
||
|
|
Vector3 proximalPoint = hit.Point;
|
||
|
|
|
||
|
|
Handles.DrawSolidDisc(touchPoint, triggerPlaneTransform.forward, DRAW_RADIUS);
|
||
|
|
Handles.DrawLine(touchPoint, proximalPoint, 2);
|
||
|
|
Handles.DrawLine(proximalPoint - triggerPlaneTransform.right * DRAW_RADIUS, proximalPoint + triggerPlaneTransform.right * DRAW_RADIUS, 2);
|
||
|
|
Handles.DrawLine(proximalPoint - triggerPlaneTransform.up * DRAW_RADIUS, proximalPoint + triggerPlaneTransform.up * DRAW_RADIUS, 2);
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void OnInspectorGUI()
|
||
|
|
{
|
||
|
|
_interactable._enterHoverNormal = EditorGUILayout.FloatField("Hover Detect Distance", _interactable._enterHoverNormal);
|
||
|
|
_interactable._exitHoverNormal = EditorGUILayout.FloatField("Hover Ignore Distance", _interactable._exitHoverNormal);
|
||
|
|
GUILayout.Space(5);
|
||
|
|
_interactable._enterHoverTangent = EditorGUILayout.FloatField("Surface Ext Hover Detect", _interactable._enterHoverTangent);
|
||
|
|
_interactable._exitHoverTangent = EditorGUILayout.FloatField("Surface Ext Hover Ignore", _interactable._exitHoverTangent);
|
||
|
|
GUILayout.Space(5);
|
||
|
|
_interactable._cancelSelectNormal = EditorGUILayout.FloatField("Interact Disable Distance", _interactable._cancelSelectNormal);
|
||
|
|
_interactable._cancelSelectTangent = EditorGUILayout.FloatField("Surface Ext Interact Disable", _interactable._cancelSelectTangent);
|
||
|
|
if (GUI.changed)
|
||
|
|
{
|
||
|
|
EditorUtility.SetDirty(_interactable);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|