@@ -23,82 +23,149 @@ public bool CanMigrate(GameObject gameObject)
2323 /// <inheritdoc />
2424 public void Migrate ( GameObject gameObject )
2525 {
26- var mh1 = gameObject . GetComponent < ManipulationHandler > ( ) ;
27- var mh2 = gameObject . AddComponent < ObjectManipulator > ( ) ;
26+ var manipHandler = gameObject . GetComponent < ManipulationHandler > ( ) ;
27+ var objManip = gameObject . AddComponent < ObjectManipulator > ( ) ;
2828
29- mh2 . HostTransform = mh1 . HostTransform ;
29+ objManip . HostTransform = manipHandler . HostTransform ;
3030
31- switch ( mh1 . ManipulationType )
31+ switch ( manipHandler . ManipulationType )
3232 {
3333 case ManipulationHandler . HandMovementType . OneHandedOnly :
34- mh2 . ManipulationType = ObjectManipulator . HandMovementType . OneHanded ;
34+ objManip . ManipulationType = ManipulationHandFlags . OneHanded ;
3535 break ;
3636 case ManipulationHandler . HandMovementType . TwoHandedOnly :
37- mh2 . ManipulationType = ObjectManipulator . HandMovementType . TwoHanded ;
37+ objManip . ManipulationType = ManipulationHandFlags . TwoHanded ;
3838 break ;
3939 case ManipulationHandler . HandMovementType . OneAndTwoHanded :
40- mh2 . ManipulationType = ObjectManipulator . HandMovementType . OneHanded |
41- ObjectManipulator . HandMovementType . TwoHanded ;
40+ objManip . ManipulationType = ManipulationHandFlags . OneHanded |
41+ ManipulationHandFlags . TwoHanded ;
4242 break ;
4343 }
4444
45- mh2 . AllowFarManipulation = mh1 . AllowFarManipulation ;
46- mh2 . OneHandRotationModeNear = ( ObjectManipulator . RotateInOneHandType ) mh1 . OneHandRotationModeNear ;
47- mh2 . OneHandRotationModeFar = ( ObjectManipulator . RotateInOneHandType ) mh1 . OneHandRotationModeFar ;
45+ objManip . AllowFarManipulation = manipHandler . AllowFarManipulation ;
4846
49- switch ( mh1 . TwoHandedManipulationType )
47+ if ( manipHandler . OneHandRotationModeNear == manipHandler . OneHandRotationModeFar )
48+ {
49+ MigrateOneHandRotationModes ( ref objManip , manipHandler . OneHandRotationModeNear , ManipulationProximityFlags . Near | ManipulationProximityFlags . Far ) ;
50+ }
51+ else
52+ {
53+ MigrateOneHandRotationModes ( ref objManip , manipHandler . OneHandRotationModeNear , ManipulationProximityFlags . Near ) ;
54+ MigrateOneHandRotationModes ( ref objManip , manipHandler . OneHandRotationModeFar , ManipulationProximityFlags . Far ) ;
55+ }
56+
57+ switch ( manipHandler . TwoHandedManipulationType )
5058 {
5159 case ManipulationHandler . TwoHandedManipulation . Scale :
52- mh2 . TwoHandedManipulationType = TransformFlags . Scale ;
60+ objManip . TwoHandedManipulationType = TransformFlags . Scale ;
5361 break ;
5462 case ManipulationHandler . TwoHandedManipulation . Rotate :
55- mh2 . TwoHandedManipulationType = TransformFlags . Rotate ;
63+ objManip . TwoHandedManipulationType = TransformFlags . Rotate ;
5664 break ;
5765 case ManipulationHandler . TwoHandedManipulation . MoveScale :
58- mh2 . TwoHandedManipulationType = TransformFlags . Move |
66+ objManip . TwoHandedManipulationType = TransformFlags . Move |
5967 TransformFlags . Scale ;
6068 break ;
6169 case ManipulationHandler . TwoHandedManipulation . MoveRotate :
62- mh2 . TwoHandedManipulationType = TransformFlags . Move |
70+ objManip . TwoHandedManipulationType = TransformFlags . Move |
6371 TransformFlags . Rotate ;
6472 break ;
6573 case ManipulationHandler . TwoHandedManipulation . RotateScale :
66- mh2 . TwoHandedManipulationType = TransformFlags . Rotate |
74+ objManip . TwoHandedManipulationType = TransformFlags . Rotate |
6775 TransformFlags . Scale ;
6876 break ;
6977 case ManipulationHandler . TwoHandedManipulation . MoveRotateScale :
70- mh2 . TwoHandedManipulationType = TransformFlags . Move |
78+ objManip . TwoHandedManipulationType = TransformFlags . Move |
7179 TransformFlags . Rotate |
7280 TransformFlags . Scale ;
7381 break ;
7482 }
7583
76- mh2 . ReleaseBehavior = ( ObjectManipulator . ReleaseBehaviorType ) mh1 . ReleaseBehavior ;
84+ objManip . ReleaseBehavior = ( ObjectManipulator . ReleaseBehaviorType ) manipHandler . ReleaseBehavior ;
7785
78- if ( mh1 . ConstraintOnRotation != RotationConstraintType . None )
86+ if ( manipHandler . ConstraintOnRotation != RotationConstraintType . None )
7987 {
80- var rotateConstraint = mh2 . gameObject . AddComponent < RotationAxisConstraint > ( ) ;
81- rotateConstraint . TargetTransform = mh1 . HostTransform ;
82- rotateConstraint . ConstraintOnRotation = RotationConstraintHelper . ConvertToAxisFlags ( mh1 . ConstraintOnRotation ) ;
88+ var rotateConstraint = objManip . EnsureComponent < RotationAxisConstraint > ( ) ;
89+ rotateConstraint . TargetTransform = manipHandler . HostTransform ;
90+ rotateConstraint . ConstraintOnRotation = RotationConstraintHelper . ConvertToAxisFlags ( manipHandler . ConstraintOnRotation ) ;
8391 }
8492
85- if ( mh1 . ConstraintOnMovement == MovementConstraintType . FixDistanceFromHead )
93+ if ( manipHandler . ConstraintOnMovement == MovementConstraintType . FixDistanceFromHead )
8694 {
87- var moveConstraint = mh2 . gameObject . AddComponent < FixedDistanceConstraint > ( ) ;
88- moveConstraint . TargetTransform = mh1 . HostTransform ;
95+ var moveConstraint = objManip . EnsureComponent < FixedDistanceConstraint > ( ) ;
96+ moveConstraint . TargetTransform = manipHandler . HostTransform ;
8997 moveConstraint . ConstraintTransform = CameraCache . Main . transform ;
9098 }
9199
92- mh2 . SmoothingActive = mh1 . SmoothingActive ;
93- mh2 . MoveLerpTime = mh1 . SmoothingAmoutOneHandManip ;
94- mh2 . RotateLerpTime = mh1 . SmoothingAmoutOneHandManip ;
95- mh2 . ScaleLerpTime = mh1 . SmoothingAmoutOneHandManip ;
96- mh2 . OnManipulationStarted = mh1 . OnManipulationStarted ;
97- mh2 . OnManipulationEnded = mh1 . OnManipulationEnded ;
98- mh2 . OnHoverEntered = mh1 . OnHoverEntered ;
99- mh2 . OnHoverExited = mh1 . OnHoverExited ;
100+ objManip . SmoothingActive = manipHandler . SmoothingActive ;
101+ objManip . MoveLerpTime = manipHandler . SmoothingAmoutOneHandManip ;
102+ objManip . RotateLerpTime = manipHandler . SmoothingAmoutOneHandManip ;
103+ objManip . ScaleLerpTime = manipHandler . SmoothingAmoutOneHandManip ;
104+ objManip . OnManipulationStarted = manipHandler . OnManipulationStarted ;
105+ objManip . OnManipulationEnded = manipHandler . OnManipulationEnded ;
106+ objManip . OnHoverEntered = manipHandler . OnHoverEntered ;
107+ objManip . OnHoverExited = manipHandler . OnHoverExited ;
108+
109+ Object . DestroyImmediate ( manipHandler ) ;
110+ }
111+
112+ private void MigrateOneHandRotationModes ( ref ObjectManipulator objManip , ManipulationHandler . RotateInOneHandType mode , ManipulationProximityFlags proximity )
113+ {
114+ ObjectManipulator . RotateInOneHandType newMode = ObjectManipulator . RotateInOneHandType . RotateAboutGrabPoint ;
115+
116+ switch ( mode )
117+ {
118+ case ManipulationHandler . RotateInOneHandType . MaintainRotationToUser :
119+ {
120+ newMode = ObjectManipulator . RotateInOneHandType . RotateAboutGrabPoint ;
121+
122+ var constraint = objManip . EnsureComponent < FixedRotationToUserConstraint > ( ) ;
123+ constraint . TargetTransform = objManip . HostTransform ;
124+ constraint . HandType = ManipulationHandFlags . OneHanded ;
125+ constraint . ProximityType = proximity ;
126+ break ;
127+ }
128+ case ManipulationHandler . RotateInOneHandType . GravityAlignedMaintainRotationToUser :
129+ {
130+ newMode = ObjectManipulator . RotateInOneHandType . RotateAboutGrabPoint ;
100131
101- Object . DestroyImmediate ( mh1 ) ;
132+ var rotConstraint = objManip . EnsureComponent < FixedRotationToUserConstraint > ( ) ;
133+ rotConstraint . TargetTransform = objManip . HostTransform ;
134+ rotConstraint . HandType = ManipulationHandFlags . OneHanded ;
135+ rotConstraint . ProximityType = proximity ;
136+
137+ var axisConstraint = objManip . EnsureComponent < RotationAxisConstraint > ( ) ;
138+ axisConstraint . TargetTransform = objManip . HostTransform ;
139+ axisConstraint . HandType = ManipulationHandFlags . OneHanded ;
140+ axisConstraint . ProximityType = proximity ;
141+ axisConstraint . ConstraintOnRotation = AxisFlags . XAxis | AxisFlags . ZAxis ;
142+ break ;
143+ }
144+ case ManipulationHandler . RotateInOneHandType . FaceUser :
145+ newMode = ObjectManipulator . RotateInOneHandType . FaceUser ;
146+ break ;
147+ case ManipulationHandler . RotateInOneHandType . FaceAwayFromUser :
148+ newMode = ObjectManipulator . RotateInOneHandType . FaceAwayFromUser ;
149+ break ;
150+ case ManipulationHandler . RotateInOneHandType . MaintainOriginalRotation :
151+ newMode = ObjectManipulator . RotateInOneHandType . MaintainOriginalRotation ;
152+ break ;
153+ case ManipulationHandler . RotateInOneHandType . RotateAboutObjectCenter :
154+ newMode = ObjectManipulator . RotateInOneHandType . RotateAboutObjectCenter ;
155+ break ;
156+ case ManipulationHandler . RotateInOneHandType . RotateAboutGrabPoint :
157+ newMode = ObjectManipulator . RotateInOneHandType . RotateAboutGrabPoint ;
158+ break ;
159+ }
160+
161+ if ( proximity . HasFlag ( ManipulationProximityFlags . Near ) )
162+ {
163+ objManip . OneHandRotationModeNear = newMode ;
164+ }
165+ if ( proximity . HasFlag ( ManipulationProximityFlags . Far ) )
166+ {
167+ objManip . OneHandRotationModeFar = newMode ;
168+ }
102169 }
103170 }
104171}
0 commit comments