コード例 #1
0
    /// Author: Ben Stern
    /// <summary>
    /// Attempt to select an object or interact with it in some way
    /// </summary>
    /// <param name="selectedObject">The is attempting to be selected</param>
    public void ObjectSelected(SelectableObject selectedObject)
    {
        if (currentSelection == null)
        {
            selectedObject.selected = true;
            currentSelection        = selectedObject;
            selectionIcon.color     = selectedObject.GetComponent <Image>().color;
            selectionIcon.sprite    = selectedObject.GetComponent <Image>().sprite;
        }
        else
        {
            //TODO: call interactable object methods
            InteractableBase currentInteractable  = currentSelection.GetComponent <InteractableBase>();
            InteractableBase selectedInteractable = selectedObject.GetComponent <InteractableBase>();

            if (currentInteractable != null && selectedInteractable != null)
            {
                if (selectedObject.name == "Plate" &&
                    selectedObject.transform.childCount >= 1 &&
                    (currentSelection.gameObject.GetComponent <SpaghettiScript>() != true && currentSelection.gameObject.GetComponent <MeatballScript>() != true && currentSelection.gameObject.GetComponent <SauceScript>() != true))
                {
                    ClearSelection();
                }

                else if ((currentSelection.name == "Spatula" && selectedObject.name == "Frying Pan") ||
                         (currentSelection.name == "Spatula" && selectedObject.name == "Plate"))
                {
                    selectedInteractable.AttemptInteraction(currentInteractable);
                }

                else if (selectedInteractable.AttemptInteraction(currentInteractable))
                {
                    ClearSelection();
                }
            }
        }
    }
コード例 #2
0
    /// Author: Kyle Weekley, John Vance
    /// <summary>
    /// Attempt to select an object or interact with it in some way
    /// Added so that the objects in the cafeteria scene can be selected in interacted with
    /// </summary>
    /// <param name="selectedObject">The is attempting to be selected</param>
    public void ObjectSelected(SelectableObject selectedObject)
    {
        if (currentSelection == null)
        {
            selectionIcon = GameObject.Find("Selection Sprite").GetComponent <Image>();

            selectedObject.selected = true;
            currentSelection        = selectedObject;
            selectionIcon.color     = selectedObject.GetComponent <Image>().color;
            selectionIcon.sprite    = selectedObject.GetComponent <Image>().sprite;
        }
        else
        {
            //TODO: call interactable object methods
            InteractableBase currentInteractable  = currentSelection.GetComponent <InteractableBase>();
            InteractableBase selectedInteractable = selectedObject.GetComponent <InteractableBase>();
            if (currentInteractable != null && selectedInteractable != null)
            {
                if ((currentSelection.name == "Spatula" && selectedObject.name == "Frying Pan") ||
                    (currentSelection.name == "Spatula" && selectedObject.name == "Plate"))
                {
                    selectedInteractable.AttemptInteraction(currentInteractable);
                }

                else if (selectedInteractable == currentInteractable)
                {
                    ClearSelection();
                }

                else if (selectedInteractable.AttemptInteraction(currentInteractable))
                {
                    CheckOrder();
                    ClearSelection();
                }
            }
        }
    }