Trick to display build date
I have seen a few tricks to display the build date. Here is mine.
I write a c# script that writes a c# script. Try not to get schizophrenic while doing so. I add an empty gameObject, let's call ist BuildDate, and add two scripts:
BuildDateAutomatic.cs
BuildDateController.cs
in the beginning, BuilddateAutomatic is a placeholder for the script to be written automatically. Its initial content is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BuildDateAutomatic : MonoBehaviour
{
public string GetFileInfo()
{
return ("Hello World");
}
}
Now comes the script to write the contents of this file and to display the build date.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
public class BuildDateController : MonoBehaviour
{
public BuildDateAutomatic BuildDateAutomatic;
public Text buildDateText;
// Start is called before the first frame update
void Start()
{
if (Application.isEditor)
{
string filePath;
byte[] fileContent;
string fileString;
string dateString;
dateString = "\"" + System.DateTime.Now.ToString("yyyy-MM-dd") + "\"";
fileString = @"/*** THIS FILE IST GENERATED AUTOMATICALLY - DO NOT EDIT! ***/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BuildDateAutomatic : MonoBehaviour
{
public string GetFileInfo()
{
return (" + dateString + @");
}
}";
filePath = "Assets/BuildDateAutomatic.cs";
fileContent = System.Text.Encoding.UTF8.GetBytes(fileString);
File.WriteAllBytes(filePath, fileContent);
}
//now, let's put the build date on the screen
buildDateText.text = BuildDateAutomatic.GetFileInfo();
} // start
}
if (Application.isEditor) means that the file is written only when the project runs in the editor. Therefore not the real build date is displayed, but the date of the latest time you did a test-run.
Apart from the build date you can write whatever you like.
It may be a dirty trick, but it works for me. Hopefully you like it and it works for you as well.
Your answer
Follow this Question
Related Questions
Version control of thirdparty assets 0 Answers
Unity smart merge + GIT on MAC OSX 0 Answers
Occlusion Culling Data imported from another PC not working 0 Answers