When creating a new file in Unity 4.6 it gives default headers as:
using UnityEngine;
using System.Collections;
which I always change to:
using UnityEngine;
using System.Collections.Generic;
any reason why this is so? Just wondering…
When creating a new file in Unity 4.6 it gives default headers as:
using UnityEngine;
using System.Collections;
which I always change to:
using UnityEngine;
using System.Collections.Generic;
any reason why this is so? Just wondering…
I believe System.Collections is there so you don’t have to do additional imports to write a Coroutine (which uses IEnumerators from System.Collections).
You can modify the default script. It’s placed somewhere (google it, I don’t remember) in your Unity install folder. You can replace it with whatever.
I can’t find the post now, but it had an example of an error that occurred in a script that had
using System.Collections.Generic; without also having using System.Collections;
System.Collections contains IEnumerator, which is needed for coroutines to function.
System.Collection.Generic really doesn’t contain anything required for basic Unity functionality.
Yep, what those guys said. But yes, the first thing I do when I upgrade Unity is reinstall my customized C# script template. It’s called “81-C# Script-NewBehaviourScript.cs”, and where it’s found varies with platform (as @Baste said, google it). For what it’s worth, here’s what mine looks like:
using UnityEngine;
using UnityEngine.Events;
using System.Collections.Generic;
public class #SCRIPTNAME# : MonoBehaviour {
#region Public Properties
#endregion
//--------------------------------------------------------------------------------
#region Private Properties
#endregion
//--------------------------------------------------------------------------------
#region MonoBehaviour Events
void Start() {
}
void Update() {
}
#endregion
//--------------------------------------------------------------------------------
#region Public Methods
#endregion
//--------------------------------------------------------------------------------
#region Private Methods
#endregion
}
I use UnityEngine.Events and generic containers way more often than I use Coroutines, so I adjusted the using directives accordingly. And I like the defined regions. Sometimes they are overkill for a very trivial script, but I find it easier to cut them out when not needed than to add them in when they are.
Do you/anyone know if Unity cares about any other magical strings than #SCRIPTNAME#?
There is #NAME# which seems to do the exact same thing as #SCRIPTNAME#. #SCRIPTNAME_LOWER# results in a camel case name.