Exemplo n.º 1
0
    public void HandleDescent()
    {
        switch (descendStage)
        {
        case DescendStage.WaitToLower:
            if (Time.time > waitToLowerStartTime + WAIT_TO_LOWER_TIME)
            {
                waitToLowerStartTime = -1;

                silkManager.ActivateSilk();

                lowerStartTime = Time.time;
                descendStage   = DescendStage.LowerFromCeiling;
                SetLowerAnim();
            }
            break;

        case DescendStage.LowerFromCeiling:

            if (Time.time - LOWER_DURATION > lowerStartTime)
            {
                lowerStartTime = -1;

                descentStartTime = Time.time;
                descendStage     = DescendStage.Descend1;
                SetDescendAnim();
            }
            break;

        case DescendStage.Descend1:
            transform.position += new Vector3(0, -DESCEND_SPEED * Time.deltaTime);

            if (Time.time > descentStartTime + TIME_BETWEEN_CHANGING_DESCENT_TYPES)
            {
                descentStartTime = -1;

                preDescendChangeZ         = transform.position.z;
                firstFrameOfDescendChange = true;

                grabHandler.enabled            = true; //TODO why?
                grabHandler.checkForCollisions = false;
                descendStage = DescendStage.Descend2;
                SetDescend2Anim();

                if (Random.Range(0, 2) == 0)
                {
                    //Debug.Log("Random 0");
                    descendDirectionMultiplier = 1;
                }
                else
                {
                    descendDirectionMultiplier = -1;
                    //Debug.Log("Random 1");
                }

                //Descend2 uses the inverted of the descend animation, so flip by 180
                gameObject.transform.Rotate(Vector3.right, 180);

                ToggleNonTriggerColliders(true);
            }
            break;

        case DescendStage.Descend2:
            transform.position += new Vector3(0, -DESCEND_SPEED * Time.deltaTime);

            if (transform.position.y < descendLimitY)
            {
                initialDepth = modelPositionCheckGO.transform.position.z;
                targetHeight = modelPositionCheckGO.transform.position.y;

                grabHandler.ToggleGrabbable(false);
                descendStage = DescendStage.DropToTable;
                SetDropAnim();
                dropStartTime = Time.time;
            }
            else
            {
                gameObject.transform.Rotate(Vector3.down, ROTATE_DURING_DESCENT_SPEED * Time.deltaTime * descendDirectionMultiplier);
            }

            break;

        case DescendStage.DropToTable:

            //Correct the absolute WHACK translations while transitioning to the drop animation
            if (transform.position.y > motionCorrectionY)
            {
                targetHeight -= DESCEND_SPEED * Time.deltaTime;

                float depthDifference  = modelPositionCheckGO.transform.position.z - initialDepth;
                float heightDifference = modelPositionCheckGO.transform.position.y - targetHeight;

                transform.position += new Vector3(0, -heightDifference, -depthDifference);
            }

            //Once we land on the table, switch to random pathing (after a small wait)
            if (Time.time > dropStartTime + DROP_TIME)
            {
                //Debug.Log("WE JUST LEFT DROP");
                randomPathWaitStartTime = Time.time;

                silkManager.FadeSilk();

                grabHandler.enabled = true;
                grabHandler.ToggleGrabbable(true);

                SetIdleAnim();
                descendStage = DescendStage.WaitToPath;
            }
            break;

        case DescendStage.WaitToPath:

            if (Time.time > randomPathWaitStartTime + RANDOM_PATH_WAIT_TIME)
            {
                randomPathWaitStartTime = -1;

                descendStage = DescendStage.None;
                SwitchToRandomPathing();
            }
            break;
        }
    }