Exemplo n.º 1
0
        /// <inheritdoc />
        public void Migrate(GameObject gameObject)
        {
            var mh1 = gameObject.GetComponent <ManipulationHandler>();
            var mh2 = gameObject.AddComponent <ObjectManipulator>();

            mh2.HostTransform = mh1.HostTransform;

            switch (mh1.ManipulationType)
            {
            case ManipulationHandler.HandMovementType.OneHandedOnly:
                mh2.ManipulationType = ObjectManipulator.HandMovementType.OneHanded;
                break;

            case ManipulationHandler.HandMovementType.TwoHandedOnly:
                mh2.ManipulationType = ObjectManipulator.HandMovementType.TwoHanded;
                break;

            case ManipulationHandler.HandMovementType.OneAndTwoHanded:
                mh2.ManipulationType = ObjectManipulator.HandMovementType.OneHanded |
                                       ObjectManipulator.HandMovementType.TwoHanded;
                break;
            }

            mh2.AllowFarManipulation    = mh1.AllowFarManipulation;
            mh2.OneHandRotationModeNear = (ObjectManipulator.RotateInOneHandType)mh1.OneHandRotationModeNear;
            mh2.OneHandRotationModeFar  = (ObjectManipulator.RotateInOneHandType)mh1.OneHandRotationModeFar;

            switch (mh1.TwoHandedManipulationType)
            {
            case ManipulationHandler.TwoHandedManipulation.Scale:
                mh2.TwoHandedManipulationType = TransformFlags.Scale;
                break;

            case ManipulationHandler.TwoHandedManipulation.Rotate:
                mh2.TwoHandedManipulationType = TransformFlags.Rotate;
                break;

            case ManipulationHandler.TwoHandedManipulation.MoveScale:
                mh2.TwoHandedManipulationType = TransformFlags.Move |
                                                TransformFlags.Scale;
                break;

            case ManipulationHandler.TwoHandedManipulation.MoveRotate:
                mh2.TwoHandedManipulationType = TransformFlags.Move |
                                                TransformFlags.Rotate;
                break;

            case ManipulationHandler.TwoHandedManipulation.RotateScale:
                mh2.TwoHandedManipulationType = TransformFlags.Rotate |
                                                TransformFlags.Scale;
                break;

            case ManipulationHandler.TwoHandedManipulation.MoveRotateScale:
                mh2.TwoHandedManipulationType = TransformFlags.Move |
                                                TransformFlags.Rotate |
                                                TransformFlags.Scale;
                break;
            }

            mh2.ReleaseBehavior = (ObjectManipulator.ReleaseBehaviorType)mh1.ReleaseBehavior;

            if (mh1.ConstraintOnRotation != RotationConstraintType.None)
            {
                var rotateConstraint = mh2.gameObject.AddComponent <RotationAxisConstraint>();
                rotateConstraint.TargetTransform      = mh1.HostTransform;
                rotateConstraint.ConstraintOnRotation = RotationConstraintHelper.ConvertToAxisFlags(mh1.ConstraintOnRotation);
            }

            if (mh1.ConstraintOnMovement == MovementConstraintType.FixDistanceFromHead)
            {
                var moveConstraint = mh2.gameObject.AddComponent <FixedDistanceConstraint>();
                moveConstraint.TargetTransform     = mh1.HostTransform;
                moveConstraint.ConstraintTransform = CameraCache.Main.transform;
            }

            mh2.SmoothingActive       = mh1.SmoothingActive;
            mh2.MoveLerpTime          = mh1.SmoothingAmoutOneHandManip;
            mh2.RotateLerpTime        = mh1.SmoothingAmoutOneHandManip;
            mh2.ScaleLerpTime         = mh1.SmoothingAmoutOneHandManip;
            mh2.OnManipulationStarted = mh1.OnManipulationStarted;
            mh2.OnManipulationEnded   = mh1.OnManipulationEnded;
            mh2.OnHoverEntered        = mh1.OnHoverEntered;
            mh2.OnHoverExited         = mh1.OnHoverExited;

            Object.DestroyImmediate(mh1);
        }
        /// <inheritdoc />
        public void Migrate(GameObject gameObject)
        {
            var manipHandler = gameObject.GetComponent <ManipulationHandler>();
            var objManip     = gameObject.AddComponent <ObjectManipulator>();

            objManip.HostTransform = manipHandler.HostTransform;

            switch (manipHandler.ManipulationType)
            {
            case ManipulationHandler.HandMovementType.OneHandedOnly:
                objManip.ManipulationType = ManipulationHandFlags.OneHanded;
                break;

            case ManipulationHandler.HandMovementType.TwoHandedOnly:
                objManip.ManipulationType = ManipulationHandFlags.TwoHanded;
                break;

            case ManipulationHandler.HandMovementType.OneAndTwoHanded:
                objManip.ManipulationType = ManipulationHandFlags.OneHanded |
                                            ManipulationHandFlags.TwoHanded;
                break;
            }

            objManip.AllowFarManipulation = manipHandler.AllowFarManipulation;

            if (manipHandler.OneHandRotationModeNear == manipHandler.OneHandRotationModeFar)
            {
                MigrateOneHandRotationModes(ref objManip, manipHandler.OneHandRotationModeNear, ManipulationProximityFlags.Near | ManipulationProximityFlags.Far);
            }
            else
            {
                MigrateOneHandRotationModes(ref objManip, manipHandler.OneHandRotationModeNear, ManipulationProximityFlags.Near);
                MigrateOneHandRotationModes(ref objManip, manipHandler.OneHandRotationModeFar, ManipulationProximityFlags.Far);
            }

            switch (manipHandler.TwoHandedManipulationType)
            {
            case ManipulationHandler.TwoHandedManipulation.Scale:
                objManip.TwoHandedManipulationType = TransformFlags.Scale;
                break;

            case ManipulationHandler.TwoHandedManipulation.Rotate:
                objManip.TwoHandedManipulationType = TransformFlags.Rotate;
                break;

            case ManipulationHandler.TwoHandedManipulation.MoveScale:
                objManip.TwoHandedManipulationType = TransformFlags.Move |
                                                     TransformFlags.Scale;
                break;

            case ManipulationHandler.TwoHandedManipulation.MoveRotate:
                objManip.TwoHandedManipulationType = TransformFlags.Move |
                                                     TransformFlags.Rotate;
                break;

            case ManipulationHandler.TwoHandedManipulation.RotateScale:
                objManip.TwoHandedManipulationType = TransformFlags.Rotate |
                                                     TransformFlags.Scale;
                break;

            case ManipulationHandler.TwoHandedManipulation.MoveRotateScale:
                objManip.TwoHandedManipulationType = TransformFlags.Move |
                                                     TransformFlags.Rotate |
                                                     TransformFlags.Scale;
                break;
            }

            objManip.ReleaseBehavior = (ObjectManipulator.ReleaseBehaviorType)manipHandler.ReleaseBehavior;

            if (manipHandler.ConstraintOnRotation != RotationConstraintType.None)
            {
                var rotateConstraint = objManip.EnsureComponent <RotationAxisConstraint>();
                rotateConstraint.TargetTransform      = manipHandler.HostTransform;
                rotateConstraint.ConstraintOnRotation = RotationConstraintHelper.ConvertToAxisFlags(manipHandler.ConstraintOnRotation);
            }

            if (manipHandler.ConstraintOnMovement == MovementConstraintType.FixDistanceFromHead)
            {
                var moveConstraint = objManip.EnsureComponent <FixedDistanceConstraint>();
                moveConstraint.TargetTransform     = manipHandler.HostTransform;
                moveConstraint.ConstraintTransform = CameraCache.Main.transform;
            }

            objManip.SmoothingActive       = manipHandler.SmoothingActive;
            objManip.MoveLerpTime          = manipHandler.SmoothingAmoutOneHandManip;
            objManip.RotateLerpTime        = manipHandler.SmoothingAmoutOneHandManip;
            objManip.ScaleLerpTime         = manipHandler.SmoothingAmoutOneHandManip;
            objManip.OnManipulationStarted = manipHandler.OnManipulationStarted;
            objManip.OnManipulationEnded   = manipHandler.OnManipulationEnded;
            objManip.OnHoverEntered        = manipHandler.OnHoverEntered;
            objManip.OnHoverExited         = manipHandler.OnHoverExited;

            // finally check if there's a CursorContextManipulationHandler on the gameObject that we have to swap
            CursorContextManipulationHandler cursorContextManipHandler = gameObject.GetComponent <CursorContextManipulationHandler>();

            if (cursorContextManipHandler)
            {
                gameObject.AddComponent <CursorContextObjectManipulator>();
                // remove old component
                Object.DestroyImmediate(cursorContextManipHandler);
            }

            Object.DestroyImmediate(manipHandler);
        }