Ejemplo n.º 1
0
 private static void CreateCodeItemFromTemplate()
 {
     CustomTemplateWizard.DisplayWizard(wizard => CreateItemFromTemplate(TemplateHeader + BehaviourTemplate, ".cs", wizard));
 }
Ejemplo n.º 2
0
 private static void CreateEnumItemFromTemplate()
 {
     CustomTemplateWizard.DisplayWizard(wizard => CreateItemFromTemplate(TemplateHeader + EnumTemplate, ".cs", wizard));
 }
Ejemplo n.º 3
0
        private static void CreateItemFromTemplate(string template, string fileExtension, CustomTemplateWizard wizard)
        {
            try
            {
                string path = Path.ChangeExtension(Path.Combine(CustomAssetHelper.GetSelectedObjectFolder(), wizard.ItemName), fileExtension);

                if (File.Exists(path))
                {
                    if (!EditorUtility.DisplayDialog("File exists already!", "Do you want to overwrite the file?", "Yes", "No"))
                    {
                        return;
                    }
                }

                using (var writer = new StreamWriter(path, false))
                {
                    writer.Write(ReplaceTemplateTokens(template,
                                                       new[] { "$ItemName", wizard.ItemName },
                                                       new[] { "$User", wizard.ProgrammerName },
                                                       new[] { "$Namespace", wizard.Namespace },
                                                       new[] { "$Year", DateTime.Now.Year.ToString(CultureInfo.InvariantCulture) },
                                                       new[] { "$DateTime", DateTime.Now.ToShortDateString() },
                                                       new[] { "$EditingItemName", FindEditingItemName(wizard.ItemName) }));
                }

                AssetDatabase.ImportAsset(path);
            }
            catch (Exception exception)
            {
                Debug.LogException(exception);
            }
        }