@@ -23,58 +23,41 @@ public ConstraintManager(GameObject gameObject)
2323
2424 public void ApplyScaleConstraints ( ref MixedRealityTransform transform , bool isOneHanded , bool isNear )
2525 {
26- ManipulationHandFlags handMode = isOneHanded ? ManipulationHandFlags . OneHanded : ManipulationHandFlags . TwoHanded ;
27- ManipulationProximityFlags proximityMode = isNear ? ManipulationProximityFlags . Near : ManipulationProximityFlags . Far ;
28-
29- foreach ( var constraint in constraints )
30- {
31- if ( constraint . ConstraintType == Utilities . TransformFlags . Scale &&
32- constraint . HandType . HasFlag ( handMode ) &&
33- constraint . ProximityType . HasFlag ( proximityMode ) )
34- {
35- constraint . ApplyConstraint ( ref transform ) ;
36- }
37- }
26+ ApplyConstraintsForType ( ref transform , isOneHanded , isNear , TransformFlags . Scale ) ;
3827 }
3928
4029 public void ApplyRotationConstraints ( ref MixedRealityTransform transform , bool isOneHanded , bool isNear )
4130 {
42- ManipulationHandFlags handMode = isOneHanded ? ManipulationHandFlags . OneHanded : ManipulationHandFlags . TwoHanded ;
43- ManipulationProximityFlags proximityMode = isNear ? ManipulationProximityFlags . Near : ManipulationProximityFlags . Far ;
44-
31+ ApplyConstraintsForType ( ref transform , isOneHanded , isNear , TransformFlags . Rotate ) ;
32+ }
33+
34+ public void ApplyTranslationConstraints ( ref MixedRealityTransform transform , bool isOneHanded , bool isNear )
35+ {
36+ ApplyConstraintsForType ( ref transform , isOneHanded , isNear , TransformFlags . Move ) ;
37+ }
38+
39+ public void Initialize ( MixedRealityPose worldPose )
40+ {
4541 foreach ( var constraint in constraints )
4642 {
47- if ( constraint . ConstraintType == Utilities . TransformFlags . Rotate &&
48- constraint . HandType . HasFlag ( handMode ) &&
49- constraint . ProximityType . HasFlag ( proximityMode ) )
50- {
51- constraint . ApplyConstraint ( ref transform ) ;
52- }
43+ constraint . Initialize ( worldPose ) ;
5344 }
5445 }
5546
56- public void ApplyTranslationConstraints ( ref MixedRealityTransform transform , bool isOneHanded , bool isNear )
47+ private void ApplyConstraintsForType ( ref MixedRealityTransform transform , bool isOneHanded , bool isNear , TransformFlags transformType )
5748 {
5849 ManipulationHandFlags handMode = isOneHanded ? ManipulationHandFlags . OneHanded : ManipulationHandFlags . TwoHanded ;
5950 ManipulationProximityFlags proximityMode = isNear ? ManipulationProximityFlags . Near : ManipulationProximityFlags . Far ;
60-
51+
6152 foreach ( var constraint in constraints )
6253 {
63- if ( constraint . ConstraintType == Utilities . TransformFlags . Move &&
54+ if ( constraint . ConstraintType == transformType &&
6455 constraint . HandType . HasFlag ( handMode ) &&
6556 constraint . ProximityType . HasFlag ( proximityMode ) )
6657 {
6758 constraint . ApplyConstraint ( ref transform ) ;
6859 }
6960 }
7061 }
71-
72- public void Initialize ( MixedRealityPose worldPose )
73- {
74- foreach ( var constraint in constraints )
75- {
76- constraint . Initialize ( worldPose ) ;
77- }
78- }
7962 }
8063}
0 commit comments