private static void CreateUSSAsset() { var contents = "VisualElement {}"; var icon = EditorGUIUtility.IconContent <StyleSheet>().image as Texture2D; ProjectWindowUtil.CreateAssetWithContent("NewUSSFile.uss", contents, icon); }
static void CreateSmartTextureMenuItem() { // Asset creation code from pschraut Texture2DArrayImporter // https://github.com/pschraut/UnityTexture2DArrayImportPipeline/blob/master/Editor/Texture2DArrayImporter.cs#L360-L383 string directoryPath = "Assets"; foreach (Object obj in Selection.GetFiltered(typeof(Object), SelectionMode.Assets)) { directoryPath = AssetDatabase.GetAssetPath(obj); if (!string.IsNullOrEmpty(directoryPath) && File.Exists(directoryPath)) { directoryPath = Path.GetDirectoryName(directoryPath); break; } } directoryPath = directoryPath.Replace("\\", "/"); if (directoryPath.Length > 0 && directoryPath[directoryPath.Length - 1] != '/') { directoryPath += "/"; } if (string.IsNullOrEmpty(directoryPath)) { directoryPath = "Assets/"; } var fileName = string.Format("SmartTexture.{0}", k_SmartTextureExtesion); directoryPath = AssetDatabase.GenerateUniqueAssetPath(directoryPath + fileName); ProjectWindowUtil.CreateAssetWithContent(directoryPath, "Smart Texture Asset for Unity. Allows to channel pack textures by using a ScriptedImporter. Requires Smart Texture Package from https://github.com/phi-lira/SmartTexture. Developed by Felipe Lira."); }
static void CreateCubemapArrayMenuItem() { // https://forum.unity.com/threads/how-to-implement-create-new-asset.759662/ string directoryPath = "Assets"; foreach (Object obj in Selection.GetFiltered(typeof(Object), SelectionMode.Assets)) { directoryPath = AssetDatabase.GetAssetPath(obj); if (!string.IsNullOrEmpty(directoryPath) && File.Exists(directoryPath)) { directoryPath = Path.GetDirectoryName(directoryPath); break; } } directoryPath = directoryPath.Replace("\\", "/"); if (directoryPath.Length > 0 && directoryPath[directoryPath.Length - 1] != '/') { directoryPath += "/"; } if (string.IsNullOrEmpty(directoryPath)) { directoryPath = "Assets/"; } var fileName = $"New CubemapArray.{kFileExtension}"; directoryPath = AssetDatabase.GenerateUniqueAssetPath(directoryPath + fileName); ProjectWindowUtil.CreateAssetWithContent(directoryPath, "This file represents a CubemapArray asset for Unity.\nYou need the 'CubemapArray Import Pipeline' package available at https://github.com/pschraut/UnityCubemapArrayImportPipeline to properly import this file in Unity."); }
private static void Menu() { Texture2D icon = AssetPreview.GetMiniTypeThumbnail(typeof(TextAsset)); string extension = "test-external"; ProjectWindowUtil.CreateAssetWithContent($"New External Type Info.{extension}", "{}", icon); }
public static void CreateTemplateMenuItem() { UxmlSchemaGenerator.UpdateSchemaFiles(); string folder = ProjectWindowUtil.GetActiveFolderPath(); string[] pathComponents = folder.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); List <string> backDots = new List <string>(); foreach (var s in pathComponents) { if (s == ".") { continue; } if (s == ".." && backDots.Count > 0) { backDots.RemoveAt(backDots.Count - 1); } else { backDots.Add(".."); } } backDots.Add(UxmlSchemaGenerator.k_SchemaFolder); string schemaDirectory = string.Join("/", backDots.ToArray()); string xmlnsList = String.Empty; string schemaLocationList = String.Empty; Dictionary <string, string> namespacePrefix = UxmlSchemaGenerator.GetNamespacePrefixDictionary(); foreach (var prefix in namespacePrefix) { if (prefix.Key == String.Empty) { continue; } if (prefix.Value != String.Empty) { xmlnsList += " xmlns:" + prefix.Value + "=\"" + prefix.Key + "\"\n"; } schemaLocationList += " " + prefix.Key + " " + schemaDirectory + "/" + UxmlSchemaGenerator.GetFileNameForNamespace(prefix.Key) + "\n"; } // The noNamespaceSchemaLocation attribute should be sufficient to reference all namespaces // but Rider does not support it very well, so we add schemaLocation to make it happy. string xmlTemplate = @"<?xml version=""1.0"" encoding=""utf-8""?> <engine:" + k_RootNode + @" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" " + xmlnsList + @" xsi:noNamespaceSchemaLocation=""" + schemaDirectory + @"/UIElements.xsd"" xsi:schemaLocation="" " + schemaLocationList + @""" > <engine:Label text=""Hello World!"" /> </engine:" + k_RootNode + ">"; ProjectWindowUtil.CreateAssetWithContent("New UIElements View.uxml", xmlTemplate, EditorGUIUtility.FindTexture(typeof(VisualTreeAsset))); }
private static void CreateSceneXml() { var contentObjectModel = ContentObjectModel.GetInstance(); var path = ContentParser.GetContentFolderPathFromSelectedFile(ContentParser.ScenesFolder); var filename = ""; int i = 0; do { var sceneName = String.Format("NewScene{0}", i == 0 ? string.Empty : i.ToString()); filename = String.Format("{0}{1}.xml", path, sceneName); ++i; // find unique name if (!File.Exists(filename)) { // check if view name exists if (!contentObjectModel.SceneObjects.Any(x => x.Name == sceneName)) { // name is valid break; } } } while (true); ProjectWindowUtil.CreateAssetWithContent(filename, string.Empty); }
private static void ExternalTypeCreateMenu() { Texture2D icon = AssetPreview.GetMiniTypeThumbnail(typeof(TextAsset)); const string name = "New Utf8Json External Type." + Utf8JsonExternalTypeEditorUtility.EXTERNAL_TYPE_ASSET_EXTENSION_NAME; ProjectWindowUtil.CreateAssetWithContent(name, "{}", icon); }
private static void CreateUXMAsset() { var folder = GetCurrentFolder(); var contents = CreateUXMLTemplate(folder); var icon = EditorGUIUtility.IconContent <VisualTreeAsset>().image as Texture2D; ProjectWindowUtil.CreateAssetWithContent("NewUXMLTemplate.uxml", contents, icon); }
private static void CreateUXMAsset() { var folder = GetCurrentFolder(); var path = AssetDatabase.GenerateUniqueAssetPath(folder + "/NewUXMLTemplate.uxml"); var contents = CreateUXMLTemplate(folder); var icon = EditorGUIUtility.IconContent <VisualTreeAsset>().image as Texture2D; ProjectWindowUtil.CreateAssetWithContent(path, contents, icon); }
public static void CreateUSSFile() { var folder = GetCurrentFolder(); var path = AssetDatabase.GenerateUniqueAssetPath(folder + "/NewUSSFile.uss"); var contents = "VisualElement {}"; var icon = EditorGUIUtility.IconContent <StyleSheet>().image as Texture2D; ProjectWindowUtil.CreateAssetWithContent(path, contents, icon); }
public static void CreateScriptFile() { var selectPath = AssetDatabase.GetAssetPath(Selection.activeObject); if (File.Exists(selectPath)) { selectPath = Path.GetDirectoryName(selectPath) ?? selectPath; } ProjectWindowUtil.CreateAssetWithContent(Path.Combine(selectPath, "NewScript.vns"), "// Write your script here\n\n", EditorGUIUtility.Load("File Icon/VNS Icon.png") as Texture2D); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }
private static void CreateFlatFile(string extention, string content = "") { string path = Selection.activeObject == null ? "Assets" : AssetDatabase.GetAssetPath(Selection.activeObject.GetInstanceID()); if (!Directory.Exists(path)) { // A file was selected instead of a directory so parse the directory from the path. path = Path.GetDirectoryName(path); } ProjectWindowUtil.CreateAssetWithContent($"file{extention}", content); }
public static void CreateTSSFile() { if (CommandService.Exists(nameof(CreateTSSFile))) { CommandService.Execute(nameof(CreateTSSFile), CommandHint.Menu); } else { var contents = "VisualElement {}"; var icon = EditorGUIUtility.IconContent <ThemeStyleSheet>().image as Texture2D; ProjectWindowUtil.CreateAssetWithContent("NewTSSFile.tss", contents, icon); } }
public static void CreateJsAsset() { string path = AssetCreationHelper.GetSelectedPath(); string assetPathAndName = AssetCreationHelper .CreateUniqueAssetPath(path, "JS", "js"); var icon = EditorGUIUtility .IconContent("TextAsset Icon").image as Texture2D; ProjectWindowUtil.CreateAssetWithContent( assetPathAndName, "", icon); }
/// <summary> /// Create a new asset instance saved to disk, in the active directory. /// </summary> /// <param name="assetName">The asset file name with extension.</param> /// <param name="mutator">Optional mutator that can be used to modify the asset.</param> /// <returns>The new asset instance.</returns> public static TContainer CreateAssetInActiveDirectory(string assetName, Action <TContainer> mutator = null) { var path = Path.Combine(GetCurrentAssetDirectory(), assetName); var asset = CreateInstance(mutator); if (asset != null && asset) { var assetPath = AssetDatabase.GenerateUniqueAssetPath(path); ProjectWindowUtil.CreateAssetWithContent(assetPath, asset.SerializeToJson(), AssetPreview.GetMiniThumbnail(asset)); return(asset); } return(null); }
public static void CreateDefaultRuntimeTSSFile() { if (CommandService.Exists(nameof(CreateDefaultRuntimeTSSFile))) { CommandService.Execute(nameof(CreateDefaultRuntimeTSSFile), CommandHint.Menu); } else { var contents = "@import url(\"" + ThemeRegistry.kThemeScheme + "://default\");\nVisualElement {}"; var icon = EditorGUIUtility.IconContent <ThemeStyleSheet>().image as Texture2D; ProjectWindowUtil.CreateAssetWithContent(ThemeRegistry.kUnityRuntimeThemeFileName, contents, icon); } }
public static void CreateTSSFile() { if (CommandService.Exists(nameof(CreateTSSFile))) { CommandService.Execute(nameof(CreateTSSFile), CommandHint.Menu); } else { var folder = GetCurrentFolder(); var path = AssetDatabase.GenerateUniqueAssetPath(folder + "/NewTSSFile.tss"); var contents = "VisualElement {}"; var icon = EditorGUIUtility.IconContent <ThemeStyleSheet>().image as Texture2D; ProjectWindowUtil.CreateAssetWithContent(path, contents, icon); } }
public static void CreateUXMLTemplate() { if (CommandService.Exists(nameof(CreateUXMLTemplate))) { CommandService.Execute(nameof(CreateUXMLTemplate), CommandHint.Menu); } else { var folder = GetCurrentFolder(); var path = AssetDatabase.GenerateUniqueAssetPath(folder + "/NewUXMLTemplate.uxml"); var contents = CreateUXMLTemplate(folder); var icon = EditorGUIUtility.IconContent <VisualTreeAsset>().image as Texture2D; ProjectWindowUtil.CreateAssetWithContent(path, contents, icon); } }
public static void CreateVisualEffectAsset() { var templateString = ""; try { templateString = File.ReadAllText($"{GetTemplatePath()}{_templateAssetName}"); } catch (Exception e) { Debug.LogError("Couldn't read template for new FluvioFX asset : " + e.Message); return; } ProjectWindowUtil.CreateAssetWithContent("New Fluid Particle System.vfx", templateString); }
public static void CreateScript() { var path = ScriptsPath; if (Selection.activeObject != null) { path = AssetDatabase.GetAssetPath(Selection.activeObject); if (!AssetDatabase.IsValidFolder(path)) { path = Path.GetDirectoryName(path); } } path = Path.Combine(path, "MaestroScript.maestro"); ProjectWindowUtil.CreateAssetWithContent(path, ""); if (!path.StartsWith(ScriptsPath)) { Debug.LogWarningFormat("Maestro script path '{0}' is outside of '{1}'", path, ScriptsPath); } }
void CreateNewTemplatesFiles() { if (IsInputValid()) { m_Root.SetEnabled(false); if (m_IsUxmlEnable) { var uxmlPath = Path.Combine(m_Folder, m_UxmlName + ".uxml"); ProjectWindowUtil.CreateAssetWithContent(uxmlPath, UIElementsTemplate.CreateUXMLTemplate(m_Folder), EditorGUIUtility.FindTexture(typeof(VisualTreeAsset))); } if (m_IsUssEnable) { var ussPath = Path.Combine(m_Folder, m_UssName + ".uss"); ProjectWindowUtil.CreateAssetWithContent(ussPath, UIElementsTemplate.CreateUssTemplate(), EditorGUIUtility.FindTexture(typeof(VisualTreeAsset))); } if (m_IsCSharpEnable) { var cSharpPath = Path.Combine(m_Folder, m_CSharpName + ".cs"); ProjectWindowUtil.CreateScriptAssetWithContent(cSharpPath, UIElementsTemplate.CreateCSharpTemplate(m_CSharpName, m_UxmlName, m_UssName, m_Folder)); } else { Close(); } if (m_Root.Q <Toggle>("openFilesToggle").value) { OpenNewlyCreatedFiles(); } } else { ShowErrorMessage(); } }
//[MenuItem("Assets/Create/Delight View + Code-behind", false, -19)] //private static void CreateViewXmlAndCodeBehind() //{ // CreateViewXml(true); //} private static void CreateViewXml(bool generateCodeBehind) { var contentObjectModel = ContentObjectModel.GetInstance(); var path = ContentParser.GetContentFolderPathFromSelectedFile(ContentParser.ViewsFolder); var filename = ""; int i = 0; string viewName = ""; do { viewName = String.Format("NewView{0}", i == 0 ? string.Empty : i.ToString()); filename = String.Format("{0}{1}.xml", path, viewName); ++i; // find unique name if (!File.Exists(filename)) { // check if view name exists if (!contentObjectModel.ViewObjects.Any(x => x.Name == viewName)) { // name is valid break; } } } while (true); // set indicator to generate code-behind once file is renamed if (generateCodeBehind) { var config = MasterConfig.GetInstance(); config.GenerateBlankCodeBehind = true; config.SaveConfig(); } // create XML file that the user will be allowed to name, once created the XML parser will generate the content ProjectWindowUtil.CreateAssetWithContent(filename, string.Empty); }
private static void CreateSnippets(string defaultName, string snippetName, FileExtension extension) { try { // Get the directory path of selection. // Only get the first selection's directory path. // In other words, script will be create under the first selection's directory path. string path = GetSelectionPath(); path = GetDirectoryPath(path); int fileIndex = 1; string fileNameWithExtension = String.Concat(defaultName, ".", extension.ToString()); string targetPath = Path.Combine(path, fileNameWithExtension); while (true) { if (!File.Exists(targetPath)) { string snippetPath = Path.Combine(SnippetsFolder, snippetName); string content = File.ReadAllText(snippetPath); ProjectWindowUtil.CreateAssetWithContent(targetPath, content); break; } else { fileIndex++; fileNameWithExtension = String.Concat(defaultName, fileIndex.ToString(), ".", extension.ToString()); targetPath = Path.Combine(path, fileNameWithExtension); } } } catch (Exception e) { Debug.LogException(e); return; } }
public static void CreateNewAsset() => ProjectWindowUtil.CreateAssetWithContent ("New Metamesh.metamesh", "");
static void CreateAssetWithContentAndStartRenaming(string assetName, string content, Texture2D icon) { ProjectWindowUtil.CreateAssetWithContent($"{GetActiveFolderPath()}/{assetName}", content, icon); }
static void CreateTexture2DArray() { ProjectWindowUtil.CreateAssetWithContent("NewTexture2DArray.texture2darray", "MomomaAssets.Texture2DArrayImporter"); }
private static void CreateManagedText() => ProjectWindowUtil.CreateAssetWithContent("NewManagedText.txt", DefaultManagedTextContent);
private static void CreateScript() => ProjectWindowUtil.CreateAssetWithContent("NewScript.nani", DefaultScriptContent);
public static void CreateNewAsset() => ProjectWindowUtil.CreateAssetWithContent("New Colormap.pugrad", "");
public static void CreateNewAsset() => ProjectWindowUtil.CreateAssetWithContent ("New Gradation Texture.gradation", "");