Beispiel #1
0
    private IEnumerator GrabObjectWithStick(GameObject objectToStick)
    {
        if (stick.foods.Count >= stick.ingredientsPivots.Length)
        {
            yield break;
        }

        controller.acting = true;
        float      timePassed = 0;
        Vector3    startPos   = initPos;
        Vector3    endPos     = Vector3.up * (stick.foods.Count + 1);
        Quaternion startRot   = initRot;
        Quaternion endRot     = initRot * Quaternion.AngleAxis(90, transform.forward);

        endPos.y = 0;
        float duration = stickGrabDuration / 2;

        //Disable collisions
        foreach (Food item in stick.foods)
        {
            item.col.enabled = false;
        }

        //Down
        while (timePassed < duration)
        {
            timePassed += Time.deltaTime;

            float value = stickGrabCurveDown.Evaluate(timePassed / duration);
            handPivot.localPosition = Vector3.LerpUnclamped(startPos, endPos, value);
            value = stickGrabRotationCurveDown.Evaluate(timePassed / duration);
            handPivot.localRotation = Quaternion.SlerpUnclamped(startRot, endRot, value);

            yield return(null);
        }

        //Stick ingredient
        if (objectToStick.tag != "Stick")
        {
            ObjectPool pool = objectToStick.GetComponent <ObjectPool>();
            if (pool != null)
            {
                objectToStick = pool.GetPooledObject();
                objectToStick.GetComponent <Poolable>().pool = pool;
            }

            Food food = objectToStick.GetComponent <Food>();
            food.col.enabled = false;
            stick.AddIngredient(food);
            Sound_Manager.Instance.PlayRandomSFX(food.grabClips);
        }

        grill.RemoveFromGrill(objectToStick.GetComponent <Cookable>());

        //Up
        timePassed = 0;
        startPos   = endPos;
        endPos     = initPos;
        startRot   = endRot;
        endRot     = initRot;

        while (timePassed < duration)
        {
            timePassed += Time.deltaTime;

            float value = stickGrabCurveUp.Evaluate(timePassed / duration);
            handPivot.localPosition = Vector3.LerpUnclamped(startPos, endPos, value);
            value = stickGrabRotationCurveUp.Evaluate(timePassed / duration);
            handPivot.localRotation = Quaternion.SlerpUnclamped(startRot, endRot, value);

            yield return(null);
        }

        handPivot.localPosition = initPos;
        handPivot.localRotation = initRot;
        controller.acting       = false;
        finishedGrabbing        = true;

        //Enable Collisions
        foreach (Food item in stick.foods)
        {
            item.col.enabled = true;
        }
    }