VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
AVR_GrabNodeEditor.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEditor;
5 
6 using AVR.Phys;
7 
8 namespace AVR.UEditor.Phys {
9  [CustomEditor(typeof(AVR_GrabNode), true)]
10  public class AVR_GrabNode_Editor : AVR.UEditor.Core.AVR_Behaviour_Editor
11  {
12  private bool drawDebugHand => debugHand!=null;
13 
14  private GameObject debugHand = null;
15 
16  public override void OnInspectorGUI()
17  {
18  base.OnInspectorGUI();
19 
20  if (!drawDebugHand && GUILayout.Button("Draw DebugHand"))
21  {
22  debugHand = AVR.UEditor.Core.AVR_EditorUtility.InstantiatePrefabAsChild(((AVR_GrabNode)target).transform, "/editor/defaultPrefabPaths/debugHand");
23  }
24  else if(drawDebugHand && GUILayout.Button("Hide DebugHand"))
25  {
26  GameObject.DestroyImmediate(debugHand);
27  }
28  }
29 
30  void OnEnable() {
31  try {
32  debugHand = ((AVR_GrabNode)target).GetComponentInChildren<AVR.Phys.AVR_DebugHand>().gameObject;
33  } catch(System.Exception) { }
34  }
35 
36  void OnDisable() {
37  if(debugHand) GameObject.DestroyImmediate(debugHand);
38  }
39 
40  public void OnSceneGUI()
41  {
42  AVR_GrabNode node = (AVR_GrabNode)target;
43 
44  const float angle_arches_size = 0.12f;
45 
46  Handles.color = new Color(0, 1, 0, 0.3f);
47  Handles.DrawSolidArc(node.transform.position, node.transform.up, node.transform.forward, node.allowed_pitch, angle_arches_size);
48  Handles.DrawSolidArc(node.transform.position, node.transform.up, node.transform.forward, -node.allowed_pitch, angle_arches_size);
49 
50  Handles.color = new Color(0, 0, 1, 0.3f);
51  Handles.DrawSolidArc(node.transform.position, node.transform.forward, node.transform.right, node.allowed_roll, angle_arches_size);
52  Handles.DrawSolidArc(node.transform.position, node.transform.forward, node.transform.right, -node.allowed_roll, angle_arches_size);
53 
54  Handles.color = new Color(1, 0, 0, 0.3f);
55  Handles.DrawSolidArc(node.transform.position, node.transform.right, node.transform.up, node.allowed_yaw, angle_arches_size);
56  Handles.DrawSolidArc(node.transform.position, node.transform.right, node.transform.up, -node.allowed_yaw, angle_arches_size);
57 
58  Handles.color = Color.yellow;
59  const int circle_res = 4;
60  for(int i=0; i<circle_res; i++) {
61  float fac = ((float)i / circle_res);
62  Handles.DrawWireDisc(node.transform.position, fac * node.transform.right + (1f - fac) * node.transform.forward, node.override_radius);
63  Handles.DrawWireDisc(node.transform.position, fac * -node.transform.right + (1f - fac) * node.transform.forward, node.override_radius);
64  }
65  Handles.DrawWireDisc(node.transform.position, node.transform.up, node.override_radius);
66  }
67  }
68 }
Represents a grabbable node on an AVR_Grabbable. Nodes have preset poses/constraints for the hand tha...
Definition: AVR_GrabNode.cs:15
In-editor drawn hand for setting up GrabNodes.