示例#1
0
    //Create All GUI elements
    private void OnGUI()
    {
        //check if a tutorial controller already exists
        if (GameObject.FindObjectOfType <TutorialController>())
        {
            //localize the tutorialController
            tutorialController = GameObject.FindObjectOfType <TutorialController>();

            //name for the window
            GUILayout.Label("Save Tutorial Preset", EditorStyles.boldLabel);

            //input field for the scriptable object to be saved to and limit to TutorialMapScriptableObject type
            tutorialMapObject = EditorGUILayout.ObjectField("Tutorial Scriptable Object", tutorialMapObject, typeof(TutorialMapScriptableObject), false) as TutorialMapScriptableObject;

            //create mask transform inputs
            GUILayout.Label("", EditorStyles.boldLabel);
            GUILayout.Label("Save Mask Transform", EditorStyles.boldLabel);
            maskTransform = EditorGUILayout.ObjectField("Mask Rect Transform", tutorialController.mapMaskTransform, typeof(RectTransform), true) as RectTransform;

            //buttons for saving transforms of normal mask or alternate mask
            //alternate mask is used for changing size in certain interactions
            if (GUILayout.Button("Save Mask Transform"))
            {
                SaveMaskTransform();
            }
            if (GUILayout.Button("Save Alternate Mask Transform"))
            {
                SaveAltMaskTransform();
            }

            //create secondary mask transform inputs
            GUILayout.Label("", EditorStyles.boldLabel);
            GUILayout.Label("Save Secondary Mask Transform", EditorStyles.boldLabel);
            secondaryMaskTransform = EditorGUILayout.ObjectField("Mask Rect Transform", tutorialController.mapSecondaryMaskTransform, typeof(RectTransform), true) as RectTransform;

            //button for saving transforms of secondary mask
            if (GUILayout.Button("Save Secondary Mask Transform"))
            {
                SaveSecondaryMask();
            }

            //create secondary panel transform inputs
            GUILayout.Label("", EditorStyles.boldLabel);
            GUILayout.Label("Save Panel Transform", EditorStyles.boldLabel);
            panelTransform    = EditorGUILayout.ObjectField("Panel Rect Transform", tutorialController.mapPanelBGTransform, typeof(RectTransform), true) as RectTransform;
            triangleTransform = EditorGUILayout.ObjectField("Triangle Rect Transform", tutorialController.mapArrowTransform, typeof(RectTransform), true) as RectTransform;

            //buttons for saving transforms of normal panel or alternate panel
            //alternate panel is used for changing size in certain interactions
            if (GUILayout.Button("Save Panel Transform"))
            {
                SavePanelTransforms();
            }
            if (GUILayout.Button("Save Alternate Panel Transform"))
            {
                SaveAltPanelTransforms();
            }

            //create inputs for tutorial text
            GUILayout.Label("", EditorStyles.boldLabel);
            GUILayout.Label("Save Panel Text", EditorStyles.boldLabel);
            titleString       = EditorGUILayout.TextField("Title", titleString);
            titleText         = EditorGUILayout.ObjectField("Title Text", tutorialController.mapTitleText, typeof(TMP_Text), true) as TMP_Text;
            informationString = EditorGUILayout.TextField("Information", informationString);
            informationText   = EditorGUILayout.ObjectField("Information Text", tutorialController.mapInformationText, typeof(TMP_Text), true) as TMP_Text;

            //save input text to scriptable object
            if (GUILayout.Button("Save Text"))
            {
                SaveText();
            }


            //create inputs for the map guide buttons
            GUILayout.Label("", EditorStyles.boldLabel);
            GUILayout.Label("Save Map Button", EditorStyles.boldLabel);
            tutorialMapButtonTransform = EditorGUILayout.ObjectField("Map Button Rect Transform", tutorialMapButtonTransform, typeof(RectTransform), true) as RectTransform;
            buttonTitleString          = EditorGUILayout.TextField("Button Title", buttonTitleString);
            buttonTitleText            = EditorGUILayout.ObjectField("Button Title Text", buttonTitleText, typeof(TMP_Text), true) as TMP_Text;

            //save button values to scriptable object
            if (GUILayout.Button("Save Map Button"))
            {
                SaveMapButton();
            }

            //update any changes made in the ui window
            if (GUI.changed)
            {
                informationText.text = informationString;
                EditorUtility.SetDirty(informationText);
                titleText.text = titleString;
                EditorUtility.SetDirty(titleText);
                EditorUtility.SetDirty(tutorialMapObject);
                EditorUtility.SetDirty(maskTransform);
                EditorUtility.SetDirty(panelTransform);
                EditorUtility.SetDirty(triangleTransform);

                if (buttonTitleText != null && tutorialMapButtonTransform != null)
                {
                    buttonTitleText.text = buttonTitleString;
                    EditorUtility.SetDirty(buttonTitleText);
                    EditorUtility.SetDirty(tutorialMapButtonTransform);
                }
            }


            //button for saving all tutorial aspects
            GUILayout.Label("", EditorStyles.boldLabel);
            if (GUILayout.Button("Save All"))
            {
                SaveTutorial();
            }
        }
        //if a tutorial controller does not exist Add button for user to create one
        else
        {
            GUILayout.Label("There is currently no tutorial system in the scene", EditorStyles.boldLabel);
            if (GUILayout.Button("Add Tutorial System to Scene"))
            {
                GameObject tutPrefab = PrefabUtility.LoadPrefabContents("Packages/com.vmlab.tutorialslibrary/Runtime/Prefabs/TitleAndTutorialCanvas.prefab") as GameObject;
                Instantiate(tutPrefab);
            }
        }
    }
 void SetMapButton(TutorialMapScriptableObject tutButton, RectTransform mapButtonPrefab)
 {
     mapButtonPrefab.anchoredPosition = tutButton.mapButtonPosition;
 }