Exemple #1
0
 public HintRankPair(Hint h)
 {
     hint = h;
 }
Exemple #2
0
        /// <summary>
        /// Display a hint.
        /// </summary>
        /// <param name="text">Text to be displayed/</param>
        /// <param name="button">A ButtonID to display the hint.</param>
        public void DisplayHint(string text, ButtonID button)
        {
            if (activeHints == null)
            {
                activeHints = new List <HintRankPair>();
            }

            GameObject newHint = GameObject.Instantiate(HintPrefab);

            newHint.name = button.ToString() + " Hint";

            Hint hint = newHint.GetComponent <Hint>();

            hint.SetText(text);
            hint.HintButton = button;
            /* Check if the hint hooks was loaded before. If not load it now. */
            if (hintHooks == null)
            {
                hint.LoadHintHooks();
            }

            /* This hint should be on the right hand. */
            if (button.ToString().Contains("Right"))
            {
                newHint.transform.SetParent(ControllerManager.Instance.GetControllerAttachPosition(true).transform);
            }
            else if (button.ToString().Contains("Left"))
            {
                newHint.transform.SetParent(ControllerManager.Instance.GetControllerAttachPosition(false).transform);
            }
            else
            {
                Debug.LogError("HintManager: Something is wrong, can't figure out which hand to place hint.");
            }

            /* Position the hint */
            hint.SetPosition(hintHooks.Find(h => h.Button.Equals(button)).HintPosition);

            /* Draw the line linking hint and controller */
            hint.DrawLine(hintHooks.Find(h => h.Button.Equals(button)).LinePosition);

            List <HintRankPair> hintsOnTheSameButton = activeHints.FindAll(h => h.hint.HintButton.Equals(button));
            HintRankPair        rankPair             = new HintRankPair(hint);

            rankPair.rank = hintsOnTheSameButton.Count + 1;

            if (hintsOnTheSameButton.Count == 0)
            {
                /* Add hint to actives*/
                activeHints.Add(rankPair);
            }
            else
            {
                /* Protect the activeHints from spamming. (If a rogue programmer misuse this method). */
                if (hintsOnTheSameButton.Find(h => h.hint.GetText().Equals(text)) != null)
                {
                    Destroy(newHint);
                    return;
                }

                /* Disable the active hint with rank below and add new hint. */
                HintRankPair hintToDisable;
                hintToDisable = hintsOnTheSameButton.Find(h => h.rank == hintsOnTheSameButton.Count);
                hintToDisable.hint.gameObject.SetActive(false);
                activeHints.Add(rankPair);
            }
        }