Пример #1
0
    protected override Status SubUpdate()
    {
        switch (state)
        {
        // Setup the Emote Node
        case InnerState.Setup:
            emoteNode = EmoteNode.Create(1f, "interactBox", EmoteNode.ParameterType.Bool, true);
            emoteNode.Restart();
            emoteNode.Beginn(tree);
            state++;
            break;

        // Play the animation which is handled by the inner emote node
        case InnerState.PlayAnimation:
            switch (emoteNode.CurrentStatus)
            {
            case Status.Running:
                emoteNode.Update();
                break;

            case Status.Success:
                state++;
                break;

            case Status.Failure:
                return(Status.Failure);
            }
            break;

        // Save/ Take all items from/ to the box
        case InnerState.SaveItems:
            return(Interact());

        default:
            Debug.LogError("Should not be able to get here. Unimplemented case " + state);
            return(Status.Failure);
        }

        return(Status.Running);
    }
Пример #2
0
    protected override Status SubUpdate()
    {
        // This switch case is a state machine. If a case wants to transition into another state it needs to set the "state" variable.
        // This can be done by setting it directly or incrementing it by 1, i.e. ++.
        switch (state)
        {
        // Prepares the emoteNode
        case InnerState.Setup:
            emoteNode = EmoteNode.Create(0.6f, "pickupItem", EmoteNode.ParameterType.Trigger);
            emoteNode.Restart();
            emoteNode.Beginn(tree);
            state++;
            return(Status.Running);

        // Play the emote node, i.e. pickup item
        case InnerState.PickupItem:
            switch (emoteNode.CurrentStatus)
            {
            case Status.Running:
                emoteNode.Update();
                break;

            case Status.Success:
                state++;
                break;

            case Status.Failure:
                return(Status.Failure);
            }
            return(Status.Running);

        // Puts the item into the inventory of the toy
        case InnerState.SaveItemInInventory:

            if (!item)     // check if someone else alredy picked up the item
            {
                return(Status.Failure);
            }

            int itemsToPickUp = toy.Inventory.CapacityLeft / item.item.SingleWeight;

            Item addToInventory;
            if (itemsToPickUp >= item.item.Amount)     // Can pickup every item
            {
                addToInventory = item.item;
                Destroy(item.gameObject);
            }
            else     // can not pickup every item
            {
                addToInventory        = Instantiate(item.item);
                addToInventory.Amount = itemsToPickUp;
                item.item.Amount     -= itemsToPickUp;
            }
            toy.Inventory.Add(addToInventory);

            return(Status.Success);

        default:
            Debug.LogError("Should not be able to get here. Unimplemented case " + state);
            return(Status.Failure);
        }
    }