|
| 1 | +// |
| 2 | +// Copyright (c) Microsoft. All rights reserved. |
| 3 | +// Licensed under the MIT license. |
| 4 | +// |
| 5 | +// MIT License: |
| 6 | +// Permission is hereby granted, free of charge, to any person obtaining |
| 7 | +// a copy of this software and associated documentation files (the |
| 8 | +// "Software"), to deal in the Software without restriction, including |
| 9 | +// without limitation the rights to use, copy, modify, merge, publish, |
| 10 | +// distribute, sublicense, and/or sell copies of the Software, and to |
| 11 | +// permit persons to whom the Software is furnished to do so, subject to |
| 12 | +// the following conditions: |
| 13 | +// |
| 14 | +// The above copyright notice and this permission notice shall be |
| 15 | +// included in all copies or substantial portions of the Software. |
| 16 | +// |
| 17 | +// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, |
| 18 | +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 20 | +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 21 | +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 22 | +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 23 | +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 | +// |
| 25 | + |
| 26 | +using HoloToolkit.Unity.InputModule; |
| 27 | +using HoloToolkit.Unity.Receivers; |
| 28 | +using System; |
| 29 | +using System.Collections.Generic; |
| 30 | +using System.Linq; |
| 31 | +using System.Text; |
| 32 | +using System.Threading.Tasks; |
| 33 | +using UnityEngine; |
| 34 | + |
| 35 | +namespace Microsoft.SpatialAlignment |
| 36 | +{ |
| 37 | + /// <summary> |
| 38 | + /// Handles user interaction and routes it to a <see cref="NudgeRefinement"/>. |
| 39 | + /// </summary> |
| 40 | + public class NudgeController : InteractionReceiver |
| 41 | + { |
| 42 | + #region Nested Types |
| 43 | + private enum NudgeAction |
| 44 | + { |
| 45 | + Direction, |
| 46 | + Rotation, |
| 47 | + Finish, |
| 48 | + Cancel |
| 49 | + }; |
| 50 | + #endregion // Nested Types |
| 51 | + |
| 52 | + #region Unity Inspector Variables |
| 53 | + [SerializeField] |
| 54 | + [Tooltip("The nudge refinement instance to control.")] |
| 55 | + private NudgeRefinement refinement; |
| 56 | + #endregion // Unity Inspector Variables |
| 57 | + |
| 58 | + #region Overrides / Event Handlers |
| 59 | + protected override void InputUp(GameObject obj, InputEventData eventData) |
| 60 | + { |
| 61 | + if (refinement == null) |
| 62 | + { |
| 63 | + Debug.LogWarning($"{nameof(NudgeController)} does not have a valid {nameof(Refinement)} instance."); |
| 64 | + return; |
| 65 | + } |
| 66 | + |
| 67 | + // What action? |
| 68 | + NudgeAction action; |
| 69 | + RefinementDirection direction; |
| 70 | + NudgeRotation rotation; |
| 71 | + |
| 72 | + switch (obj.name) |
| 73 | + { |
| 74 | + case "Ok": |
| 75 | + action = NudgeAction.Finish; |
| 76 | + break; |
| 77 | + case "Cancel": |
| 78 | + action = NudgeAction.Cancel; |
| 79 | + break; |
| 80 | + |
| 81 | + } |
| 82 | + |
| 83 | + Debug.Log(obj.name + " : InputUp"); |
| 84 | + txt.text = obj.name + " : InputUp"; |
| 85 | + } |
| 86 | + #endregion // Overrides / Event Handlers |
| 87 | + |
| 88 | + #region Public Properties |
| 89 | + /// <summary> |
| 90 | + /// Gets or sets the nudge refinement instance to control. |
| 91 | + /// </summary> |
| 92 | + public NudgeRefinement Refinement { get { return refinement; } set { refinement = value; } } |
| 93 | + #endregion // Public Properties |
| 94 | + } |
| 95 | +} |
0 commit comments