internal void CreateNewTemplatesFiles() { if (IsInputValid()) { m_Root.SetEnabled(false); if (!Directory.Exists(m_Folder)) { Directory.CreateDirectory(m_Folder); } StyleSheet styleSheet = null; VisualTreeAsset visualTreeAsset = null; if (m_IsUssEnable) { File.WriteAllText(ussPath, GetUssTemplateContent()); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>(ussPath); } if (m_IsUxmlEnable) { var stringBuilder = new StringBuilder(); if (m_IsUssEnable) { var assetUri = URIHelpers.MakeAssetUri(styleSheet); var encodedUri = URIHelpers.EncodeUri(assetUri); stringBuilder.AppendLine(string.Format(@"<Style src=""{0}"" />", encodedUri)); stringBuilder.Append('\t'); } stringBuilder.AppendLine(@"<engine:Label text=""Hello World! From UXML"" />"); if (m_IsUssEnable) { stringBuilder.Append('\t'); stringBuilder.AppendLine(@"<engine:Label class=""custom-label"" text=""Hello World! With Style"" />"); } File.WriteAllText(uxmlPath, UIElementsTemplate.CreateUXMLTemplate(m_Folder, stringBuilder.ToString())); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); visualTreeAsset = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(uxmlPath); } File.WriteAllText(cSharpPath, UIElementsTemplate.CreateCSharpTemplate(m_CSharpName, m_IsUxmlEnable, m_IsUssEnable && !m_IsUxmlEnable)); AssetDatabase.Refresh(); } else { ShowErrorMessage(); } }
void CreateNewTemplatesFiles() { if (IsInputValid()) { m_Root.SetEnabled(false); if (!Directory.Exists(m_Folder)) { Directory.CreateDirectory(m_Folder); } if (m_IsUxmlEnable) { var uxmlPath = Path.Combine(m_Folder, m_UxmlName + ".uxml"); File.WriteAllText(uxmlPath, UIElementsTemplate.CreateUXMLTemplate(m_Folder, "<engine:Label text=\"Hello World! From UXML\" />")); } if (m_IsUssEnable) { var ussPath = Path.Combine(m_Folder, m_UssName + ".uss"); File.WriteAllText(ussPath, GetUssTemplateContent()); } if (m_IsUssEnable || m_IsUxmlEnable) { AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); } if (m_IsCSharpEnable) { var cSharpPath = Path.Combine(m_Folder, m_CSharpName + ".cs"); File.WriteAllText(cSharpPath, UIElementsTemplate.CreateCSharpTemplate(m_CSharpName, m_UxmlName, m_UssName, m_Folder)); AssetDatabase.Refresh(); } else { Close(); } if (m_Root.Q <Toggle>("openFilesToggle").value) { OpenNewlyCreatedFiles(); } } else { ShowErrorMessage(); } }