示例#1
0
 public void Update(DragTrack track, Moveable_Drag draggable)
 {
     track.ApplyAutoForce(targetValue, speed, draggable);
 }
示例#2
0
        /**
         * <summary>Applies a drag force on the object, based on the movement of the cursor.</summary>
         * <param name = "force">The force vector to apply</param>
         * <param name = "mousePosition">The position of the mouse</param>
         * <param name = "_distanceToCamera">The distance between the object's centre and the camera</param>
         */
        public override void ApplyDragForce(Vector3 force, Vector3 mousePosition, float _distanceToCamera)
        {
            distanceToCamera = _distanceToCamera;

            // Scale force
            force *= speedFactor * distanceToCamera / 50f;

            // Limit magnitude
            if (force.magnitude > maxSpeed)
            {
                force *= maxSpeed / force.magnitude;
            }

            if (dragMode == DragMode.LockToTrack)
            {
                if (track != null)
                {
                    switch (track.dragMovementCalculation)
                    {
                    case DragMovementCalculation.DragVector:
                        track.ApplyDragForce(force, this);
                        break;

                    case DragMovementCalculation.CursorPosition:
                        float mousePositionAlong = track.GetScreenPointProportionAlong(mousePosition);
                        float totalPositionAlong = mousePositionAlong + screenToWorldOffset;

                        if (track.preventEndToEndJumping)
                        {
                            bool inDeadZone = (totalPositionAlong >= 1f || totalPositionAlong <= 0f);
                            if (endLocked)
                            {
                                if (!inDeadZone)
                                {
                                    endLocked = false;
                                }
                            }
                            else
                            {
                                if (inDeadZone)
                                {
                                    endLocked = true;
                                }
                            }

                            if (track.Loops || !endLocked)
                            {
                                lastFrameTotalCursorPositionAlong = totalPositionAlong;
                            }
                            else
                            {
                                totalPositionAlong = lastFrameTotalCursorPositionAlong;
                            }
                        }

                        track.ApplyAutoForce(totalPositionAlong, speedFactor / 10f, this);
                        break;
                    }
                }
            }
            else
            {
                Vector3 newRot = Vector3.Cross(force, KickStarter.CameraMain.transform.forward);

                if (dragMode == DragMode.MoveAlongPlane)
                {
                    if (alignMovement == AlignDragMovement.AlignToPlane)
                    {
                        if (plane)
                        {
                            _rigidbody.AddForceAtPosition(Vector3.Cross(newRot, plane.up), transform.position + (plane.up * grabDistance));
                        }
                        else
                        {
                            ACDebug.LogWarning("No alignment plane assigned to " + this.name, this);
                        }
                    }
                    else
                    {
                        _rigidbody.AddForceAtPosition(force, transform.position - (KickStarter.CameraMain.transform.forward * grabDistance));
                    }
                }
                else if (dragMode == DragMode.RotateOnly)
                {
                    newRot /= Mathf.Sqrt((grabPoint.position - transform.position).magnitude) * 2.4f * rotationFactor;

                    if (moveWithRigidbody)
                    {
                        _rigidbody.AddTorque(newRot);
                    }
                    else
                    {
                        //transform.Rotate (newRot, Space.World);
                        thisFrameTorque = newRot;
                    }

                    if (allowZooming)
                    {
                        UpdateZoom();
                    }
                }
            }
        }
示例#3
0
        /**
         * Called every frame by StateHandler.
         */
        public override void UpdateMovement()
        {
            base.UpdateMovement();

            if (dragMode == DragMode.LockToTrack && track)
            {
                if (track && (_rigidbody.angularVelocity != Vector3.zero || _rigidbody.velocity != Vector3.zero))
                {
                    track.UpdateDraggable(this);

                    if (interactionOnMove && gameObject.layer != LayerMask.NameToLayer(KickStarter.settingsManager.deactivatedLayer))
                    {
                        if (!KickStarter.actionListManager.IsListRunning(interactionOnMove))
                        {
                            interactionOnMove.Interact();
                        }
                    }
                }
                else if (targetTrackSpeed > 0f)
                {
                    trackValue = track.GetDecimalAlong(this);
                }

                if (targetTrackSpeed > 0f)
                {
                    if ((targetTrackValue == 0f && trackValue < 0.01f) ||
                        (targetTrackValue == 1f && trackValue > 0.99f))
                    {
                        // Special case, since colliders cause ends to not quite be met
                        StopAutoMove();
                    }
                    else if ((targetStartedGreater && targetTrackValue > trackValue) || (!targetStartedGreater && targetTrackValue < trackValue))
                    {
                        track.ApplyAutoForce(targetTrackValue, targetTrackSpeed, this);
                    }
                    else
                    {
                        StopAutoMove();
                    }
                }

                if (collideSound && collideSoundClip && track is DragTrack_Hinge)
                {
                    if (trackValue > 0.05f && trackValue < 0.95f)
                    {
                        canPlayCollideSound = true;
                    }
                    else if ((trackValue == 0f || (!onlyPlayLowerCollisionSound && trackValue == 1f)) && canPlayCollideSound)
                    {
                        canPlayCollideSound = false;
                        collideSound.Play(collideSoundClip, false);
                    }
                }

                if (targetTrackSpeed == 0f && !isHeld && (trackValue == 0f || trackValue == 1f))
                {
                    _rigidbody.isKinematic = true;
                }
                else
                {
                    _rigidbody.isKinematic = false;
                }
            }
            else if (isHeld)
            {
                if (dragMode == DragMode.RotateOnly && allowZooming && distanceToCamera > 0f)
                {
                    LimitZoom();
                }
            }

            if (moveSoundClip && moveSound)
            {
                if (dragMode == DragMode.LockToTrack && track && track is DragTrack_Hinge)
                {
                    PlayMoveSound(_rigidbody.angularVelocity.magnitude, trackValue);
                }
                else
                {
                    PlayMoveSound(_rigidbody.velocity.magnitude, trackValue);
                }
            }
        }
示例#4
0
        public override void UpdateMovement()
        {
            base.UpdateMovement();
            if (dragMode == DragMode.LockToTrack && track)
            {
                track.UpdateDraggable(this);

                if (UsesRigidbody && (_rigidbody.angularVelocity != Vector3.zero || _rigidbody.velocity != Vector3.zero))
                {
                    RunInteraction(true);
                }

                if (IsAutoMoving())
                {
                    if (activeAutoMove.CheckForEnd(this))
                    {
                        StopAutoMove(true);
                    }
                }
                else if (!UsesRigidbody && dragMode == DragMode.LockToTrack && track)
                {
                    if (IsHeld)
                    {
                        heldIntensity = 1f;
                    }
                    else
                    {
                        if (heldIntensity > 0.01f && trackValue > 0f && trackValue < 1f)
                        {
                            switch (track.dragMovementCalculation)
                            {
                            case DragMovementCalculation.DragVector:
                                track.ApplyDragForce(lastFrameForce * heldIntensity, this);
                                break;

                            case DragMovementCalculation.CursorPosition:
                                if (simulatedMass > 0)
                                {
                                    track.ApplyAutoForce(lastFrameTotalPositionAlong, heldIntensity * speedFactor * 0.02f / simulatedMass, this, false);
                                }
                                break;

                            default:
                                break;
                            }
                        }
                        heldIntensity = Mathf.Lerp(heldIntensity, 0f, Time.deltaTime * simulatedMass);
                    }
                }

                if (collideSound && !track.UsesEndColliders)
                {
                    if (trackValue > 0.03f && trackValue < 0.97f)
                    {
                        canPlayCollideSound = true;
                    }
                    else if ((Mathf.Approximately(trackValue, 0f) || (!onlyPlayLowerCollisionSound && Mathf.Approximately(trackValue, 1f))) && canPlayCollideSound)
                    {
                        canPlayCollideSound = false;
                        collideSound.Play(collideSoundClip, false);
                    }
                }
            }
            else if (isHeld)
            {
                if (dragMode == DragMode.RotateOnly && allowZooming && distanceToCamera > 0f)
                {
                    LimitZoom();
                }
            }

            if (moveSoundClip && moveSound)
            {
                if (dragMode == DragMode.LockToTrack && track)
                {
                    PlayMoveSound(track.GetMoveSoundIntensity(trackValue - lastFrameTrackValue));
                }
                else if (_rigidbody)
                {
                    PlayMoveSound(_rigidbody.velocity.magnitude);
                }
            }

            lastFrameTrackValue = trackValue;
        }