Exemple #1
0
        /// <summary>
        ///helper method that removes a button and places it in the inactive pool
        /// </summary>
        /// <param name="br"></param>
        /// <param name="columnId"></param>
        private void RemoveButton(ButtonRow br, int columnId)
        {
            IterableButton removedButton = br.RemoveButton(columnId);

            //update its navigation

            InactiveButtonPool.Add(removedButton);
            removedButton.transform.SetAsLastSibling();
            UpdateNavigationAfterButtonRemove(removedButton);
        }
Exemple #2
0
 /// <summary>
 /// If the field Button prefab is set to null, create a generic button, returning its IterableButton component
 /// </summary>
 /// <param name="rowId"></param>
 /// <param name="columnId"></param>
 /// <returns></returns>
 private IterableButton BuildIterableButton(int rowId, int columnId)
 {
     //lets check the inactive pool first
     if (InactiveButtonPool.Count == 0)
     {
         if (ButtonPrefab == null)
         {
             var emptyGameObject = new GameObject("Button");
             emptyGameObject.transform.SetParent(ParentRectTransform);
             emptyGameObject.AddComponent <Image>();
             Button     button = emptyGameObject.AddComponent <Button>();
             ColorBlock colors = button.colors;
             colors.highlightedColor = HighlightedButtonColor;
             button.colors           = colors;
             IterableButton b = emptyGameObject.AddComponent <IterableButton>();
             b.Init(rowId, columnId, button);
             b.transform.SetAsLastSibling();
             return(b);
         }
         {
             try
             {
                 GameObject go = Instantiate(ButtonPrefab);
                 go.transform.SetParent(ParentRectTransform);
                 IterableButton b      = go.AddComponent <IterableButton>();
                 Button         button = GetComponent <Button>();
                 ColorBlock     colors = button.colors;
                 colors.highlightedColor = HighlightedButtonColor;
                 button.colors           = colors;
                 b.Init(rowId, columnId, button);
                 b.transform.SetAsLastSibling();
                 return(b);
             }
             catch (NoButtonAttachedToPrefabException ex)
             {
                 Debug.Log(ex.StackTrace);
                 throw;
             }
         }
     }
     else //return one of the iterable buttons in the pool
     {
         IterableButton b = InactiveButtonPool[0];
         b.Activate();
         b.transform.SetAsLastSibling();
         b.SetRowAndColumnIndex(rowId, columnId);
         InactiveButtonPool.RemoveAt(0);
         return(b);
     }
 }