예제 #1
0
    protected override void HandleInteraction(PlayerController playerInteracting)
    {
        // If theere is already a player chopping items on the board, then do nothing
        if (_activeChoppingState != null)
        {
            return;
        }
        // If the player has any items in hand, then the player can't chop items on a board
        if (playerInteracting.PlayerHand.HasAnyItemInHand())
        {
            return;
        }
        // If all the items on the board aren't choppable, then the player can't chop items on the board
        Choppable choppableItem = transform.GetComponentInChildren <Choppable>();

        if (choppableItemOnBoard == null)
        {
            return;
        }
        // If the choppable item on the board is already chopped, then the player can't chop items on the board
        else if (choppableItem.ChopComplete)
        {
            return;
        }

        // Otherwise, let's get chopping
        // Create a new player state with the player that's interacting with this chopping board
        // and the choppable item to chop
        _activeChoppingState = new ChoppingState(playerInteracting, choppableItem, OnChoppingEnded);
        // Assign the new chopping state to the player
        playerInteracting.SetPlayerState(_activeChoppingState);
        // Call the on chop starting event
        OnChopStarting.Invoke(choppableItem);
    }
 private void OnChoppableItemBoarded(Choppable choppableItem)
 {
     ChoppableItemProgressionChanged(choppableItem);
     startIngredientImage.sprite  = choppableItem.GetComponent <FoodGameObject>().FoodIngredient.IngredientSprite;
     resultIngredientImage.sprite = choppableItem.ChoppedIngredient.IngredientSprite;
     choppableItem.OnChoppedProgressionChanged.AddListener(ChoppableItemProgressionChanged);
     ToggleChoppingBoard(true);
 }
예제 #3
0
 private void  OnChoppableItemOnBoardPickedUp(HoldableItem itemOnBoard)
 {
     if (itemOnBoard.HoldingState == HoldableItem.HeldState.Held)
     {
         itemOnBoard.OnHoldStateChange.RemoveListener(OnChoppableItemOnBoardPickedUp);
         OnChoppableItemUnboarded.Invoke(choppableItemOnBoard);
         choppableItemOnBoard = null;
     }
 }
예제 #4
0
    public override void PlayerDroppedItem(HoldableItem droppedItem, PlayerController player)
    {
        HoldableItem itemOnBoard = transform.GetComponentInChildren <HoldableItem>();

        if (itemOnBoard == null)
        {
            droppedItem.transform.parent   = transform;
            droppedItem.transform.position = transform.position;
            droppedItem.ToggleRigidBodyKinematic(true);
            choppableItemOnBoard = droppedItem.GetComponent <Choppable>();
            if (choppableItemOnBoard != null)
            {
                droppedItem.OnHoldStateChange.AddListener(OnChoppableItemOnBoardPickedUp);
                OnChoppableItemBoarded.Invoke(choppableItemOnBoard);
            }
        }
    }
예제 #5
0
    private void OnChoppingEnded(Choppable itemChopped)
    {
        Debug.Log("End of chop");
        // Call the on chop ending event
        OnChopEnding.Invoke(itemChopped);

        if (itemChopped.ChopComplete)
        {
            Debug.Log("Item chop complete");
            FoodGameObject choppedResult = Instantiate(itemChopped.ChoppedIngredient.IngredientPrefab, itemChopped.transform.position, itemChopped.transform.rotation);
            choppedResult.transform.parent = itemChopped.transform.parent;
            choppedResult.GetHoldableItemComponent().ToggleRigidBodyKinematic(true);
            OnChoppableItemUnboarded.Invoke(itemChopped);
            Destroy(itemChopped.gameObject);
        }

        _activeChoppingState = null;
    }
 private void ChoppableItemProgressionChanged(Choppable choppableItem)
 {
     OnChoppedItemProgressionChanged(choppableItem.ChoppedAmount);
 }
 private void OnChoppableItemUnboarded(Choppable choppableItem)
 {
     choppableItem.OnChoppedProgressionChanged.RemoveListener(ChoppableItemProgressionChanged);
     ToggleChoppingBoard(false);
 }
예제 #8
0
 public ChoppingState(PlayerController playerControllerStateMachine, Choppable choppableItem, System.Action <Choppable> choppingEndCallbackHandler) : base(playerControllerStateMachine)
 {
     itemBeingChopped = choppableItem;
     this.choppingEndCallbackHandler = choppingEndCallbackHandler;
 }