@@ -140,43 +140,79 @@ internal void SetDefaultInteractionMapping(bool overwrite = false)
140140
141141 internal bool UpdateInteractionSettingsFromDefault ( )
142142 {
143+ if ( interactions == null || interactions . Length == 0 ) { return false ; }
144+
145+ MixedRealityInteractionMapping [ ] newDefaultInteractions = GetDefaultInteractionMappings ( ) ;
146+
147+ if ( newDefaultInteractions == null )
148+ {
149+ return false ;
150+ }
151+
152+ if ( interactions . Length != newDefaultInteractions . Length )
153+ {
154+ interactions = CreateNewMatchedMapping ( interactions , newDefaultInteractions ) ;
155+ return true ;
156+ }
157+
143158 bool updatedMappings = false ;
144159
145- if ( interactions ? . Length > 0 )
160+ for ( int i = 0 ; i < newDefaultInteractions . Length ; i ++ )
146161 {
147- MixedRealityInteractionMapping [ ] newDefaultInteractions = GetDefaultInteractionMappings ( ) ;
162+ MixedRealityInteractionMapping currentMapping = interactions [ i ] ;
163+ MixedRealityInteractionMapping currentDefaultMapping = newDefaultInteractions [ i ] ;
148164
149- if ( newDefaultInteractions == null )
165+ if ( Equals ( currentMapping , currentDefaultMapping ) )
150166 {
151- return updatedMappings ;
167+ interactions [ i ] = new MixedRealityInteractionMapping ( currentDefaultMapping )
168+ {
169+ MixedRealityInputAction = currentMapping . MixedRealityInputAction
170+ } ;
171+
172+ updatedMappings = true ;
152173 }
174+ }
153175
154- for ( int i = 0 ; i < newDefaultInteractions . Length ; i ++ )
176+ return updatedMappings ;
177+ }
178+
179+ private MixedRealityInteractionMapping [ ] CreateNewMatchedMapping ( MixedRealityInteractionMapping [ ] interactions , MixedRealityInteractionMapping [ ] newDefaultInteractions )
180+ {
181+ MixedRealityInteractionMapping [ ] newDefaultMapping = new MixedRealityInteractionMapping [ newDefaultInteractions . Length ] ;
182+
183+ for ( int i = 0 ; i < newDefaultInteractions . Length ; i ++ )
184+ {
185+ for ( int j = 0 ; j < interactions . Length ; j ++ )
155186 {
156- MixedRealityInteractionMapping currentMapping = interactions [ i ] ;
157- MixedRealityInteractionMapping currentDefaultMapping = newDefaultInteractions [ i ] ;
158-
159- if ( currentMapping . Id != currentDefaultMapping . Id ||
160- currentMapping . Description != currentDefaultMapping . Description ||
161- currentMapping . AxisType != currentDefaultMapping . AxisType ||
162- currentMapping . InputType != currentDefaultMapping . InputType ||
163- currentMapping . KeyCode != currentDefaultMapping . KeyCode ||
164- currentMapping . AxisCodeX != currentDefaultMapping . AxisCodeX ||
165- currentMapping . AxisCodeY != currentDefaultMapping . AxisCodeY ||
166- currentMapping . InvertXAxis != currentDefaultMapping . InvertXAxis ||
167- currentMapping . InvertYAxis != currentDefaultMapping . InvertYAxis )
187+ if ( Equals ( interactions [ j ] , newDefaultInteractions [ i ] ) )
168188 {
169- interactions [ i ] = new MixedRealityInteractionMapping ( currentDefaultMapping )
189+ newDefaultMapping [ i ] = new MixedRealityInteractionMapping ( newDefaultInteractions [ i ] )
170190 {
171- MixedRealityInputAction = currentMapping . MixedRealityInputAction
191+ MixedRealityInputAction = interactions [ j ] . MixedRealityInputAction
172192 } ;
173-
174- updatedMappings = true ;
193+ break ;
175194 }
176195 }
196+
197+ if ( newDefaultMapping [ i ] == null )
198+ {
199+ newDefaultMapping [ i ] = new MixedRealityInteractionMapping ( newDefaultInteractions [ i ] ) ;
200+ }
177201 }
178202
179- return updatedMappings ;
203+ return newDefaultMapping ;
204+ }
205+
206+ private bool Equals ( MixedRealityInteractionMapping a , MixedRealityInteractionMapping b )
207+ {
208+ return ! ( a . Description != b . Description ||
209+ a . AxisType != b . AxisType ||
210+ a . InputType != b . InputType ||
211+ a . KeyCode != b . KeyCode ||
212+ a . AxisCodeX != b . AxisCodeX ||
213+ a . AxisCodeY != b . AxisCodeY ||
214+ a . InvertXAxis != b . InvertXAxis ||
215+ a . InvertYAxis != b . InvertYAxis ) ;
180216 }
181217
182218 private MixedRealityInteractionMapping [ ] GetDefaultInteractionMappings ( )
0 commit comments