Skip to content

Commit

Permalink
Build Version is now optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuan Liu committed Nov 13, 2017
1 parent c81b2f8 commit cf7dbef
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions Utils/BuildVersion.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if UNITY_EDITOR
#if UNITY_EDITOR && ENABLE_BUILD_VERSION
using UnityEditor;
using UnityEditor.Build;
#endif
Expand All @@ -8,35 +8,30 @@ namespace DUCK.Utils
{
public class BuildVersion : ScriptableObject
{
internal const string AssetPath = "BuildVersion";
internal const string ASSET_NAME = "BuildVersion";

public string DateStamp = "debug/Editor";
public string dateStamp = "debug/Editor";

#if UNITY_EDITOR
#if UNITY_EDITOR && ENABLE_BUILD_VERSION
public void UpdateForNewBuild()
{
DateStamp = System.DateTime.Now.ToString("dd/MM/yyyy");
dateStamp = System.DateTime.Now.ToString("dd/MM/yyyy");
}
#endif

private static BuildVersion buildVersion;
public static BuildVersion GetBuildVersion()
{
if (buildVersion == null)
{
buildVersion = (Resources.Load(AssetPath) as BuildVersion) ?? CreateInstance<BuildVersion>();
}

return buildVersion;
return buildVersion ?? (buildVersion = Resources.Load(ASSET_NAME) as BuildVersion ?? CreateInstance<BuildVersion>());
}

public override string ToString()
{
return DateStamp;
return dateStamp;
}
}

#if UNITY_EDITOR
#if UNITY_EDITOR && ENABLE_BUILD_VERSION
public class BuildVersionAutoIncrement : IPreprocessBuild
{
public int callbackOrder { get { return 0; } }
Expand All @@ -45,8 +40,8 @@ public void OnPreprocessBuild(BuildTarget target, string path)
{
const string root = "Assets";
const string folder = "Resources";
const string folderPath = root + "/" + folder + "/";
const string fullPath = folderPath + BuildVersion.AssetPath + ".asset";
const string folderPath = root + "/" + folder;
const string fullPath = folderPath + "/" + BuildVersion.ASSET_NAME + ".asset";

var buildVersion = ScriptableObject.CreateInstance<BuildVersion>();
buildVersion.UpdateForNewBuild();
Expand Down

0 comments on commit cf7dbef

Please sign in to comment.