//------------------------------------------------------------------------------
        private void ActionCreate()
        {
            if (m_generatedFileList.Count > 0)
            {
                XenoTemplateTool.GenerateFiles(m_templateFilePath, m_userSuppliedNameText, m_targetPath);
            }

            Close();
        }
示例#2
0
        //------------------------------------------------------------------------------
        private void SaveAndRefreshGUI()
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            GUIContent saveButtonContent = new GUIContent("Save & Refresh", "Saves all unsaved assets and refreshes the Xenotemplates menu. Refreshing is only required when the name of the template changes.");

            bool saveAndRefreshMenu = GUILayout.Button(saveButtonContent, EditorStyles.miniButton);

            if (saveAndRefreshMenu)
            {
                AssetDatabase.SaveAssets();
                XenoTemplateTool.RefreshTemplates();
            }

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();
        }
示例#3
0
        //
        // Private methods
        //


        //------------------------------------------------------------------------------
        private String CustomMappingDelegateMenu(String selectedValue, MonoScript script)
        {
            if (script == null)
            {
                return(String.Empty);
            }

            List <String> methods = XenoTemplateTool.GetValidSubstitutionMethods(script);

            if (methods.Count == 0)
            {
                return(String.Empty);
            }

            int selectedIndex = Math.Max(0, methods.IndexOf(selectedValue));

            int newSelectedIndex = EditorGUILayout.Popup(selectedIndex, methods.ToArray());

            return(methods[newSelectedIndex]);
        }
示例#4
0
 public static void AutoMono()
 {
     XenoTemplateTool.PromptUserForNameAuto();
 }
        //
        // EditorWindow methods
        //

        //------------------------------------------------------------------------------
        private void OnGUI()
        {
            HandleKeyEvents();

            Rect contentRect = EditorGUILayout.BeginVertical();

            GUIStyle titleStyle = new GUIStyle(GUI.skin.label);

            titleStyle.fontStyle = FontStyle.Bold;
            titleStyle.alignment = TextAnchor.UpperCenter;
            GUILayout.Label("XenoTemplate", titleStyle);

            GUI.SetNextControlName("NameTokenTextField");
            String newName = EditorGUILayout.TextField(m_userSuppliedNameText);
            String error   = String.Empty;

            if (newName != m_userSuppliedNameText || m_generatedFileList.Count == 0)
            {
                XenoTemplateTool.GenerateFileNames(m_templateFilePath, newName, ref m_generatedFileList, ref error);
                m_userSuppliedNameText = newName;
            }

            EditorGUILayout.LabelField("Files to create", String.Format("{0}", m_generatedFileList.Count));

            if (m_generatedFileList.Count == 0)
            {
                if (!String.IsNullOrEmpty(error))
                {
                    EditorGUILayout.HelpBox(error, MessageType.Error);
                }
                else
                {
                    EditorGUILayout.HelpBox("Template malformed. No files will be created.", MessageType.Error);
                }
            }

            GUIStyle fileNameStyle = new GUIStyle(EditorStyles.label);

            fileNameStyle.alignment     = TextAnchor.LowerRight;
            fileNameStyle.contentOffset = new Vector2(-15.0f, 0.0f);

            foreach (String fileName in m_generatedFileList)
            {
                GUILayout.Label(fileName, fileNameStyle);
            }

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();

            bool cancelClicked = GUILayout.Button("Cancel", GUILayout.ExpandWidth(false));

            if (cancelClicked)
            {
                ActionCancel();
            }

            GUILayout.FlexibleSpace();

            if (m_generatedFileList.Count > 0)
            {
                bool proceedClicked = GUILayout.Button("Proceed", GUILayout.ExpandWidth(false));
                if (proceedClicked)
                {
                    ActionCreate();
                }
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();

            EditorGUILayout.EndVertical();

            GUIStyle helpStyle = new GUIStyle(EditorStyles.miniLabel);

            helpStyle.fontStyle = FontStyle.Italic;
            helpStyle.alignment = TextAnchor.LowerCenter;
            Rect helpLabelRect = contentRect;

            helpLabelRect.height = EditorGUIUtility.singleLineHeight;
            helpLabelRect.y      = contentRect.height - helpLabelRect.height;

            String helpString = "Esc. to cancel; Enter to create";

            if (m_generatedFileList.Count == 0)
            {
                helpString = "Esc. to cancel";
            }

            GUI.Label(helpLabelRect, helpString, helpStyle);



            if (m_setSize && Event.current.type == EventType.Repaint)
            {
                ResizeWindow(contentRect);
                m_setSize = false;
            }

            if (m_setFocus && Event.current.type == EventType.Repaint)
            {
                EditorGUI.FocusTextInControl("NameTokenTextField");
                m_setFocus = false;
            }
        }