Sometimes it is useful for a game to display version information, or a revision number such as is assigned by version control or continuous integration solution. What's a good way to do this for a Unity game?
The usual way how this is done is by having keywords which are expanded by the version control on checkin. You can then use that keyword in a string in your game and simply display that.
Now, as far as I know, Asset Server doesn't have such keywords (that would be a feature-request ;-) ). Examples of keywords used by other version control systems:
Of course, you might want to be doing some string-cleanup to remove the "cryptic" parts of the version control keywords.
Personally, I prefer to use labels I manually assign for releases (you could do that in a property in one of your "core management" prefabs that you can easily change in the Unity editor and that is accessible from where ever you have the GUI code to display that information). Usually, that creates more meaningful information for actual users and seems like a small extra-step to take while creating my builds. However, using the automatic assignment of dates through version control might be helpful in "hot development" (when you push out releases every few days). Keep in mind, though: That value will only change when you actually made a change to that file.
Finally, there's yet another solution: If you have a custom build-system (which can be implemented Unity's batch mode features), you might do your own replacement in the code during the build; and you'd increase the number for each build (or include the build-date, or whichever information you find useful). You could also keep that number / text in a little text-file that your game-code can access (might be easier to set up than doing the string replacement in your code but adds a little complexity in your game-code).
In my opinion, that's the optimal solution (meaningful values + no manual work involved once it's set up + totally customizable) - but also the most complex one to set up. But when you know how to set up a build-system, that should be one of your smaller concerns ;-)
EDIT: updated code to make copy of string before returning to C#
Okay here it is:
To be able to show date/time of a build (useful to make sure your testers are using the right version) I made a very simple plugin that adds two functions to retrieve date and time string of the build process. To use it, add the Test.h and Test.mm to the xcode project and JBuildInfo.cs to your unity project. Shouldn't be hard to figure out how to use this I guess...
Here's a simple solution that uses the C# assembly version.
Specify the AssemblyVersion attribute like so:
And you can retrieve a formatted version number like so:
This prints out the Version in Major.Minor.Build.Revision format (e.g. "1.0.5557.38042"). The Build number is the number of days since Jan. 1, 2000. The Revision number is half the number of seconds since 12:00 AM that day.
If you want, you can use this information to print out a human-readable timestamp (e.g. "3/20/2015 9:08:04 PM"):
This solution was adapted from some other solutions:
You can use a compile-time language to create a string. At least I know that Boo has this.
Unity actually opens every scene during the build process: This can be exploited as follows: