Example #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);
        }
Example #2
0
        private bool Add(UIOption option)
        {
            //Base case
            if (this.count + 1 > Size)
            {
                Debug.LogWarning("[UIOptionsGrid] Tried to add but the grid was full");
                return(false);
            }

            //Create and set up the added element
            this.grid[this.head.x, this.head.y] = option;

            //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(true);
        }