コード例 #1
0
 private void DestroyCanvas()
 {
     while (thisGO.transform.childCount > 0)
     {
         DTEditorUtility.DestroyImmediateAndAllChildren(thisGO.transform.GetChild(0).gameObject);
     }
 }
コード例 #2
0
            private void UpdateNumberOfButtons()
            {
                if (thisGO.transform.GetChild(0).GetChild(0).childCount < thisGO.GetComponent <GenericMenu>().mArrStrButtonNames.Length)
                {
                    // Add new Button
                    int       numButtons = mSP_ButtonNames.arraySize;
                    float     buttonVertBlockPercentage = (1.0f - mSP_MenuPaddingTop.floatValue - mSP_MenuPaddingBottom.floatValue) / numButtons;
                    int       index  = numButtons - 1;
                    Transform parent = thisGO.transform.GetChild(0).GetChild(0);
                    AddGenericMenuButton(parent, index, numButtons, buttonVertBlockPercentage);
                }
                else if (thisGO.transform.GetChild(0).GetChild(0).childCount > thisGO.GetComponent <GenericMenu>().mArrStrButtonNames.Length)
                {
                    // Remove Button
                    Transform panelTransform = thisGO.transform.GetChild(0).GetChild(0);
                    int       numButtons     = mSP_ButtonNames.arraySize;
                    for (int i = 0; i < numButtons; i++)
                    {
                        Text genericMenuButtonText = panelTransform.GetChild(i).GetChild(0).GetComponent <Text>();
                        if (genericMenuButtonText.text != thisGO.GetComponent <GenericMenu>().mArrStrButtonNames[i])
                        {
                            numButtons = -1;
                            DTEditorUtility.DestroyImmediateAndAllChildren(panelTransform.GetChild(i).gameObject);
                            break;
                        }
                    }

                    // Its the last buton that should be deleted.
                    if (numButtons > 0)
                    {
                        DTEditorUtility.DestroyImmediateAndAllChildren(panelTransform.GetChild(mSP_ButtonNames.arraySize).gameObject);
                    }
                }
                else
                {
                    Debug.LogWarning("No change in number of buttons");
                    return;
                }

                // Update all the button positions.
                UpdateButtonTransforms();
            }