-
Notifications
You must be signed in to change notification settings - Fork 358
/
Copy pathExecutionEnvironment.cs
102 lines (90 loc) · 3.42 KB
/
ExecutionEnvironment.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// <copyright file="ExecutionEnvironment.cs" company="Google Inc.">
// Copyright (C) 2018 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
using System;
using System.Globalization;
using UnityEngine;
namespace Google {
/// <summary>
/// Class that describes Unity's execution state.
/// </summary>
internal class ExecutionEnvironment {
/// <summary>
/// Cached lower case CommandLine
/// </summary>
private static string Cached_Environment_CommandLine_Lower = null;
/// <summary>
/// Get/Set cached lower case CommandLine
/// </summary>
public static string Environment_CommandLine_Lower {
get {
if (Cached_Environment_CommandLine_Lower == null) {
Cached_Environment_CommandLine_Lower = Environment.CommandLine.ToLower();
}
return Cached_Environment_CommandLine_Lower;
}
}
/// <summary>
/// Whether the editor was started in batch mode.
/// </summary>
public static bool InBatchMode {
get { return Environment_CommandLine_Lower.Contains("-batchmode"); }
}
/// <summary>
/// Whether the editor was started with a method to executed.
/// </summary>
public static bool ExecuteMethodEnabled {
get { return Environment_CommandLine_Lower.Contains("-executemethod"); }
}
/// <summary>
/// Whether the UI should be treated as interactive.
/// </summary>
internal static bool InteractiveMode {
get {
return !(Environment_CommandLine_Lower.Contains("-gvh_noninteractive") ||
ExecutionEnvironment.InBatchMode);
}
}
/// <summary>
/// If the Unity version can't be parsed, return a safe-ish version number.
/// </summary>
private const float DEFAULT_UNITY_VERSION_MAJOR_MINOR = 5.4f;
// Cached Unity version.
private static float unityVersionMajorMinor = -1.0f;
/// <summary>
/// Returns the major/minor version of the unity environment we are running in
/// as a float so it can be compared numerically.
/// If the default
/// </summary>
public static float VersionMajorMinor {
get {
if (unityVersionMajorMinor >= 0.0f) return unityVersionMajorMinor;
float result = DEFAULT_UNITY_VERSION_MAJOR_MINOR;
string version = Application.unityVersion;
if (!string.IsNullOrEmpty(version)) {
int dotIndex = version.IndexOf('.');
if (dotIndex > 0 && version.Length > dotIndex + 1) {
if (!float.TryParse(version.Substring(0, dotIndex + 2), NumberStyles.Any,
CultureInfo.InvariantCulture, out result)) {
result = DEFAULT_UNITY_VERSION_MAJOR_MINOR;
}
}
}
unityVersionMajorMinor = result;
return result;
}
}
}
}