Esempio n. 1
0
 private void DestroyCanvas()
 {
     while (thisGO.transform.childCount > 0)
     {
         DTEditorUtility.DestroyImmediateAndAllChildren(thisGO.transform.GetChild(0).gameObject);
     }
 }
Esempio n. 2
0
            private void DrawMenuButtonProperties()
            {
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Menu Button Properties:", EditorStyles.boldLabel);

                // Draw array of menu button names and events.
                for (int index = 0; index < mSP_ButtonNames.arraySize; index++)
                {
                    // Div-like wrapper for each button data.
                    Rect buttonDataRect = EditorGUILayout.BeginVertical(MarginNMarginStyle);
                    EditorGUI.DrawRect(buttonDataRect, Color.grey);
                    DTEditorUtility.ShrinkRectByOne(ref buttonDataRect);
                    EditorGUI.DrawRect(buttonDataRect, Color.white);

                    DrawButtonDataAtIndex(index);

                    EditorGUILayout.EndVertical();
                }

                // Button to add menu buttons.
                if (GUILayout.Button(addButtonContent))
                {
                    mSP_ButtonNames.InsertArrayElementAtIndex(mSP_ButtonNames.arraySize);
                    mSP_ButtonEvents.InsertArrayElementAtIndex(mSP_ButtonEvents.arraySize);

                    mbNeedUpdateNumberOfButtons = true;
                }
            }
Esempio n. 3
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();
            }
Esempio n. 4
0
            private bool CreateNewActionScript(string _name)
            {
                TextAsset templateTextFile = AssetDatabase.LoadAssetAtPath("Assets/DaburuTools/Action/Editor/ActionScriptTemplate.txt",
                                                                           typeof(TextAsset)) as TextAsset;

                if (templateTextFile == null)
                {
                    Debug.LogError("Failed to load ActionScriptTemplate. Plase make sure the DaburuTools folder is in /Assets/");
                    mbFailLoadTemplate = true;
                    return(false);
                }
                mbFailLoadTemplate = false;

                string contents = "";

                contents = templateTextFile.text;
                contents = contents.Replace("#SCRIPTNAME#", _name);
                string newAssetPath = DTEditorUtility.GetSelectedPathOrFallback();

                newAssetPath += "/" + _name + ".cs";

                if (File.Exists(newAssetPath) == false)                 // Do not overwrite
                {
                    using (StreamWriter outfile =
                               new StreamWriter(newAssetPath))
                    {
                        outfile.Write(contents);
                    }                    //File written

                    AssetDatabase.Refresh();

                    // Highlight the asset.
                    Selection.activeObject = (Object)AssetDatabase.LoadAssetAtPath(newAssetPath, typeof(MonoScript));
                    EditorGUIUtility.PingObject(Selection.activeObject);
                    return(true);
                }

                Debug.LogError("Script of same name exists in the same Assets folder. Please name this Action something else.");
                mbFailNewAsset = true;
                return(false);
            }
Esempio n. 5
0
            public override void OnInspectorGUI()
            {
                serializedObject.Update();

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("General Options", EditorStyles.boldLabel);

                // Menu Size Field.
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(mSP_MenuSize, menuSizeContent);
                if (EditorGUI.EndChangeCheck())
                {
                    mbNeedUpdateMenuSize = true;
                }

                // Menu Top and Bottom Padding Fields
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.Slider(mSP_MenuPaddingTop, 0.0f, 1.0f, menuPaddingTopContent);
                EditorGUILayout.Slider(mSP_MenuPaddingBottom, 0.0f, 1.0f, menuPaddingBottomContent);

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Button Layout Options", EditorStyles.boldLabel);

                // Button Horizontal Percentage Field.
                EditorGUILayout.Slider(mSP_ButtonHorzPercent, 0.0f, 1.0f, buttonHorzPercentContent);

                // Button Verticle Margin Field.
                EditorGUILayout.Slider(mSP_ButtonVertMargin, 0.0f, 0.1f, buttonVertMarginContent);
                if (EditorGUI.EndChangeCheck())
                {
                    mbNeedUpdateButtonTransforms = true;
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Button Content Options", EditorStyles.boldLabel);

                // Button Font Size Field.
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(mSP_ButtonFontSize, buttonFontSizeContent);
                if (EditorGUI.EndChangeCheck())
                {
                    mbNeedUpdateButtonFontSize = true;
                }

                // Menu Button order, name, and events.
                DrawMenuButtonProperties();

                EditorGUILayout.Space();

                // Danger Zone (Force Reconstruct, Deleting, etc.)
                Rect dangerZoneRect = EditorGUILayout.BeginVertical(MarginNMarginStyle);

                EditorGUI.DrawRect(dangerZoneRect, Color.grey);
                DTEditorUtility.ShrinkRectByOne(ref dangerZoneRect);
                EditorGUI.DrawRect(dangerZoneRect, Color.red);
                EditorGUILayout.LabelField("DANGER ZONE", EditorStyles.boldLabel);
                if (GUILayout.Button(forceReconstructButtonContent))
                {
                    ConstructCanvasFromScratch();
                }
                GUILayout.EndVertical();

                serializedObject.ApplyModifiedProperties();

                // Once inspector is done drawing and applying modifications,
                // Ensure that a Canvas and EventSystem are created.
                // If there is no Canvas and/or EventSystem, EnsureMenuCanvas will create one.
                EnsureMenuCanvas();
                UpdateCanvas();                 // Then Update the Canvas if needed.
            }