Unity Udexreal开发插件包
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.

73 lines
2.6 KiB

using UnityEngine;
using UnityEditor;
using System;
namespace UDE_HAND_INTERACTION
{
[CustomEditor(typeof(HandInteractor))]
public class HandInteractorEditor : Editor
{
HandInteractor handInteractor { get { return target as HandInteractor; } }
public float ActiveRange;
public GameObject RecordedTarget;
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
ActiveRangeSetting();
handInteractor.FingerInteractData.ShortcutKeyCode = (KeyCode)EditorGUILayout.EnumPopup("Shortcut Key Code", handInteractor.FingerInteractData.ShortcutKeyCode);
RecordInteractionButton();
RecordStaticPoseButton();
EditorGUILayout.Separator();
if (GUI.changed)
{
EditorUtility.SetDirty(handInteractor);
}
}
void ActiveRangeSetting()
{
ActiveRange = EditorGUILayout.FloatField("Active Range", handInteractor.ActiveRange);
handInteractor.GetComponentInChildren<SphereCollider>().radius = ActiveRange;
handInteractor.ActiveRange = ActiveRange;
}
void RecordInteractionButton()
{
GUILayout.Space(10);
if (GUILayout.Button("Create Realtime Hand Interaction"))
{
handInteractor.RecordInteractionButton();
}
}
void RecordStaticPoseButton()
{
GUILayout.Space(5);
if (GUILayout.Button("Create Static Hand Pose"))
{
handInteractor.RecordStaticPoseButton();
}
}
private void OnSceneGUI()
{
Transform detectArea = handInteractor.DetectArea;
if (detectArea == null)
{
detectArea = handInteractor.transform.Find("DetectArea").transform;
}
int sign = handInteractor.handness == HandInteractor.Handness.Left ? 1 : -1;
Debug.DrawRay(detectArea.position, detectArea.forward, Color.blue);
Debug.DrawRay(detectArea.position, detectArea.forward + sign * detectArea.right, Color.magenta);
Debug.DrawRay(detectArea.position, sign * detectArea.right, Color.red);
Debug.DrawRay(detectArea.position, sign * detectArea.right - detectArea.forward, Color.green);
Debug.DrawRay(detectArea.position, sign * detectArea.right + (float)Math.Sqrt(3) * detectArea.up, Color.cyan);
Debug.DrawRay(detectArea.position, sign * detectArea.right - (float)Math.Sqrt(3) * detectArea.up, Color.yellow);
}
}
}