really really irritating new C# file thing

To compiler dev team: In the future, can you please do the following at the beginning of C# scripts:

using UnityEngine;
using System; // <- need this to throw and catch useful exceptions
using System.Collections.Generic; // <- need this for almost-not-braindead containers

Instead of:

using UnityEngine;
using System.Collections; // <- USELESS!

because I’m finding that I have to change this for every file the editor creates. I’d use VS macros, except they have a tendency to be buggy.


Anyway, just a gripe of mine.

You can go and alter the script template yourself, if you like. Look in:

Unity\Editor\Data\Resources\ScriptTemplates

Thank you for the quick reply.

I didn’t know there was an actual “new files” templates folder.

Life is now a teensy bit better.

Thats cool. Thanks for that very useful tip

No, this is a bad idea for general usage.

using System; // <- need this to throw and catch useful exceptions

If you did this, anytime you used Random, you’d need to differentiate between System.Random and UnityEngine.Random, which would confuse a lot of people, trust me. You don’t technically ever need “using System” in any case, just prepend System where necessary. (e.g. System.Exception instead of Exception.)

using System.Collections; // <- USELESS!

It’s far from useless; you use it for IEnumerator (coroutines). Without it you could do “System.Collections.IEnumerator” instead, but again, not having it by default would confuse far too many people. The only thing I’d agree with is importing System.Collections.Generic as standard, but as PlanetTimmy mentions, you can always change the template yourself.

–Eric

FWIW I don’t think there’s any issue with using both System.Collections and System.Collections.Generic in the same file. When you use IEnumerator, if you use it without generic arguments then you get the coroutine-compatible version from System.Collections, and if you use it with generic arguments then you get the generics-compatible version from System.Collections.Generic.

Also if you’re using Visual Studio why are you even posting this and not making your own templates for different things

Because people often create new scripts via the ‘Assets->Create’ menu in Unity, rather than via VS?

I see you missed my point
Besides being able to edit the script template that was mentioned before

Also useful to get rid of the ultra-annoying “You are using two different carriage return types” error message. Changing those files is the first thing I do every time I upgrade Unity.

Apparently so. What was your point?