Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Manage Script Templates

Discussion in 'Unity Hub Preview' started by v01pe_, Feb 8, 2018.

  1. v01pe_

    v01pe_

    Joined:
    Mar 25, 2015
    Posts:
    31
    I like to replace the standard script templates with my own and also add a few custom ones. The script templates I'm talking about are those used when selecting e.g. Create -> C# Script from the context menu in the project window, or form the Assets menu.

    They are located inside the Unity install folder at Unity.app/Contents/Resources/ScriptTemplates on OS X and at Editor\Data\Resources\ScriptTemplates on Windows. Therein also lies the problem of modifying them… every time you install a new version of Unity, those are not present any more and have to be copied over to the new install folder, or are lost, if you install over the same folder.

    I wrote a script to place them where they belong for new installs, but through the Unity Hub would be a convenient way to manage these templates and make them available on all Unity versions installed.
     
  2. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,052
    What if we made it that you could just put your custom templates in your project folder somewhere instead, so that you didn't need to modify the install?
     
    hadynlander and Iamsodarncool like this.
  3. v01pe_

    v01pe_

    Joined:
    Mar 25, 2015
    Posts:
    31
    Actually better would be if they could be put in a user folder like other Unity settings. At least the files that I'm using aren't really project specific. That's p.e. my `81-C# Script-NewBehaviourScript.cs.txt`:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class #SCRIPTNAME# : MonoBehaviour
    4. {
    5.     void Start()
    6.     {
    7.        
    8.     }
    9.    
    10.     void Update()
    11.     {
    12.        
    13.     }
    14. }
    I thought about hooking them up with Unity Hub, because I often work on two different computers and the Hub would be a great way to not only keep them with different Unity versions, but also on different machines if they are synced.

    But I'd already very happy if I could override and add to the default ones by placing them somewhere in my Library folder.
     
    AlanMattano and Iamsodarncool like this.
  4. hadynlander

    hadynlander

    Joined:
    Jan 24, 2014
    Posts:
    24
    I realise I'm late to the party here, but it made more sense to reply to this comment than start a fresh thread.

    Anyway, I'd really like this! It'd be super useful to have template scripts with the correct namespaces baked in for different projects, both as a freelancer (jumping between many projects) and as a team contributor (ensuring consistency across the codebase). I could even see myself creating more specialised templates per project if I wasn't concerned about cluttering up the Create context menu in unrelated projects...

    So that's a resounding yes please from me, if it's not too late!
     
    Iamsodarncool likes this.
  5. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    859
    I'm afraid that if Unity for some technical reason changes the default templates, having my own template, I will not notice the difference and I will lose the upgrade.

    Is annoying searching inside C:\Program Files\Unity\Hub\Editor folder because folders of different Unity versions are not deleted. A fast link to the C# folder of that particular Vr can be a very good starting solution?

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. /********************************************
    4. *
    5. *  2018
    6. *  #SCRIPTNAME#
    7. *  
    8. *      .
    9. *  
    10. *          .
    11. *
    12. * *****************************************/
    13.  
    14. public class #SCRIPTNAME# : MonoBehaviour
    15. {
    16.     #region VARIABLES
    17.     [Space][Header("#SCRIPTNAME#")]
    18.     [Space(25)]
    19.     [Space]
    20.  
    21.     // PUBLIC
    22.     public bool consoleDebug;
    23.  
    24.     // PRIVATE
    25.     #endregion
    26.  
    27.     void Start ()
    28.     {
    29.         #NOTRIM#
    30.     }
    31.  
    32.     void Update ()
    33.     {
    34.         #NOTRIM#
    35.     }
    36. }
    37.  
    38. /*
    39. using System.Collections;        // For sub rutine & making list
    40. using System.Collections.Generic;    // for making list
    41. using UnityEngine.UI;
    42. using UnityEngine.EventSystems;        // pass on what the button do when is click
    43.     [Range(0, 3.5f)]
    44.     [Tooltip("Info")]
    45.     [Space][Header("INPUTS")][Space]
    46.     [Space][Header("DRAG & DROP")][Space]
    47.     [Space][Header("OUTPUTS")][Space]
    48.     if (consoleDebug) Debug.Log("" + "\n");
    49.     void OnGUI(){GUILayout.TextArea("text " + VARIABLE.ToString() );}
    50.     GUIStyle guiStyle = new GUIStyle();
    51.     void OnGUI()
    52.     {
    53.         guiStyle.fontSize = 50;
    54.         guiStyle.normal.textColor = Color.white;
    55.         GUI.Label(new Rect(10, 10, 100, 20), "Notas: " + myVar1, guiStyle);
    56.         GUI.Label(new Rect(10, 65, 100, 20), "Infos: " + myVar2, guiStyle);
    57.     }
    58. /*------------------------------- FUNCTIONS -----------------------------*/
    59.  
     
    Last edited: Jun 13, 2018
  6. v01pe_

    v01pe_

    Joined:
    Mar 25, 2015
    Posts:
    31
    I know this is already kind of an old thread, but here and then I think about it and the more I do so the more I like the idea of being able to put the templates into a folder somewhere inside the project. This way one could add even more specialised presets that only make sense for that project.

    Additionally it would still be nice to have a collection of template overrides that I want to include in every new project. This could be solved by a more general approach by defining custom project presets like "2D" and "3D" that already exist as dropdown in the new project view!
     
    hadynlander likes this.
  7. hadynlander

    hadynlander

    Joined:
    Jan 24, 2014
    Posts:
    24
    It would also be useful for students at schools and universities who don't have permissions to access the Unity install directory, or for people working in offices with shared machines, etc.

    I used to teach at a uni where both of those situations applied, and it was annoying enough having the default script template with curly braces on the same line as declarations... which was bad not because one standard's better than another (that part of the argument is entirely subjective / pointless), but because it confuses newbies with a standard that differs from almost every other code example they'll ever find in the Unity API / Unity Manual / MSDN / DotNetPerls / etc...
     
  8. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    3,175
    I did some major sleuthing through Unity's csharp reference over the weekend, and I baked up Unity-Script-Templates, which is a little plugin to create custom script templates, and edit the built-in ones though an editor window.

    Editing the built-in ones requires you to launch Unity as root/Administrator, as it's just a simple File.Write operation, so it won't solve @hadynlander's problem. That being said, it's a pretty good stop gap measure until we get an official solution.
     
    hadynlander likes this.
  9. hadynlander

    hadynlander

    Joined:
    Jan 24, 2014
    Posts:
    24
    Nice one @Baste! I'll try to give it a shot later this week :)