uTemplate Beta Feedback Thread

Unfinity Games

Infinite
Staff member
Jun 14, 2014
49
2
30
#1
Originally, I'd planned for each bit of feedback to be its own thread, but it seems like a good idea to have a general feedback thread for non-specific ideas/thoughts. If you'd like to talk about a specific feature, or something in specific, feel free to make a thread specifically for that.

So, let 'er rip! All feedback is welcome here!
 
Last edited:
Jul 15, 2016
4
2
15
#2
I like very much what I see. I have another templating asset that I have been using, but it is not as feature rich as this one. I'm going to start using this in my daily workflow already.
 

Unfinity Games

Infinite
Staff member
Jun 14, 2014
49
2
30
#3
I'm really glad you like it, @Tinjaw! It was born out of necessity, and it kind of rolled into something much more than it was originally designed to do. Template method inheritance, presets, and a bunch of other stuff came about out of a "well, this is great now, but what if uTemplate could do this too?".

Out of curiosity, is there anything in your other template asset that you like, but isn't currently possible in uTemplate?
 
Jul 22, 2016
6
1
15
#4
Hi everyone, Just joined and happy to try the beta. docavage same as on unity forum. Using uNote on main project now. Working great. Really useful. Will donwload utemplate now :)
 
Jul 22, 2016
6
1
15
#5
I'm really glad you like it, @Tinjaw! It was born out of necessity, and it kind of rolled into something much more than it was originally designed to do. Template method inheritance, presets, and a bunch of other stuff came about out of a "well, this is great now, but what if uTemplate could do this too?".

Out of curiosity, is there anything in your other template asset that you like, but isn't currently possible in uTemplate?
Hi @Tinjaw. See you most days on the secret sale thread. Good one that. Well done for getting it going:) I keep looking and commenting to keep it on the asset store forum front page.

Don't want to hijack the thread. As Unfinity asked for feedback here thought would post it here. Apologies if this is not done.

@Unfinity Games , Just had a quick test. Really like it. Nice and simple from what I can see. One thing haven't found is a way to add my own methods. Does one exist or is it me being a bit slow.

Two things I would do:

1. Make an Unfinity dropdown menu for all your products to be listed in and quick access.
2. Make the template window dockable so it can sit in the editor.

Also hope you don't mind but I have pointed your unity thread out to a couple of beta groups I am in. Hopefully you'll get more onboard:)
 
Jul 22, 2016
6
1
15
#6
Just had a thought. If you make the live window editable. We could type our own templates/methods/etc out and if you had a 'save template' button at the bottom this could be used to save it out to the template list. Just a thought.
 

Unfinity Games

Infinite
Staff member
Jun 14, 2014
49
2
30
#7
@Unfinity Games , Just had a quick test. Really like it. Nice and simple from what I can see. One thing haven't found is a way to add my own methods. Does one exist or is it me being a bit slow.

Two things I would do:

1. Make an Unfinity dropdown menu for all your products to be listed in and quick access.
2. Make the template window dockable so it can sit in the editor.
Hey, @docsavage! Welcome, and thanks for giving uTemplate a go!

You can definitely add your own Templates and associated Methods (in fact, that's what I made it for!). You can read about that in the Documentation.

As for #1, making top-level dropdown menus is actually discouraged by the Unity Asset Store team, so I can't really do that (unfortunately). Interesting tidbit, the early, early version of U2DEX actually did that, but that was before that soft-rule was instated by the UAS team (way back in 2013!).

As for #2, I'll look into that. The window is more meant to be popped open, used, and removed so it doesn't get in the way, but I'll see what I can do about that. I'm fully aware that my personal workflow may not be best.

Also hope you don't mind but I have pointed your unity thread out to a couple of beta groups I am in. Hopefully you'll get more onboard:)
Nope, that's totally fine! The hardest part is getting the word out -- thanks for helping!

Just had a thought. If you make the live window editable. We could type our own templates/methods/etc out and if you had a 'save template' button at the bottom this could be used to save it out to the template list. Just a thought.
Due to the way that Unity's internal AssetDatabase works, I'm not sure it'd handle the live window being editable (there's also a fair bit of Reflection used by uTemplate to check methods and types, etc.) so I can't think of an easy way to do this. I've added to the list, though, as I like the idea behind it.

Thanks for all the feedback, keep it coming!
 
Last edited:

samix

New Member
Dec 14, 2017
8
0
1
#9
Hi team,
I'm looking for a way to add the date of creation of the script in my template. Something like: Replace("
#DATE#", DateTime.Now.ToString("MM/dd/yyyy"));
Wondering if there is a way to extend the Template Keywords.
Please let me know what you think.
Thanks
Sam
 

Unfinity Games

Infinite
Staff member
Jun 14, 2014
49
2
30
#10
Hi there @samix, thanks for getting in touch!

There currently isn't a built-in way to do that. I can see the utility in being able to output the current date/time, so I can definitely look into this. DateTime is kind of tricky, though, as ideally the Keyword would support formatting (i.e. so it isn't hardcoded into a MM/dd/yyyy format), but Keywords aren't really set up to take arguments.

I think in this case it would be better to not make this a built-in Keyword, but instead come up with a way to inject some kind of Keyword replacement Key/Value pair. Ideally, this would be self-contained in some user-editable .cs file, so it gets compiled normally (easier to catch errors than have it in a standalone text-file!). Due to how Unity works, though, I'm not sure how a user-editable .cs file would work, as any changes would get overwritten any time uTemplate is updated.

So, I'm thinking of some kind of API hook that could be used like this:

C#:
[InitializeOnLoad]
    public class uTemplateCustomKeywords
    {
        static uTemplateCustomKeywords()
        {
            //Register our replacement.
            UnfinityGames.uTemplate.uTemplateScriptCreationWizard.RegisterKeywordReplacement("#DATETIME#, DateTime.Now.ToString("MM/dd/yyyy"));
        }
    }
So, pros and cons:

Pros
  • Would be a generic solution, so it would work for many different types of replacements.
  • Would allow replacements to run more advanced C# code, as long as they return a string.
  • Global -- would allow replacements to be specified in one place, and used in all templates.
Cons
  • Would require the user to make a separate .cs file. (This might be a kind of stealth Pro, though, as it won't get overwritten by Unity this way!)
  • Due to the use of InitializeOnLoad, it's possible, if unlikely, that Unity could miss the initialization of the script object on a recompile, meaning you'll lose any custom replacements.
  • Any C# code that's used to generate a Key or Value for the replacement would be run when the script is Initialized. Meaning that, in the example, #DATETIME# would be replaced with the DateTime when the class was Initialized, not when the script is generated.
The last con is tricky, as it basically makes this not work for your intended purpose. This kind of system would work for the majority of Keyword replacements, but it would not work very well for anything that needs to be somewhat dynamic.

Give me some time to think about this and experiment. I think it's a great idea, it's just that DateTime is one of the more complicated examples of something to inject in a case like this.
 

Unfinity Games

Infinite
Staff member
Jun 14, 2014
49
2
30
#11
So, this is in-progress but the way it's shaping up is pretty cool. Basically, I went with an easier-to-use abstract class inheritance system, so your actual keyword definition class will look something like this:

C#:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

using UnfinityGames.uTemplate;

public class uTemplateKeywords : uTemplateCustomKeywordContainer
{
    public string HeaderInfo = "//Copyright (c) Some Company 2017.  All rights reserved.\n"
                            + "//#NICESCRIPTNAME# (#SCRIPTNAME#) generated on #DATETIME#.";   

    public override Dictionary<string, string> KeywordReplacements()
    {
        return new Dictionary<string, string>()
        {
            { "#DATE#", System.DateTime.Now.ToString("MM/dd/yyyy") },
            { "#DATETIME#", System.DateTime.Now.ToString("MM/dd/yyyy HH:mm") },
            { "#HEADERINFO#", HeaderInfo }
        };
    }
}
As you can see, you can get pretty creative with the keyword replacements, and there aren't really any restrictions on what you can use as a replacement value (as long as it evaluates to a string!).

The best news is that these are evaluated at generation time (i.e. when the script is being generated by uTemplate) so DateTime will work correctly. One important thing, though, is that these replacements operate independently of some of the built-in ones. Due to the way these get injected, they get injected after some built-in ones are processed. The good news is that it makes these much more flexible (so flexible that SCRIPTNAME and NICESCRIPTNAME are now using this system internally!). The main thing is that you can't use SCRIPTHEADER or SCRIPTMETHODS with these, as those have to be on their own lines for proper processing.

Otherwise, if a keyword doesn't require it being on its own line (like SCRIPTNAME, for example, or any custom ones) you can nest these and have keywords inside of keyword replacements, like HeaderInfo in the above example.

This is a pretty big change, and it's not fully functional yet, but if you want to PM my your invoice number here I can get you set up with a beta version of this new feature when it's ready.
 

Unfinity Games

Infinite
Staff member
Jun 14, 2014
49
2
30
#12
A new beta version of uTemplate is available in the downloads area for registered buyers. It includes the new keyword replacement system.

Give it a spin and feel free to post feedback here. It's a very, very new system, so there may be bugs -- I'd be extremely interested in hearing about any thoughts or issues anyone has, as it also involved rewriting a pretty good chunk of the keyword parsing system.
 

Unfinity Games

Infinite
Staff member
Jun 14, 2014
49
2
30
#14
Ah, that's right -- without the documentation it's not exactly easy to work out!

You're going to have to make a class that inherits from, and implements, the abstract uTemplateCustomKeywordContainer class. The example code I posted above should be a good starting point. Just make sure it's in an Editor folder somewhere so it gets compiled into the Editor-specific code.

The magic happens in the KeywordReplacements method, as that's where you can set up your keyword replacements. Additionally, you can make use of the CurrentTemplateData variable of the uTemplateCustomKeywordContainer, as the variables contained in that struct will be auto-filled in by uTemplate before processing (so you can use it to get the ClassName, NiceClassName and EditorTargetClassName, if needed). It might be helpful for building certain replacements, so you're free to access them!

Additionally, several of the built-in replacements can be used inside of your custom replacements. Namely the #SCRIPTNAME#, #NICESCRIPTNAME# and #TARGETCLASSNAME# keywords. You can chain them inside of your custom replacements, and play around with a bit of keyword-ception.

Finally, since uTemplate looks this up dynamically right before processing, you can use DateTime or anything of that sort and it will be accessed right before it's output, so everything should be as fresh as possible.

Hopefully that answers your question! Post back if you run into any other issues or have any additional thoughts!
 

samix

New Member
Dec 14, 2017
8
0
1
#15
Thanks for the direction. It gave me a start; I copied your example code (posted above) to create uTemplateKeywords.cs, inside an Editor folder. But after I haven’t find the way to use it / connect it to the system. Should I attached it to the .preset.asset?
Please let me know what you think.
Thanks
 

Unfinity Games

Infinite
Staff member
Jun 14, 2014
49
2
30
#16
Once you register the keywords in that class, you can start using your keyword replacements in all of your Templates. The replacement system doesn't do anything on its own -- you have to add your new keywords to any Templates you want to use them in. For example, here's a modified MonoBehaviour Template using #DATETIME# keyword from my example:

MonoBehaviour.cs.txt
Code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

Script #SCRIPTNAME# generated on #DATETIME#

#SCRIPTHEADER#
public class #SCRIPTNAME# : MonoBehaviour
{
    #SCRIPTMETHODS#
}
For more information on creating Templates, you can check the documentation on creating Templates.
 

samix

New Member
Dec 14, 2017
8
0
1
#17
Thanks for your explanation, the #DATETIME# works great now : )
I have been confused by the KeywordReplacementKeys, and KeywordReplacementValues fields in the inspector of the preset.asset / Template object. Should I simply ignore those fields?
 

Unfinity Games

Infinite
Staff member
Jun 14, 2014
49
2
30
#18
Glad you got it working!

Yes, the KeywordReplacementKeys and KeywordReplacementValues in the .preset.asset files should be ignored. They're used internally, but due to the way .asset files work they get serialized and displayed in the inspector. They wouldn't be very good for users anyway, as you wouldn't be able to have dynamic replacements like this new system offers. I'd forgotten that they get serialized and displayed -- sorry for the confusion!

Please report back if you have any thoughts or issues with the pre-release build. It's a pretty big change, so I definitely want to make sure nothing major breaks before releasing it to the Asset Store.

Once everything checks out some documentation can be made and it can be released for everyone. Thanks for testing it!
 

samix

New Member
Dec 14, 2017
8
0
1
#19
Thanks for the clarification.
In the .preset.asset files, I noticed that some params works such as “Class Name” and “Class Comment”, and some not, such as “Namespace”. Maybe you could use HideInInspector] to limit the visible variables to only what the user can update in the inspector.

I tested the option to set the default nameSpace in the preferences (pretty cool). In addition, is it possible to also set the namespace in the .preset.asset files?
Please let me know what you think; and thanks again for your time.


Ps: I have to admit I’m still wondering how you made uTemplateKeywords.cs works, by overriding the KeywordReplacements Dictionary. : )
 

Unfinity Games

Infinite
Staff member
Jun 14, 2014
49
2
30
#20
To be honest, editing preset files via the Inspector was never a supported feature -- anything that works is unintended. Unity's AssetDatabase is so fragile, that I wouldn't recommend editing anything in there, especially as a lot of the information is inter-related, and could confuse the various parsers when loaded. I could hide the various fields, but I think that would be confusing in debug scenarios when a preset doesn't work correctly (which hasn't happened yet, thankfully!).

It's far safer, and often easier, to just load up the preset, change whatever needs changed, and save it back out again. Editing the asset values via the Inspector is not recommended.

I tested the option to set the default nameSpace in the preferences (pretty cool). In addition, is it possible to also set the namespace in the .preset.asset files?
Please let me know what you think; and thanks again for your time.
It is not currently possible to set namespaces per-file. It's a feature that will likely be included eventually, but it's not high-priority as most users find that the Default Namespace is enough. Most users don't even use a namespace at all!

Ps: I have to admit I’m still wondering how you made uTemplateKeywords.cs works, by overriding the KeywordReplacements Dictionary. : )
Ha, that's a little bit of Reflection magic. ;)
 
Forgot your password?