@@ -16,6 +16,7 @@ sealed class MainMenu : MonoBehaviour, IMainMenu, IConnectInterfaces, IInstantia
1616 IRequestFeedback
1717 {
1818 const string k_SettingsMenuSectionName = "Settings" ;
19+ const float k_MaxFlickDuration = 0.3f ;
1920
2021 [ SerializeField ]
2122 ActionMap m_ActionMap ;
@@ -43,6 +44,8 @@ sealed class MainMenu : MonoBehaviour, IMainMenu, IConnectInterfaces, IInstantia
4344 MainMenuUI m_MainMenuUI ;
4445 float m_LastRotationInput ;
4546 MenuHideFlags m_MenuHideFlags = MenuHideFlags . Hidden ;
47+ float m_RotationInputStartValue ;
48+ float m_RotationInputStartTime ;
4649 readonly Dictionary < Type , MainMenuButton > m_ToolButtons = new Dictionary < Type , MainMenuButton > ( ) ;
4750 readonly Dictionary < ISettingsMenuProvider , GameObject > m_SettingsMenus = new Dictionary < ISettingsMenuProvider , GameObject > ( ) ;
4851 readonly Dictionary < ISettingsMenuItemProvider , GameObject > m_SettingsMenuItems = new Dictionary < ISettingsMenuItemProvider , GameObject > ( ) ;
@@ -53,7 +56,6 @@ sealed class MainMenu : MonoBehaviour, IMainMenu, IConnectInterfaces, IInstantia
5356 public List < Type > menuWorkspaces { private get ; set ; }
5457 public Dictionary < KeyValuePair < Type , Transform > , ISettingsMenuProvider > settingsMenuProviders { get ; set ; }
5558 public Dictionary < KeyValuePair < Type , Transform > , ISettingsMenuItemProvider > settingsMenuItemProviders { get ; set ; }
56- public List < ActionMenuData > menuActions { get ; set ; }
5759 public Transform targetRayOrigin { private get ; set ; }
5860 public Node node { get ; set ; }
5961
@@ -62,6 +64,7 @@ sealed class MainMenu : MonoBehaviour, IMainMenu, IConnectInterfaces, IInstantia
6264 public Transform rayOrigin { private get ; set ; }
6365
6466 public Bounds localBounds { get { return m_MainMenuUI . localBounds ; } }
67+ public int priority { get { return 0 ; } }
6568
6669 public bool focus { get { return m_MainMenuUI . hovering ; } }
6770
@@ -142,23 +145,53 @@ public void ProcessInput(ActionMapInput input, ConsumeControlDelegate consumeCon
142145 var mainMenuInput = ( MainMenuInput ) input ;
143146 var rotationInput = - mainMenuInput . rotate . rawValue ;
144147
145- consumeControl ( mainMenuInput . rotate ) ;
146- consumeControl ( mainMenuInput . blockY ) ;
147-
148148 const float kFlickDeltaThreshold = 0.5f ;
149- if ( ( this . GetDeviceType ( ) != DeviceType . Vive && Mathf . Abs ( rotationInput ) >= kFlickDeltaThreshold
150- && Mathf . Abs ( m_LastRotationInput ) < kFlickDeltaThreshold ) || mainMenuInput . flickFace . wasJustReleased )
149+
150+ if ( this . GetDeviceType ( ) == DeviceType . Vive )
151151 {
152- m_MainMenuUI . targetFaceIndex += ( int ) Mathf . Sign ( rotationInput ) ;
153- this . Pulse ( node , m_FaceRotationPulse ) ;
152+ if ( ! Mathf . Approximately ( rotationInput , 0f ) )
153+ {
154+ var time = Time . time ;
155+ if ( Mathf . Approximately ( m_LastRotationInput , 0f ) )
156+ {
157+ // Touch began
158+ m_RotationInputStartValue = rotationInput ;
159+ m_RotationInputStartTime = time ;
160+ }
161+ else
162+ {
163+ // Touch held
164+ var distance = rotationInput - m_RotationInputStartValue ;
165+ var lastDistance = m_LastRotationInput - m_RotationInputStartValue ;
166+ if ( Mathf . Abs ( distance ) >= kFlickDeltaThreshold
167+ && Mathf . Abs ( lastDistance ) < kFlickDeltaThreshold
168+ && time - m_RotationInputStartTime < k_MaxFlickDuration )
169+ {
170+ m_RotationInputStartValue = rotationInput ;
171+ m_RotationInputStartTime = time ;
172+ if ( ! m_MainMenuUI . rotating )
173+ {
174+ FlickMenu ( distance ) ;
175+ }
176+ }
177+ }
178+ }
179+ }
180+ else if ( Mathf . Abs ( rotationInput ) >= kFlickDeltaThreshold
181+ && Mathf . Abs ( m_LastRotationInput ) < kFlickDeltaThreshold )
182+ {
183+ FlickMenu ( rotationInput ) ;
154184 }
155-
156- if ( m_MenuHideFlags == 0 )
157- consumeControl ( mainMenuInput . flickFace ) ;
158185
159186 m_LastRotationInput = rotationInput ;
160187 }
161188
189+ void FlickMenu ( float rotationInput )
190+ {
191+ m_MainMenuUI . targetFaceIndex += ( int ) Mathf . Sign ( rotationInput ) ;
192+ this . Pulse ( node , m_FaceRotationPulse ) ;
193+ }
194+
162195 void OnDestroy ( )
163196 {
164197 if ( m_MainMenuUI )
@@ -299,6 +332,11 @@ void OnButtonHovered(Transform rayOrigin, Type buttonType, string buttonDescript
299332 this . PreviewInToolMenuButton ( rayOrigin , buttonType , buttonDescription ) ;
300333 }
301334
335+ void OnToggleHovered ( Transform rayOrigin )
336+ {
337+ this . Pulse ( this . RequestNodeFromRayOrigin ( rayOrigin ) , m_ButtonHoverPulse ) ;
338+ }
339+
302340 void SendVisibilityPulse ( )
303341 {
304342 this . Pulse ( node , m_MenuHideFlags == 0 ? m_HidePulse : m_ShowPulse ) ;
@@ -333,12 +371,29 @@ void AddSettingsMenu(ISettingsMenuProvider provider, MainMenuUI.ButtonData butto
333371 {
334372 buttonData . sectionName = k_SettingsMenuSectionName ;
335373
336- CreateFaceButton ( buttonData , tooltip , ( ) =>
374+ var button = CreateFaceButton ( buttonData , tooltip , ( ) =>
337375 {
338376 var instance = m_MainMenuUI . AddSubmenu ( k_SettingsMenuSectionName , provider . settingsMenuPrefab ) ;
339377 m_SettingsMenus [ provider ] = instance ;
340378 provider . settingsMenuInstance = instance ;
379+ AddToggleHaptics ( instance ) ;
341380 } ) ;
381+
382+ button . hovered += OnButtonHovered ;
383+ button . clicked += OnButtonClicked ;
384+ }
385+
386+ void AddToggleHaptics ( GameObject menuInstance )
387+ {
388+ var toggles = menuInstance . GetComponentsInChildren < MainMenuToggle > ( ) ;
389+ if ( toggles != null && toggles . Length > 0 )
390+ {
391+ foreach ( var toggle in toggles )
392+ {
393+ toggle . hovered += OnToggleHovered ;
394+ toggle . clicked += OnButtonClicked ;
395+ }
396+ }
342397 }
343398
344399 public void RemoveSettingsMenu ( ISettingsMenuProvider provider )
@@ -359,6 +414,7 @@ public void AddSettingsMenuItem(ISettingsMenuItemProvider provider)
359414 var instance = m_MainMenuUI . CreateCustomButton ( provider . settingsMenuItemPrefab , k_SettingsMenuSectionName ) ;
360415 m_SettingsMenuItems [ provider ] = instance ;
361416 provider . settingsMenuItemInstance = instance ;
417+ AddToggleHaptics ( instance ) ;
362418 }
363419
364420 public void RemoveSettingsMenuItem ( ISettingsMenuItemProvider provider )
@@ -376,7 +432,7 @@ public void RemoveSettingsMenuItem(ISettingsMenuItemProvider provider)
376432
377433 void ShowFeedback ( )
378434 {
379- var tooltipText = this . GetDeviceType ( ) == DeviceType . Vive ? "Press to Rotate Menu" : "Rotate Menu" ;
435+ var tooltipText = this . GetDeviceType ( ) == DeviceType . Vive ? "Swipe to Rotate Menu" : "Rotate Menu" ;
380436 List < VRInputDevice . VRControl > controls ;
381437 if ( m_Controls . TryGetValue ( "FlickFace" , out controls ) )
382438 {
0 commit comments