/// <summary> /// Overrides the navigation data for a given direction with a custom object deriving from the SelectableOptionBase class. /// </summary> /// <param name="direction"></param> /// <param name="option"></param> public void SetNextOption(SelectableNavigationDirection direction, SelectableOptionBase option) { if (!direction.Equals(SelectableNavigationDirection.NONE)) { navigationArray[(int)direction] = option; } }
/// <summary> /// Selects the given option. /// </summary> /// <param name="option">The object deriving from SelectableOptionBase to select.</param> public override void SelectOption(SelectableOptionBase option, object context = null) { if (option != null && currentGroup.options.Contains(option)) { currentlySelectedOption.Deselect(this); currentlySelectedOption = option; currentlySelectedOption.Select(this); } else { Debug.LogWarning("A null option or an option outside of the current group was almost selected, which shouldn't happen. Returning to the last one!"); } }
private void HandleMouseControls() { if (raycaster == null) { Debug.LogError("No graphic raycaster was assigned! Please set one in the inspector as it is required for mouse controls to work!"); mouseControls = false; return; } if (Input.GetMouseButtonDown(0)) { currentlySelectedOption.OkPressed(this); } if (Input.GetMouseButtonDown(1)) { currentlySelectedOption.CancelPressed(this); } Vector2 mousePosition = Input.mousePosition; if (mousePosition == previousMousePosition) { return; } previousMousePosition = mousePosition; pointerEventData.position = mousePosition; List <RaycastResult> results = new List <RaycastResult>(); raycaster.Raycast(pointerEventData, results); if (results.Count < 1) { return; } SelectableOptionBase hitOption = results[0].gameObject.GetComponent <SelectableOptionBase>(); if (hitOption != null && currentGroup.options.Contains(hitOption)) { SelectOption(hitOption); } }
private void Awake() { if (firstGroup == null) { Debug.LogError("A cursor without a valid first group was activated! Please set a valid first group!"); gameObject.SetActive(false); return; } groupHistory = new Stack <SelectableGroup>(); optionHistory = new Stack <SelectableOptionBase>(); currentGroup = firstGroup; currentlySelectedOption = firstGroup.GetFirstOption(); if (mouseControls) { pointerEventData = new PointerEventData(null); } }
/// <summary> /// Enters the given SelectableGroup. /// </summary> /// <param name="group">The SelectableGroup to enter</param> /// <param name="selectOption">The option to select after entering the group (instead of the group's first option)</param> /// <param name="context">If set to true, the group change won't be recorded in the group history and option history stacks</param> public override void EnterGroup(SelectableGroup group, SelectableOptionBase selectOption = null, object context = null) { if (group != null) { if (context == null || (context is bool && (bool)context == false)) { groupHistory.Push(currentGroup); optionHistory.Push(currentlySelectedOption); } foreach (SelectableOptionBase option in currentGroup.options) { option.GroupLeft(this); } currentGroup = group; foreach (SelectableOptionBase option in group.options) { option.GroupEntered(this); } if (selectOption == null) { SelectOption(group.GetFirstOption()); } else { SelectOption(selectOption); } } else { Debug.LogWarning("A null group was almost entered, which shouldn't happen. Returning to the last one!"); } }
/// <summary> /// Select an option inside the current group. /// </summary> /// <param name="option">The option within the current group to select</param> /// <param name="context">Use this to pass custom data to the cursor</param> public virtual void SelectOption(SelectableOptionBase option, object context = null) { }
/// <summary> /// Make a cursor enter the specified group. /// </summary> /// <param name="group">The group that should be entered</param> /// <param name="selectOption">The option within the group to select. If this is null, the first option of the group will be used.</param> /// <param name="context">Use this to pass custom data to the cursor</param> public virtual void EnterGroup(SelectableGroup group, SelectableOptionBase selectOption = null, object context = null) { }