Пример #1
0
    private void OnTriggerExit(Collider other)
    {
        if (doorrotation.ResetOnLeave)
        {
            bool DoorWasMoved  = doorrotation.transform.rotation == doorrotation.EndRotation * doorrotation.RotationOffset;
            bool HingeWasMoved = doorrotation.transform.parent.transform.rotation == doorrotation.EndRotation;

            if (doorrotation.PivotPosition == DoorRotation.PositionOfPivot.CorrectlyPositioned)
            {
                if (doorrotation.AngleConvention == 0 && DoorWasMoved)
                {
                    StartCoroutine(RotationTools.Rotate(doorrotation.gameObject, -doorrotation.InitialYRotation + doorrotation.RotationTimeline[0].FinalAngle, doorrotation.RotationTimeline[0].InitialAngle - doorrotation.InitialYRotation, 2, false, 0, doorrotation.ShortestWay));
                }
                else if (doorrotation.AngleConvention == 1 && DoorWasMoved)
                {
                    StartCoroutine(RotationTools.Rotate(doorrotation.gameObject, -doorrotation.InitialYRotation - doorrotation.RotationTimeline[0].FinalAngle, -doorrotation.RotationTimeline[0].InitialAngle - doorrotation.InitialYRotation, 2, false, 0, doorrotation.ShortestWay));
                }
            }

            if (doorrotation.PivotPosition == DoorRotation.PositionOfPivot.Centered)
            {
                if (doorrotation.AngleConvention == 0 && HingeWasMoved)
                {
                    StartCoroutine(RotationTools.Rotate(doorrotation.transform.parent.gameObject, doorrotation.RotationTimeline[0].FinalAngle, doorrotation.RotationTimeline[0].InitialAngle, 2, false, 0, doorrotation.ShortestWay));
                }
                else if (doorrotation.AngleConvention == 1 && HingeWasMoved)
                {
                    StartCoroutine(RotationTools.Rotate(doorrotation.transform.parent.gameObject, -doorrotation.RotationTimeline[0].FinalAngle, -doorrotation.RotationTimeline[0].InitialAngle, 2, false, 0, doorrotation.ShortestWay));
                }
            }

            doorrotation.CurrentRotationBlockIndex = 0;
            doorrotation.TimesRotated = 0;
        }
    }
Пример #2
0
    void lookCharacter(Vector2 input)
    {
        var horizontalLook = input.x * Vector3.up * Time.deltaTime;

        transform.localRotation *= Quaternion.Euler(horizontalLook);

        var verticalLook  = input.y * Vector3.left * Time.deltaTime;
        var newQuaternion =
            _camera.transform.localRotation * Quaternion.Euler(verticalLook);

        _camera.transform.localRotation =
            RotationTools.ClampRotationAroundXAxis(
                newQuaternion, -maxViewAngle, -minViewAngle);
    }
Пример #3
0
    public IEnumerator Swing(bool front)
    {
        RotationPending = true;

        Transform t = transform;

        RotationTimelineData CurrentRotationBlock = RotationTimeline[CurrentRotationBlockIndex];

        float TimeProgression = 0f;

        if (AngleConvention == 0) // Alex's Door System Convention
        {
            SwingStart = Quaternion.Euler(0, -CurrentRotationBlock.FrontAngle, 0);
            SwingMid   = Quaternion.Euler(0, -CurrentRotationBlock.MiddleAngle, 0);
            SwingEnd   = Quaternion.Euler(0, -CurrentRotationBlock.BackAngle, 0);
        }

        else if (AngleConvention == 1) // Unity Convention
        {
            SwingStart = Quaternion.Euler(0, CurrentRotationBlock.FrontAngle, 0);
            SwingMid   = Quaternion.Euler(0, CurrentRotationBlock.MiddleAngle, 0);
            SwingEnd   = Quaternion.Euler(0, CurrentRotationBlock.BackAngle, 0);
        }

        if (DoorScale == ScaleOfDoor.Unity3DUnits && PivotPosition == PositionOfPivot.Centered)
        {
            t = hinge.transform;

            if (TimesRotated == 0 && SwingState == 1)
            {
                t.rotation = SwingStart;
            }

            if (TimesRotated == 0 && SwingState == 2)
            {
                t.rotation = SwingMid;
            }

            if (TimesRotated == 0 && SwingState == 3)
            {
                t.rotation = SwingEnd;
            }
        }

        else if (PivotPosition == PositionOfPivot.CorrectlyPositioned)
        {
            if (TimesRotated == 0)
            {
                t.rotation = StartRotation;
            }
        }

        if (TimesRotated < CurrentRotationBlock.TimesMoveable || CurrentRotationBlock.TimesMoveable == 0)
        {
            while (TimeProgression <= (1 / CurrentRotationBlock.Speed))
            {
                TimeProgression += Time.deltaTime;
                float RotationProgression = Mathf.Clamp01(TimeProgression / (1 / CurrentRotationBlock.Speed));
                float RotationCurveValue  = CurrentRotationBlock.RotationCurve.Evaluate(RotationProgression);

                if (front)
                {
                    if (SwingState == 1)
                    {
                        t.rotation = RotationTools.Lerp(SwingStart, SwingMid, RotationCurveValue, ShortestWay);
                    }
                    if (SwingState == 2)
                    {
                        t.rotation = RotationTools.Lerp(SwingMid, SwingEnd, RotationCurveValue, ShortestWay);
                    }
                    if (SwingState == 3)
                    {
                        t.rotation = RotationTools.Lerp(SwingEnd, SwingMid, RotationCurveValue, ShortestWay);
                    }
                }

                if (!front)
                {
                    if (SwingState == 3)
                    {
                        t.rotation = RotationTools.Lerp(SwingEnd, SwingMid, RotationCurveValue, ShortestWay);
                    }
                    if (SwingState == 2)
                    {
                        t.rotation = RotationTools.Lerp(SwingMid, SwingStart, RotationCurveValue, ShortestWay);
                    }
                    if (SwingState == 1)
                    {
                        t.rotation = RotationTools.Lerp(SwingStart, SwingMid, RotationCurveValue, ShortestWay);
                    }
                }

                yield return(null);
            }

            if (front && SwingState == 1)
            {
                SwingState++;
            }
            else if (front && SwingState == 2)
            {
                SwingState++;
            }
            else if (front && SwingState == 3)
            {
                SwingState--;
            }

            else if (!front && SwingState == 1)
            {
                SwingState++;
            }
            else if (!front && SwingState == 2)
            {
                SwingState--;
            }
            else if (!front && SwingState == 3)
            {
                SwingState--;
            }

            TimesRotated++;

            if (TimesRotated == CurrentRotationBlock.TimesMoveable && CurrentRotationBlock.TimesMoveable != 0)
            {
                TimesRotated = 0;
                CurrentRotationBlockIndex++;
            }
        }
        RotationPending = false;
    }
Пример #4
0
    public IEnumerator Rotate()
    {
        RotationPending = true;

        Transform t = transform;

        RotationTimelineData CurrentRotationBlock = RotationTimeline[CurrentRotationBlockIndex];

        float TimeProgression = 0f;

        if (CurrentRotationBlock.RotationType == RotationTimelineData.TypeOfRotation.SingleRotation)
        {
            CurrentRotationBlock.TimesMoveable = 1;
        }

        if (AngleConvention == 0) // Alex's Door System Convention
        {
            StartRotation = Quaternion.Euler(0, -CurrentRotationBlock.InitialAngle, 0);
            EndRotation   = Quaternion.Euler(0, -CurrentRotationBlock.FinalAngle, 0);
        }

        else if (AngleConvention == 1) // Unity Convention
        {
            StartRotation = Quaternion.Euler(0, CurrentRotationBlock.InitialAngle, 0);
            EndRotation   = Quaternion.Euler(0, CurrentRotationBlock.FinalAngle, 0);
        }

        if (DoorScale == ScaleOfDoor.Unity3DUnits && PivotPosition == PositionOfPivot.Centered)
        {
            t = hinge.transform;
            RotationOffset = Quaternion.identity;
        }

        if (TimesRotated == 0)
        {
            t.rotation = StartRotation * RotationOffset;
        }

        if (TimesRotated < CurrentRotationBlock.TimesMoveable || CurrentRotationBlock.TimesMoveable == 0)
        {
            if (t.rotation == (RotationState == 0 ? EndRotation * RotationOffset : StartRotation *RotationOffset))
            {
                RotationState ^= 1;
            }

            while (TimeProgression <= (1 / CurrentRotationBlock.Speed))
            {
                TimeProgression += Time.deltaTime;
                float RotationProgression = Mathf.Clamp01(TimeProgression / (1 / CurrentRotationBlock.Speed));
                float RotationCurveValue  = CurrentRotationBlock.RotationCurve.Evaluate(RotationProgression);

                if (RotationState == 0) // Door is closed
                {
                    t.rotation = RotationTools.Lerp(StartRotation * RotationOffset, EndRotation * RotationOffset, RotationCurveValue, ShortestWay);
                }

                if (RotationState == 1) // Door is opened
                {
                    t.rotation = RotationTools.Lerp(EndRotation * RotationOffset, StartRotation * RotationOffset, RotationCurveValue, ShortestWay);
                }

                yield return(null);
            }

            TimesRotated++;

            if (TimesRotated == CurrentRotationBlock.TimesMoveable && CurrentRotationBlock.TimesMoveable != 0)
            {
                TimesRotated = 0;
                CurrentRotationBlockIndex++;
            }
        }
        RotationPending = false;
    }