示例#1
0
        static void Create()
        {
            //var assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);
            //var dataPath = Application.dataPath.Replace("Assets", "");
            //var FileName = "NewHLSL.hlsl";
            //var assetName = assetPath + "/" + FileName;
            //var fullPath = dataPath + assetName;

            //for (int i = 1; File.Exists(fullPath); i++)
            //{
            //    var newFileName = "NewHLSL " + i.ToString() + ".hlsl";
            //    assetName = assetPath + "/" + newFileName;
            //    fullPath = dataPath + assetName;
            //}

            //File.WriteAllText(fullPath, "", Encoding.UTF8);

            //AssetDatabase.Refresh();

            //var asset = AssetDatabase.LoadAssetAtPath(assetName, typeof(object));
            //Selection.activeObject = asset;

            string templatePath = AssetDatabase.GUIDToAssetPath(hlslTemplateGUID);

            ProjectWindowUtil.CreateScriptAssetFromTemplateFile(templatePath, defaultNewHLSLName);
        }
    public static void CreateUsingAlternativeScriptTemplate()
    {
        string templateAlternative = SelectScriptTemplateAsset();

        //User cancelled the selection
        if (string.IsNullOrEmpty(templateAlternative))
        {
            return;
        }

        ProjectWindowUtil.CreateScriptAssetFromTemplateFile(templateAlternative, "YourBehaviour.cs");
    }
示例#3
0
 private static void TryCreateScriptFromTemplate(string templateName, string defaultScriptName)
 {
     string[] guids = AssetDatabase.FindAssets(templateName);
     if (guids.Length == 0)
     {
         Debug.LogWarning(templateName + ".txt not found in asset database");
     }
     else
     {
         ProjectWindowUtil.CreateScriptAssetFromTemplateFile(AssetDatabase.GUIDToAssetPath(guids[0]), defaultScriptName + ".cs");
     }
 }
    public static void CreateUsingDefaultScriptTemplate(string pathToYourScriptTemplate)
    {
        //Check if we're in the Package Development-project or in a project that is using this script as a Package.
        Object scriptTemplateAsset = AssetDatabase.LoadAssetAtPath($"Packages/{pathToYourScriptTemplate}", typeof(Object));

        if (scriptTemplateAsset == null)
        {
            scriptTemplateAsset = AssetDatabase.LoadAssetAtPath($"Assets/{pathToYourScriptTemplate}", typeof(Object));
        }

        pathToYourScriptTemplate = AssetDatabase.GetAssetPath(scriptTemplateAsset);
        ProjectWindowUtil.CreateScriptAssetFromTemplateFile(pathToYourScriptTemplate, "PaaloBehaviour.cs");
    }
示例#5
0
        /// <summary>
        /// Looks for a Template in the external UserData Folder and creates a script from it.
        /// </summary>
        public static void CreateScriptFromCustomTemplate(string templateName, string defaultScriptName)
        {
            string templatePath = Path.Combine(GlobalPaths.UserTemplatesFolderPath, $"{templateName}.cs.txt");

            try
            {
                ProjectWindowUtil.CreateScriptAssetFromTemplateFile(templatePath, $"{defaultScriptName}.cs");
            }
            catch
            {
                ScriptBuilder.LogWarning("Template not found! Reimporting Custom Templates...");
                TemplateSettingsEditorWindow.RefreshCustomTemplates();
            }
        }
    void OnGUI()
    {
        EditorGUILayout.Space();

        targetPipeline = (TargetPipeline)EditorGUILayout.EnumPopup("Target Pipeline", targetPipeline);

        shaderName = EditorGUILayout.TextField("Shader Name", shaderName);

        if (Input.GetMouseButtonUp(0) || Input.GetKeyUp(KeyCode.Return) || Input.GetKeyUp(KeyCode.KeypadEnter))
        {
            int kbdCtrlId = GUIUtility.keyboardControl;
            if (kbdCtrlId != lastKeyboardControl)
            {
                // check to see if the focused control is this text area...
                string focusedControl = GUI.GetNameOfFocusedControl();

                if (focusedControl == "Shader Name")
                {
                    // It is!  Now, get the editor state and tweak it.
                    TextEditor textEditor = GUIUtility.GetStateObject(typeof(TextEditor), kbdCtrlId) as TextEditor;
                    textEditor.SelectAll();
                    lastKeyboardControl = kbdCtrlId;
                }
            }
        }

        EditorGUILayout.Space();
        var rect = EditorGUILayout.BeginHorizontal();

        Handles.color = Color.gray;
        Handles.DrawLine(new Vector2(rect.x - 15, rect.y), new Vector2(rect.width + 15, rect.y));
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Space();

        if (GUILayout.Button("Create"))
        {
            switch (targetPipeline)
            {
            case TargetPipeline.HDRP:
                ProjectWindowUtil.CreateScriptAssetFromTemplateFile("Assets/Simplified Custom Shaders/Base/HDRP/CustomProgram.template", shaderName + " Program.shaderprogram");
                ProjectWindowUtil.CreateScriptAssetFromTemplateFile("Assets/Simplified Custom Shaders/Base/HDRP/CustomShader.template", shaderName + ".shader");
                break;

            case TargetPipeline.URP:
                Debug.LogError("[SCS] Pipeline not supported yet.");
                break;
            }
            Close();
        }
    }
示例#7
0
        private void CreateNewScript(ScriptTemplate template)
        {
            string path = $"{settings.newNodeScriptFolder}/{template.folder}";

            if (path.EndsWith("/"))
            {
                path = path.Substring(0, path.Length - 1);
            }

            UnityEngine.Object script = AssetDatabase.LoadAssetAtPath(path, typeof(UnityEngine.Object));
            Selection.activeObject = script;
            EditorGUIUtility.PingObject(script);

            string templatePath = AssetDatabase.GetAssetPath(template.templateFile);

            ProjectWindowUtil.CreateScriptAssetFromTemplateFile(templatePath, template.fileName);
        }
示例#8
0
        private static void CreateNewCSharpScript()
        {
            string scriptPath   = Path.Combine(ProjectBrowserExt.GetSelectedPath(), "NewBehaviourScript.cs");
            string templatePath = Path.Combine(Path.GetTempPath(), "NewBehaviourScript.cs");

            File.WriteAllText(Path.GetFullPath(templatePath)
                              , Template.TransformToText <DerivedClass_cs>(new Dictionary <string, object>
            {
                { "namespacename", UnityEditorExSettings.instance.GetNamespaceName(scriptPath) },
                { "classname", "#SCRIPTNAME#" },
                { "baseclassname", "MonoBehaviour" },
                { "isPartial", false },
                { "content", "" }
            }));

            ProjectWindowUtil.CreateScriptAssetFromTemplateFile(templatePath, scriptPath);
        }
        private void CreateVariableScript()
        {
            var    settings = BehaviourTreeSettings.GetOrCreate();
            string path     = $"{settings.newVarScriptFolder}/{ScriptTemplate.Variable.folder}";

            if (path.EndsWith("/"))
            {
                path = path.Substring(0, path.Length - 1);
            }

            UnityEngine.Object script = AssetDatabase.LoadAssetAtPath(path, typeof(UnityEngine.Object));
            Selection.activeObject = script;
            EditorGUIUtility.PingObject(script);

            string templatePath = AssetDatabase.GetAssetPath(ScriptTemplate.Variable.templateFile);

            ProjectWindowUtil.CreateScriptAssetFromTemplateFile(templatePath, ScriptTemplate.Variable.fileName);
        }
示例#10
0
    public static void CreateScriptFromTemplate(string templateName, string defaultScriptName)
    {
        bool success = true;

        try
        {
            ProjectWindowUtil.CreateScriptAssetFromTemplateFile(
                $"{TemplatesRootFramework}/{templateName}",
                defaultScriptName);
        }
        catch (System.IO.FileNotFoundException)
        {
            success = false;
        }
        if (!success)
        {
            success = true;
            try
            {
                ProjectWindowUtil.CreateScriptAssetFromTemplateFile(
                    $"{TemplatesRootSolo}/{templateName}",
                    defaultScriptName);
            }
            catch (System.IO.FileNotFoundException)
            {
                success = false;
            }
        }
        if (!success)
        {
            //success = true;
            try
            {
                ProjectWindowUtil.CreateScriptAssetFromTemplateFile(
                    $"{TemplatesRootAssets}/{templateName}",
                    defaultScriptName);
            }
            catch (System.IO.FileNotFoundException)
            {
                //success = false;
            }
        }
    }
示例#11
0
    public static void CreateRuntimeComponentType()
    {
        bool success = true;

        try
        {
            ProjectWindowUtil.CreateScriptAssetFromTemplateFile(
                $"{TemplatesRootFramework}/Bootstrap.txt",
                "LatiosBootstrap.cs");
        }
        catch (System.IO.FileNotFoundException e)
        {
            success = false;
        }
        if (!success)
        {
            success = true;
            try
            {
                ProjectWindowUtil.CreateScriptAssetFromTemplateFile(
                    $"{TemplatesRootSolo}/Bootstrap.txt",
                    "LatiosBootstrap.cs");
            }
            catch (System.IO.FileNotFoundException e)
            {
                success = false;
            }
        }
        if (!success)
        {
            success = true;
            try
            {
                ProjectWindowUtil.CreateScriptAssetFromTemplateFile(
                    $"{TemplatesRootAssets}/Bootstrap.txt",
                    "LatiosBootstrap.cs");
            }
            catch (System.IO.FileNotFoundException e)
            {
                success = false;
            }
        }
    }
示例#12
0
        private static void AddScriptTemplate(string name, int priority, string file, string template, Entry parent = null, Type createdType = null)
        {
#if !UNITY_2019_1_OR_NEWER
            CreateScriptAsset createScriptAsset =
                new InternalGetter <CreateScriptAsset>(typeof(ProjectWindowUtil), "CreateScriptAsset").Func;
#endif
            var entry = new Entry(name, () =>
            {
#if UNITY_2019_1_OR_NEWER
                ProjectWindowUtil.CreateScriptAssetFromTemplateFile(template, file);
#else
                createScriptAsset(template, file);
#endif
            }, () => true, parent, priority, createdType);

            if (parent == null)
            {
                entries.Add(entry);
            }
            else
            {
                parent.Children.Add(entry);
            }
        }
    public static void CreateSmartScript()
    {
        string selectionAssetPath = GetSelectionAssetPath();

        GetScriptTemplateForPath(selectionAssetPath, out string templateContent, out string defaultName);

        if (string.IsNullOrEmpty(templateContent) || string.IsNullOrEmpty(defaultName))
        {
            return;
        }

        if (!defaultName.EndsWith(".cs"))
        {
            defaultName += ".cs";
        }

        // Unity needs a text file like: MyScriptTemplate.txt
        // so we make one in the Temp folder.
        string templateFilePath = MakeScriptTemplateTxtFile(templateContent);

        ProjectWindowUtil.CreateScriptAssetFromTemplateFile(templateFilePath, defaultName);

        PostCreateProcessor.s_NewSmartScriptPath = selectionAssetPath;
    }
示例#14
0
        static void MenuCreateCustomRenderersPassShader()
        {
            string templatePath = $"{HDUtils.GetHDRenderPipelinePath()}/Editor/RenderPipeline/CustomPass/CustomPassRenderersShader.template";

            ProjectWindowUtil.CreateScriptAssetFromTemplateFile(templatePath, "New Renderers CustomPass.shader");
        }
示例#15
0
 static void CreateCustomRuleTile()
 {
     ProjectWindowUtil.CreateScriptAssetFromTemplateFile("Packages/com.unity.2d.tilemap.extras/Editor/Tiles/RuleTile/ScriptTemplates/NewCustomRuleTile.cs.txt", "NewCustomRuleTile.cs");
 }
示例#16
0
        public static void CreateCSharpMixtureViewNodeFile()
        {
            var template = Resources.Load <TextAsset>(cSharpMixtureNodeViewTemplate);

            ProjectWindowUtil.CreateScriptAssetFromTemplateFile(AssetDatabase.GetAssetPath(template), cSharpMixtureNodeViewName);
        }
示例#17
0
        public static void CreateComuteShaderFile()
        {
            var template = Resources.Load <TextAsset>(computeShaderTemplate);

            ProjectWindowUtil.CreateScriptAssetFromTemplateFile(AssetDatabase.GetAssetPath(template), computeShaderDefaultName);
        }
示例#18
0
        public static void CreateCGFixedShaderNode()
        {
            var template = Resources.Load <TextAsset>(shaderNodeCGTemplate);

            ProjectWindowUtil.CreateScriptAssetFromTemplateFile(AssetDatabase.GetAssetPath(template), shaderName);
        }
示例#19
0
        public static void CreateCustomMipMapShaderGraph()
        {
            var template = Resources.Load <TextAsset>(customMipMapShaderTemplate);

            ProjectWindowUtil.CreateScriptAssetFromTemplateFile(AssetDatabase.GetAssetPath(template), "Custom MipMap");
        }
示例#20
0
 public static void CreatNewLuaTxt()
 {
     ProjectWindowUtil.CreateScriptAssetFromTemplateFile("Assets/GameMain/Configs/LuaCodeTemplate.txt",
                                                         "NewLuaScript.lua.txt"
                                                         );
 }
示例#21
0
 public static void CreateDialogueReplaceData()
 {
     ProjectWindowUtil.CreateScriptAssetFromTemplateFile(
         $"{TemplatesRoot}/DialogueReplaceDataTemplate.txt",
         "DialogueReplaceData.cs");
 }
 static void CreateCustomAnimatedRuleTile()
 {
     ProjectWindowUtil.CreateScriptAssetFromTemplateFile("Assets/Tilemap/Tiles/Animated Rule Tile/ScriptTemplates/NewCustomAnimatedRuleTile.cs.txt", "NewCustomAnimatedRuleTile.cs");
 }
示例#23
0
 public static void CreateComponentBufferScript()
 {
     ProjectWindowUtil.CreateScriptAssetFromTemplateFile(COMPONENT_BUFFER_SCRIPT_PATH, "ExampleComponent.cs");
 }
示例#24
0
        static void MenuCreateCustomPassCSharpScript()
        {
            string templatePath = $"{HDUtils.GetHDRenderPipelinePath()}/Editor/RenderPipeline/CustomPass/CustomPassCSharpScript.template";

            ProjectWindowUtil.CreateScriptAssetFromTemplateFile(templatePath, "New Custom Pass.cs");
        }
示例#25
0
 public static void CreateSimpleSystemScript()
 {
     ProjectWindowUtil.CreateScriptAssetFromTemplateFile(SIMPLE_SYSTEM_SCRIPT_PATH, "ExampleSystem.cs");
 }
示例#26
0
 public static void CreateAuthoringComponentType()
 {
     ProjectWindowUtil.CreateScriptAssetFromTemplateFile(
         $"{TemplatesRoot}/AuthoringComponent.txt",
         "NewComponent.cs");
 }
示例#27
0
 public static void CreateSystem()
 {
     ProjectWindowUtil.CreateScriptAssetFromTemplateFile(
         $"{TemplatesRoot}/System.txt",
         "NewSystem.cs");
 }
示例#28
0
        internal static void CreateNewRendererFeature()
        {
            string templatePath = AssetDatabase.GUIDToAssetPath(ResourceGuid.rendererTemplate);

            ProjectWindowUtil.CreateScriptAssetFromTemplateFile(templatePath, defaultNewClassName);
        }
示例#29
0
        static void MenuCreatePostProcessShader()
        {
            string templatePath = $"{HDUtils.GetHDRenderPipelinePath()}/Editor/PostProcessing/Templates/CustomPostProcessingShader.template";

            ProjectWindowUtil.CreateScriptAssetFromTemplateFile(templatePath, "New Post Process Shader.shader");
        }
 static void CreateCustomFunction()
 {
     ProjectWindowUtil.CreateScriptAssetFromTemplateFile("Assets/HLSL Asset/Editor/CFTemplate.hlsl", "New Function.hlsl");
 }