예제 #1
0
        /// <summary>
        /// Instantiates and adds an option to the grid
        /// </summary>
        /// <param name="optionData">The data for the option</param>
        /// <returns>The UI option object</returns>
        public UIOption Add(UIOptionData optionData)
        {
            UIOption option = null;

            if (this.interactable)
            {
                //Base case
                if (this.count + 1 > Size)
                {
                    Debug.LogWarning("[UIOptionsGrid] Tried to add but the grid was full");
                    return(null);
                }

                //Create and set up the added element
                option = Instantiate(this.optionPrefab);
                this.grid[this.head.x, this.head.y] = option;
                option.transform.SetParent(this.container);
                option.transform.localScale = Vector3.one;
                option.Setup(optionData);

                //If the cursor did not already exist, enable it
                if (this.count < 1)
                {
                    SetCursorAtPosition(this.head, true);
                }

                this.head = Increment(this.head);

                //Increase the count
                this.count++;
            }

            return(option);
        }
예제 #2
0
        /// <summary>
        /// Sets up an instantiated option
        /// </summary>
        /// <param name="optionData">The data in the option</param>
        /// <returns>True if setup is successful, otherwise returns false</returns>
        public bool Setup(UIOptionData optionData)
        {
            if (optionData.text != null)
            {
                this.textMesh.text = optionData.text;
            }
            else
            {
                if (this.textMesh != null)
                {
                    this.textMesh.enabled = false;
                }
            }

            if (optionData.icon != null)
            {
                this.image.sprite = optionData.icon;
            }
            else
            {
                if (this.image != null)
                {
                    this.image.enabled = false;
                }
            }

            if (optionData.action != null)
            {
                this.confirmEvent.AddListener(() =>
                {
                    optionData.action();
                });
            }

            return(true);
        }