Ashwani K
Ashwani K

Reputation: 8000

Get current unity3d version

I am writing a build utility function which generates asset bundles. I have implemented incremental building of assets. I want to ensure that when ever there is update in Unity3d version I want to ensure to build all the asset bundles again. Can anybody tell me how to get current version of Unity3d using script (C#/Javascript). Thanks

Upvotes: 3

Views: 1932

Answers (1)

CC Inc
CC Inc

Reputation: 5938

It seems there are a few ways to do this.

First way is to use the preprocessor definition's to check what version you have. I don't think this would be a solution to your problem, neverless, you use them like this:

// Specific version define including the minor revision
#if UNITY_2_6_0
// Use Unity 2.6.0 specific feature
#endif

// Specific version define not including the minor revision
#if UNITY_2_6
// Use Unity 2.6.x specific feature
#endif

More helpful to your situation would be to use the GetFullUnityVersion function or the Application.unityVersion variable.

using UnityEditorInternal;
...
DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, 0);
Debug.Log(
"Unity version = " + Application.unityVersion + "\n" +
"Full Unity version = " + InternalEditorUtility.GetFullUnityVersion() + "\n" +
"Version date = " + dt.AddSeconds(InternalEditorUtility.GetUnityVersionDate()));

You could store the current version in a file, and every time, check if the version is the same. If it isn't the same, you will have to rebuild the asset bundles.

Hope it helps!

Upvotes: 8

Related Questions