Пример #1
0
    IEnumerator ConsumeResourceRoutine(BaseResource resource)
    {
        state = resource.ResourceType == Resource.Food
                ? State.Eating
                : State.Drinking;

        // To track whether the resource was consumed and we can change it
        // Since the state of the "IsConsumable" will change once consumed
        bool consumed = true;

        if (!resource.IsConsumable)
        {
            consumed = false;
            yield return(new WaitForSeconds(timeBeforeDisplayResourceNotFound));

            yield return(StartCoroutine(ShowThoughtBubbleRoutine(ThoughtBubble.Thought.Hurt)));

            Strikes++;
        }
        else
        {
            // Prevents others from eaiting it
            resource.SetAsNotConsumable();

            // Reset Strikes
            Strikes = 0;
            var bubbleRoutine = ShowThoughtBubbleRoutine(ThoughtBubble.Thought.Happy);
            StartCoroutine(bubbleRoutine);

            var infos = resource.ResourceType == Resource.Food
                        ? eatingClips
                        : resource.ResourceType == Resource.Water
                        ? drinkingClips
                        : restingClips;

            var s = AudioManager.Instance.PlayRandom2DClip(infos);
            yield return(new WaitForSeconds(s.clip.length));

            resource.Consume();

            StopCoroutine(bubbleRoutine);
        }

        AutoChangeState(consumed);
    }