Exemple #1
0
    void Start()
    {
        guiDisplayItems = GameObject.FindGameObjectWithTag("GameTools").GetComponent <GUIDisplayItems> ();

        style = new GUIStyle();
        style.border.bottom = 3;
        style.border.top    = 3;
        style.border.left   = 3;
        style.border.right  = 3;
    }
Exemple #2
0
    /// <summary>
    /// Loads the options for the menu
    /// </summary>
    /// <param name="options">Options.</param>
    public void loadOptions(List <Options> options)
    {
        if (menuOptions == null || menuOptions.Count == 0)
        {
            menuOptions.AddRange(options);
        }
        isActive = true;


        if (GUIdisplayItems == null)
        {
            GUIdisplayItems = GameObject.FindGameObjectWithTag("GameTools").GetComponent <GUIDisplayItems>();
        }

        // for each of our options, create some sort of button
        // in our panel and put it at the right spot
        for (int i = 0; i < options.Count; i++)
        {
            GameObject goButton = (GameObject)Instantiate(GUIdisplayItems.prefabButton);
            goButton.GetComponentInChildren <Text>().text = menuOptions[i].option;

            RectTransform rect = goButton.GetComponentInChildren <Text> ().GetComponent <RectTransform>();
            rect.offsetMax = new Vector2(-10f, -10f);
            rect.offsetMin = new Vector2(10f, 10f);


            Options optionItem = new Options();
            optionItem = menuOptions [i];

            // if we have no selected buttons, set our first to selected
            if (i == 0 && indexSelected <= 0)
            {
                goButton.GetComponent <Button> ().Select();
            }
            //goButton.AddComponent(
            goButton.GetComponent <Button>().onClick.AddListener(
                () => { ButtonClicked(optionItem); }
                );
            goButton.transform.SetParent(optionsBox.transform, false);
            goButton.transform.localScale = new Vector3(1, 1, 1);
            goButton.GetComponent <Button> ().interactable = false;

            // if there is a minimum height and width set
            if (requiresLayout)
            {
                LayoutElement layEle = goButton.AddComponent <LayoutElement> ();
                layEle.minWidth  = minWidth;
                layEle.minHeight = minHeight;
            }
        }
    }
Exemple #3
0
    public WaitingForTime waitingObject;     // object to pause the game for something



    /// <summary>
    /// Start this instance.
    ///
    /// This just runs a loop that we only need to run once before we destroy the object.
    /// The Menu comes and goes and waits for input and gives options and highlights and
    /// then does commands based on inputit
    /// </summary>
    public IEnumerator Start()
    {
        // when we start, we want to have game tools initialized and some music sounds
        stingPlayer     = GameObject.FindGameObjectWithTag("GameTools").GetComponent <StingPlayer>();
        GUIdisplayItems = GameObject.FindGameObjectWithTag("GameTools").GetComponent <GUIDisplayItems>();


        if (optionsBox != null)
        {
            yield return(StartCoroutine(Initialize()));
        }

        hasAccepted = false;
    }
Exemple #4
0
    // if selection made and we are in battle, we want to update and wait for input until we receive
    // and new updates from our new class of battle


    /// <summary>
    /// Initialize this instance.
    /// </summary>
    public IEnumerator Initialize()
    {
        selectionMade = false;
        isActive      = true;
        hasAccepted   = false;

        if (GUIdisplayItems == null)
        {
            GUIdisplayItems = GameObject.FindGameObjectWithTag("GameTools").GetComponent <GUIDisplayItems>();
        }


        // we need to be careful with this - because some menus won't have this few
        // indices. We need to remove the hardcoding for this. What if a menu has more
        // options here?
        if (indexSelected <= 0 || indexSelected >= 4)
        {
            indexSelected = 0;
        }


        if (optionsBox == null)
        {
            yield return(null);
        }


        optionsBox.AddComponent <WaitingForTime> ();
        waitingObject = optionsBox.GetComponent <WaitingForTime> ();


        // wait for input if we are dealing with a pause menu - might want to replace
        // this with a flag
        if (menuType != "PauseMenu")
        {
            yield return(StartCoroutine(waitingObject.PauseBeforeInput()));
        }


        // check and see which item is highlighted here before we enter and make that
        // our indexselected
        for (var i = 0; i < menuOptions.Count; i++)
        {
            // if the item is highlighted, set our value to that
            // set i to max
            Button currentButton = optionsBox.transform.GetChild(i).gameObject.GetComponent <Button>();
            currentButton.interactable = true;

            if (i == 0 && indexSelected <= 0)
            {
                currentButton.Select();
            }
            else if (i == indexSelected)
            {
                currentButton.Select();
            }
        }


        // until we have made a selection and while we still have an options box,
        // wait for input
        while (selectionMade == false && optionsBox.activeInHierarchy)
        {
            yield return(StartCoroutine(waitingObject.WaitForKeyDown()));

            if (EventSystem.current.currentSelectedGameObject == null)
            {
                // if we have no more object
                if (optionsBox.activeInHierarchy == false)
                {
                    yield return(null);
                }
                else if (indexSelected >= 0 && indexSelected <= menuOptions.Count - 1)
                {
                    optionsBox.GetComponentsInChildren <Button> () [indexSelected].Select();
                }
                else
                {
                    optionsBox.GetComponentsInChildren <Button> () [0].Select();
                }
            }



            // if we haven't made a selection yet -
            if (!selectionMade && isActive == true && Input.anyKeyDown)
            {
                if (!isHorizontal)
                {
                    if (Input.GetKeyDown(KeyCode.DownArrow) == true)
                    {
                        incrementIndex();
                    }

                    /// INPUT KEY DOWN : MOVE DOWN THE LIST
                    if (Input.GetKeyDown(KeyCode.UpArrow) == true)
                    {
                        decrementIndex();
                    }
                }
                else
                {
                    // if we are on a horizontal menu, right should go right
                    if (Input.GetKeyDown(KeyCode.RightArrow) == true)
                    {
                        incrementIndex();
                    }

                    // if we are on a horizontal menu, left should go left
                    else if (Input.GetKeyDown(KeyCode.LeftArrow) == true)
                    {
                        decrementIndex();
                    }
                }

                if (Input.GetKeyDown(KeyCode.Return))
                {
                    selectionMade = true;

                    // play selection made sting if possible
                    if (menuType == "PauseMenu" && stingPlayer != null)
                    {
                        stingPlayer.playSelectItemSound();
                    }


                    yield return(StartCoroutine(ButtonClicked(menuOptions [indexSelected])));
                }

                if (Input.GetKeyDown(KeyCode.X))
                {
                    selectionMade = true;

                    // play selection made sting if possible
                    if (menuType == "PauseMenu" && stingPlayer != null)
                    {
                        stingPlayer.playSelectItemSound();
                    }

                    yield return(StartCoroutine(ButtonClicked(menuOptions [indexSelected])));
                }
            }
        }
    }