示例#1
0
 // REplace user defined place holders.
 private static string ReplaceUserDefinedKeys(TemplateEntry template, string content)
 {
     foreach (TemplateProperty tp in template.Properties)
     {
         content = content.Replace("#" + tp.Name + "#", tp.Value);
     }
     return(content);
 }
示例#2
0
        // Prepare the tempalte content by replacing all the place holders.
        public static string PrepareContent(TemplateEntry template)
        {
            string content = template.Content;

            content = ReplacePredefinedKeys(template, content);
            content = ReplaceUserDefinedKeys(template, content);
            return(content);
        }
示例#3
0
 // Replace the predifined place holders (template's shared properties)
 private static string ReplacePredefinedKeys(TemplateEntry template, string content)
 {
     content = content.Replace("#Company Name#", PlayerSettings.companyName);
     content = content.Replace("#Product Name#", PlayerSettings.productName);
     content = content.Replace("#File Name#", template.SharedProperties.FileName);
     content = content.Replace("#File Type#", template.SharedProperties.FileType);
     return(content);
 }
 private void DeleteTemplate()
 {
     Templates.RemoveAll(t => t.Name.Equals(SelectedTemplate.Name));
     SelectedTemplate    = Templates.FirstOrDefault();
     selectedIndex       = Templates.IndexOf(SelectedTemplate);
     lastTemplateUpdated = SelectedTemplate.Name;
     TemplateManagerDAO.Save(Templates);
 }
示例#5
0
        // Get the path to the currently selected folder.
        private static string GetContextualPath(TemplateEntry template)
        {
            string path = "Assets";

            foreach (UnityEngine.Object obj in Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets))
            {
                path = AssetDatabase.GetAssetPath(obj);
                if (File.Exists(path))
                {
                    path = Path.GetDirectoryName(path);
                }
                break;
            }
            path = path + "/" + template.SharedProperties.FileName + template.SharedProperties.FileType;


            return(path);
        }
        private void DrawTemplateMetaData()
        {
            // If in creation mode
            if (isEditMode || isCreateMode)
            {
                GUILayout.BeginHorizontal();

                GUILayout.Label("Name", GUILayout.Width(145));
                SelectedTemplate.Name = GUILayout.TextField(SelectedTemplate.Name);

                GUILayout.EndHorizontal();


                GUILayout.BeginHorizontal();
                GUILayout.Label("Menu", GUILayout.Width(145));
                SelectedTemplate.Menu = GUILayout.TextField(SelectedTemplate.Menu);
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();

                GUILayout.Label("Menu Priority", GUILayout.Width(145));
                SelectedTemplate.MenuPriority = GUILayout.TextField(SelectedTemplate.MenuPriority);

                GUILayout.EndHorizontal();
            }
            else
            {
                GUILayout.BeginHorizontal();
                // Allow tempalte selection
                selectedIndex    = EditorGUILayout.Popup(selectedIndex, Templates.Select(t => t.Name).ToArray <string>());
                SelectedTemplate = Templates.ElementAtOrDefault(selectedIndex);
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                GUILayout.Label("Menu", GUILayout.Width(145));
                GUILayout.Label(SelectedTemplate.Menu);
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                GUILayout.Label("Menu Priority", GUILayout.Width(145));
                GUILayout.Label(SelectedTemplate.MenuPriority);
                GUILayout.EndHorizontal();
            }
        }
示例#7
0
 // Create the new script in the currently selected folder, based on the template definition and the user inputs.
 public static void CreateScript(TemplateEntry template)
 {
     FileWriter.WriteFile(GetContextualPath(template), PrepareContent(template));
 }
        private void CreateTemplate()
        {
            TemplateEntry te = TemplateEntry.Instantiate();

            SelectedTemplate = te;
        }
        private void DrawControls()
        {
            GUILayout.BeginHorizontal();

            // If in creation mode
            if (isEditMode || isCreateMode)
            {
                // Can't save an invalid template

                if (GUILayout.Button("Save", GUILayout.Width(100)))
                {
                    if (isEditMode)
                    {
                        if (Regex.IsMatch(SelectedTemplate.Name, @"^\d"))
                        {
                            Debug.LogError("This template name should not start with a number.");
                        }
                        else if (string.IsNullOrWhiteSpace(SelectedTemplate.Name))
                        {
                            Debug.LogError("This template name is mandatory.");
                        }
                        else
                        {
                            UpdateTemplate();
                            isEditMode = false;
                        }
                    }
                    else
                    {
                        if (TemplateManagerDAO.Load().Exists(t => t.Name.Equals(SelectedTemplate.Name)))
                        {
                            Debug.LogError("This template name is already taken.");
                        }
                        else if (string.IsNullOrWhiteSpace(SelectedTemplate.Name))
                        {
                            Debug.LogError("This template name is mandatory.");
                        }
                        else if (Regex.IsMatch(SelectedTemplate.Name, @"^\d"))
                        {
                            Debug.LogError("This template name should not start with a number.");
                        }
                        else
                        {
                            SaveNewTempalte();

                            isCreateMode = false;
                        }
                    }
                }
                if (GUILayout.Button("Abord", GUILayout.Width(100)))
                {
                    SelectedTemplate = Templates[selectedIndex];
                    isEditMode       = false;
                    isCreateMode     = false;
                }
            }
            else
            {
                // Add control to edit/delete selected template or create a new one
                if (GUILayout.Button("Create", GUILayout.Width(100)))
                {
                    CreateTemplate();
                    isCreateMode = true;
                }
                // Can't edit or remove non existing template
                EditorGUI.BeginDisabledGroup(Templates.Count == 0);

                if (GUILayout.Button("Edit", GUILayout.Width(100)))
                {
                    isEditMode = true;
                }
                if (GUILayout.Button("Delete", GUILayout.Width(100)))
                {
                    DeleteTemplate();
                }
                EditorGUI.EndDisabledGroup();
            }
            GUILayout.EndHorizontal();
        }