diff --git a/Assets/SEE/Controls/Actions/AddEdgeAction.cs b/Assets/SEE/Controls/Actions/AddEdgeAction.cs index 48ee5a6596..4b8b45a4e7 100644 --- a/Assets/SEE/Controls/Actions/AddEdgeAction.cs +++ b/Assets/SEE/Controls/Actions/AddEdgeAction.cs @@ -137,19 +137,18 @@ public override bool Update() // Assigning the game objects to be connected. // Checking whether the two game objects are not null and whether they are // actually nodes. - // FIXME: We need an interaction for VR, too. if (SceneSettings.InputType == PlayerInputType.VRPlayer) { - if (XRSEEActions.hoveredGameObject != null && XRSEEActions.Selected && XRSEEActions.hoveredGameObject.HasNodeRef()) + if (XRSEEActions.Selected && InteractableObject.HoveredObjectWithWorldFlag.gameObject != null && InteractableObject.HoveredObjectWithWorldFlag.gameObject.HasNodeRef()) { if (from == null) { - from = XRSEEActions.hoveredGameObject; + from = InteractableObject.HoveredObjectWithWorldFlag.gameObject; XRSEEActions.Selected = false; } else if (to == null) { - to = XRSEEActions.hoveredGameObject; + to = InteractableObject.HoveredObjectWithWorldFlag.gameObject; XRSEEActions.Selected = false; } } diff --git a/Assets/SEE/Controls/Actions/AddNodeAction.cs b/Assets/SEE/Controls/Actions/AddNodeAction.cs index 35e2edf77c..2784b1e509 100644 --- a/Assets/SEE/Controls/Actions/AddNodeAction.cs +++ b/Assets/SEE/Controls/Actions/AddNodeAction.cs @@ -75,7 +75,7 @@ public override bool Update() GameObject parent = raycastHit.collider.gameObject; AddNode(raycastHit.collider.gameObject, raycastHit.point); } - else if (SceneSettings.InputType == PlayerInputType.VRPlayer && XRSEEActions.hoveredGameObject != null && XRSEEActions.Selected && XRSEEActions.hoveredGameObject.HasNodeRef() && + else if (SceneSettings.InputType == PlayerInputType.VRPlayer && XRSEEActions.Selected && InteractableObject.HoveredObjectWithWorldFlag.gameObject != null && InteractableObject.HoveredObjectWithWorldFlag.gameObject.HasNodeRef() && XRSEEActions.RayInteractor.TryGetCurrent3DRaycastHit(out RaycastHit res)) { // the hit object is the parent in which to create the new node diff --git a/Assets/SEE/Controls/Actions/DeleteAction.cs b/Assets/SEE/Controls/Actions/DeleteAction.cs index 4f0b192c7b..87dfb5eb9e 100644 --- a/Assets/SEE/Controls/Actions/DeleteAction.cs +++ b/Assets/SEE/Controls/Actions/DeleteAction.cs @@ -124,7 +124,7 @@ public override bool Update() else if (SceneSettings.InputType == PlayerInputType.VRPlayer && XRSEEActions.Selected) { // the hit object is the one to be deleted - hitGraphElements.Add(XRSEEActions.hoveredGameObject); + hitGraphElements.Add(InteractableObject.HoveredObjectWithWorldFlag.gameObject); XRSEEActions.Selected = false; return Delete(); // the selected objects are deleted and this action is done now } diff --git a/Assets/SEE/Controls/Actions/MoveAction.cs b/Assets/SEE/Controls/Actions/MoveAction.cs index 64b24523bd..fd556f69b7 100644 --- a/Assets/SEE/Controls/Actions/MoveAction.cs +++ b/Assets/SEE/Controls/Actions/MoveAction.cs @@ -258,7 +258,7 @@ public void Grab(GameObject gameObject) GrabbedGameObject = gameObject; if (SceneSettings.InputType == PlayerInputType.VRPlayer) { - originalParent = XRSEEActions.oldParent; + originalParent = XRSEEActions.OldParent; } else { @@ -307,7 +307,7 @@ public bool UnGrab() { // Node does not fit, resetting… UnReparent(); - XRSEEActions.oldParent = null; + XRSEEActions.OldParent = null; wasMoved = false; } else diff --git a/Assets/SEE/UI/Window/TreeWindow/DesktopTreeWindow.cs b/Assets/SEE/UI/Window/TreeWindow/DesktopTreeWindow.cs index 3bb2287793..0c4c521d84 100644 --- a/Assets/SEE/UI/Window/TreeWindow/DesktopTreeWindow.cs +++ b/Assets/SEE/UI/Window/TreeWindow/DesktopTreeWindow.cs @@ -452,7 +452,7 @@ void RegisterClickHandler() }); } - IEnumerable CreateContextMenuActions (TreeWindowContextMenu contextMenu, Vector2 position, GraphElement representedGraphElement, GameObject representedGameObject) + IEnumerable CreateContextMenuActions(TreeWindowContextMenu contextMenu, Vector2 position, GraphElement representedGraphElement, GameObject representedGameObject) { List appends = new() { diff --git a/Assets/SEE/XR/KeyboardManager.cs b/Assets/SEE/XR/KeyboardManager.cs index adb3893ae2..27251d2043 100644 --- a/Assets/SEE/XR/KeyboardManager.cs +++ b/Assets/SEE/XR/KeyboardManager.cs @@ -26,7 +26,7 @@ public class KeyboardManager : MonoBehaviour public Button deleteButton; /// - /// The spacebuttom, which adds a space. + /// The spacebutton, which adds a space. /// public Button spaceButton; diff --git a/Assets/SEE/XR/RadialSelection.cs b/Assets/SEE/XR/RadialSelection.cs index 20c49c5c5f..a05862f592 100644 --- a/Assets/SEE/XR/RadialSelection.cs +++ b/Assets/SEE/XR/RadialSelection.cs @@ -8,6 +8,7 @@ using UnityEngine.InputSystem; using UnityEngine.UI; using SEE.Utils; +using System; namespace SEE.XR { @@ -63,41 +64,41 @@ public class RadialSelection : MonoBehaviour public InputActionReference RadialMenuActionRef; /// - /// All actions, which are currently available. + /// All actions which are currently available. /// - List actions = new(); + private List actions = new(); /// - /// Alle submenus and their entries. + /// All submenus and their entries. /// - List<(string, List)> subMenus = new(); + private List<(string, List)> subMenus = new(); /// - /// All entry of a submenu. - /// This list is used, to swap between the main-menu and sub-menus. + /// All entries of a submenu. + /// This list is used to swap between the main-menu and sub-menus. /// The main menu contains all "main-actions" and the sub-menus more - /// specific sub-actions. We safe the main-actions here for the case, + /// specific sub-actions. We save the main-actions here for the case /// that the user wants to go back to the main-menu. /// - List menuEntries = new(); + private List menuEntries = new(); /// /// This is used for the rotate-action, because in this case we /// have a dial, which is getting spawned, and should be despawned, when the action changes. /// - GameObject actionObject; + private GameObject actionObject; /// /// The position of the submenu. - /// It should be the same, as the position from the mainmenu. + /// It should be the same as the position from the mainmenu. /// - Vector3? subMenuPosition; + private Vector3? subMenuPosition; /// /// The rotation of the submenu. - /// It should be the same, as the rotation from the mainmenu. + /// It should be the same as the rotation from the mainmenu. /// - Quaternion? subMenuRotation; + private Quaternion? subMenuRotation; /// /// The selected HideMode. @@ -134,7 +135,7 @@ bool Visit(AbstractActionStateType child, AbstractActionStateType parent) { if (parent is ActionStateTypeGroup parentGroup) { - var search = subMenus.FirstOrDefault(item => item.Item1 == parent.Name); + (string, List) search = subMenus.FirstOrDefault(item => item.Item1 == parent.Name); for (int i = 0; i < subMenus.Count; i++) { if (subMenus[i].Item1 == parent.Name && subMenus[i].Item2 == null) @@ -167,10 +168,10 @@ bool Visit(AbstractActionStateType child, AbstractActionStateType parent) /// /// Whether the radial menu is open. /// - bool radialMenuTrigger; + private bool radialMenuTrigger; /// - /// This method gets called, when the button for the radial-menu is pressed. + /// This method gets called when the button for the radial-menu is pressed. /// /// Information provided to action callbacks about what triggered an action. private void RadialMenu(InputAction.CallbackContext context) @@ -256,12 +257,12 @@ public void UpdateSelectedRadialPart() /// /// Is true if the radial menu is open. /// - bool spawned; + private bool spawned; /// /// This list represents all hideActions. /// - static List hideActions = new() + private static List hideActions = new() { "HideAll", "HideSelected", @@ -295,54 +296,9 @@ public void SelectAction(int i) subMenuPosition = radialPartCanvas.position; subMenuRotation = radialPartCanvas.rotation; } - else if (actions[i] == "HideAll") + else if (Enum.TryParse(actions[i], out HideModeSelector mode)) { - HideMode = HideModeSelector.HideAll; - TriggerHideAction(); - } - else if (actions[i] == "HideSelected") - { - HideMode = HideModeSelector.HideSelected; - TriggerHideAction(); - } - else if (actions[i] == "HideUnselected") - { - HideMode = HideModeSelector.HideUnselected; - TriggerHideAction(); - } - else if (actions[i] == "HideOutgoing") - { - HideMode = HideModeSelector.HideOutgoing; - TriggerHideAction(); - } - else if (actions[i] == "HideIncoming") - { - HideMode = HideModeSelector.HideIncoming; - TriggerHideAction(); - } - else if (actions[i] == "HideAllEdgesOfSelected") - { - HideMode = HideModeSelector.HideAllEdgesOfSelected; - TriggerHideAction(); - } - else if (actions[i] == "HideForwardTransitiveClosure") - { - HideMode = HideModeSelector.HideForwardTransitiveClosure; - TriggerHideAction(); - } - else if (actions[i] == "HideBackwardTransitiveClosure") - { - HideMode = HideModeSelector.HideBackwardTransitiveClosure; - TriggerHideAction(); - } - else if (actions[i] == "HideAllTransitiveClosure") - { - HideMode = HideModeSelector.HideAllTransitiveClosure; - TriggerHideAction(); - } - else if (actions[i] == "HighlightEdges") - { - HideMode = HideModeSelector.HighlightEdges; + HideMode = mode; TriggerHideAction(); } else diff --git a/Assets/SEE/XR/Rotator.cs b/Assets/SEE/XR/Rotator.cs index 4175dcf06f..ebf450cee6 100644 --- a/Assets/SEE/XR/Rotator.cs +++ b/Assets/SEE/XR/Rotator.cs @@ -103,7 +103,7 @@ private void Update() if (ShouldGetHandRotation) { float rotationAngle = GetInteractorRotation(); - GetRotationDistance(rotationAngle); + DetermineRotationDistance(rotationAngle); } } @@ -117,7 +117,7 @@ private void Update() /// Determines in which direction and how much the dial/node should be rotated. /// /// The current angle from the controller. - private void GetRotationDistance(float currentAngle) + private void DetermineRotationDistance(float currentAngle) { if (!firstRotation) { @@ -126,11 +126,9 @@ private void GetRotationDistance(float currentAngle) { if (angleDifference > 270f) { - float angleCheck; if (startAngle < currentAngle) { - angleCheck = CheckAngle(currentAngle, startAngle); - if (angleCheck < angleTolerance) + if (!CheckAngle(currentAngle, startAngle, angleTolerance)) { return; } @@ -142,8 +140,7 @@ private void GetRotationDistance(float currentAngle) } else if (startAngle > currentAngle) { - angleCheck = CheckAngle(currentAngle, startAngle); - if (angleCheck < angleTolerance) + if (!CheckAngle(currentAngle, startAngle, angleTolerance)) { return; } @@ -176,12 +173,24 @@ private void GetRotationDistance(float currentAngle) } /// - /// Calculates the current rotation angle of the controller. + /// Checks if the rotation was significant enough (bigger than the angleTolerance). + /// If so, the selected object will be rotated, otherwise nothing will happen. /// /// The current angle of the controller. /// The base angle. + /// The minimum angle, which needs to be reached to cause a rotation of the selected object. /// the amount of rotation - private float CheckAngle(float currentAngle, float startAngle) => (360f - currentAngle) + startAngle; + private bool CheckAngle(float currentAngle, float startAngle, float angleTolerance) + { + if (((360f - currentAngle) + startAngle) < angleTolerance) + { + return false; + } + else + { + return true; + } + } /// /// Rotates the dial/node clockwise. diff --git a/Assets/SEE/XR/XRSEEActions.cs b/Assets/SEE/XR/XRSEEActions.cs index 16dde48dd7..bfd5a4e8b6 100644 --- a/Assets/SEE/XR/XRSEEActions.cs +++ b/Assets/SEE/XR/XRSEEActions.cs @@ -30,12 +30,12 @@ public class XRSEEActions : MonoBehaviour /// /// The GameObject the user is currently hovering over. /// - public static GameObject hoveredGameObject { get; private set; } + private static GameObject hoveredGameObject { get; set; } /// /// The old parent of a node. We need this for the MoveAction. /// - public static Transform oldParent { get; set; } + public static Transform OldParent { get; set; } /// /// The button that's used for the primary actions. @@ -76,7 +76,7 @@ private void Awake() } /// - /// This method gets called, when the user begins to hover over an interactable. + /// This method gets called when the user begins to hover over an interactable. /// It provides the input data from the controller with regard to the start of a hover over an object in the CodeCity. /// /// Event data associated with the event when an Interactor first initiates hovering over an Interactable. @@ -86,7 +86,7 @@ public void OnHoverEnter(HoverEnterEventArgs args) hoveredGameObject = args.interactableObject.transform.gameObject; if (GlobalActionHistory.Current() == ActionStateTypes.Move) { - oldParent = args.interactableObject.transform.parent; + OldParent = args.interactableObject.transform.parent; } if (hoveredGameObject.transform.TryGetComponent(out showLabel)) { @@ -176,7 +176,7 @@ private void Action(InputAction.CallbackContext context) } } Selected = true; - if (GlobalActionHistory.Current() != ActionStateTypes.Move) + if (GlobalActionHistory.Current() != ActionStateTypes.Move && GlobalActionHistory.Current() != ActionStateTypes.Delete) { SelectedFlag = true; } @@ -191,7 +191,7 @@ private void Action(InputAction.CallbackContext context) /// /// Whether the TreeView is open while the user tries to move a node. /// We need to know if the user has the TreeView open, while moving a node, - /// because this can caus lags, which we prevent by closing the TreeView, befor + /// because this can cause lags, which we prevent by closing the TreeView before /// the node gets moved. /// public static bool CloseTreeView { get; set; } @@ -262,7 +262,7 @@ private void Undo(InputAction.CallbackContext context) public static bool RedoToggle { get; set; } /// - /// This method gets called, when the button for the redo-action is pressed. + /// This method gets called when the button for the redo-action is pressed. /// It will redo the last action that was undone. /// /// Information provided to action callbacks about what triggered an action.