public static void RemovePath(int i) { UnityInstalls.LazyInitialize(); UnityInstalls.installPaths.RemoveAt(i); UnityInstalls.UpdateUnityInstalls(); UnityInstalls.Save(); }
protected virtual void OnGUI() { EditorGUILayout.LabelField("Unity Installations Paths"); if (UnityInstalls.InstallPathsCount == 0 || UnityInstalls.UnityInstallsCount == 0) { EditorGUILayout.HelpBox("Your Unity folders must end by their version. (e.g. \"Unity 4.2.1f3\", \"Unity5.1.3p4\")", MessageType.Info); } foreach (var pair in UnityInstalls.EachPath) { using (new EditorGUILayout.HorizontalScope()) { EditorGUI.BeginChangeCheck(); string path = EditorGUILayout.TextField(pair.Value); if (EditorGUI.EndChangeCheck() == true) { UnityInstalls.SetPath(pair.Key, path); } if (GUILayout.Button("Browse", GUILayout.Width(60F)) == true) { path = pair.Value; if (string.IsNullOrEmpty(path) == false) { path = Path.GetDirectoryName(path); } string projectPath = EditorUtility.OpenFolderPanel("Folder with Unity installations ending by A.B.C[abfpx]NN", path, string.Empty); if (string.IsNullOrEmpty(projectPath) == false) { UnityInstalls.SetPath(pair.Key, projectPath); GUI.FocusControl(null); } } if (GUILayout.Button("X", GUILayout.Width(16F)) == true) { UnityInstalls.RemovePath(pair.Key); return; } } } if (GUILayout.Button("Add installation path") == true) { UnityInstalls.AddPath(); } using (var scroll = new EditorGUILayout.ScrollViewScope(this.scrollPosition)) { this.scrollPosition = scroll.scrollPosition; foreach (var pair in UnityInstalls.EachInstall) { EditorGUILayout.LabelField(pair.Value + " [" + pair.Key + "]"); } } }
/// <summary>Returns the path of the Unity installation corresponding to the version. Returns null if none is available.</summary> /// <param name="unityVersion"></param> /// <returns></returns> public static string GetUnityExecutable(string unityVersion) { UnityInstalls.LazyInitialize(); string path; if (UnityInstalls.unityInstalls.TryGetValue(unityVersion, out path) == true) { return(Path.Combine(path, @"Editor\Unity.exe")); } return(null); }
public static void SetPath(int i, string path) { UnityInstalls.LazyInitialize(); if (i >= 0 && i < UnityInstalls.installPaths.Count) { UnityInstalls.installPaths[i] = path; } UnityInstalls.UpdateUnityInstalls(); UnityInstalls.Save(); }
private static void UpdateUnityInstalls() { UnityInstalls.unityInstalls.Clear(); for (int i = 0, max = UnityInstalls.installPaths.Count; i < max; i++) { UnityInstalls.ExtractUnityInstalls(UnityInstalls.installPaths[i]); } if (UnityInstalls.UnityInstallsChanged != null) { UnityInstalls.UnityInstallsChanged(); } }
public static void AddPath(string path = null) { UnityInstalls.LazyInitialize(); if (path == null) { if (UnityInstalls.installPaths.Count > 0) { UnityInstalls.installPaths.Add(UnityInstalls.installPaths[UnityInstalls.installPaths.Count - 1]); } else { UnityInstalls.installPaths.Add(string.Empty); } UnityInstalls.Save(); } else if (UnityInstalls.installPaths.Contains(path) == false) { UnityInstalls.installPaths.Add(path); UnityInstalls.UpdateUnityInstalls(); UnityInstalls.Save(); } }
private static void LazyInitialize() { if (UnityInstalls.installPaths == null) { try { string rawPaths = EditorPrefs.GetString(UnityInstalls.UnityInstallPathsPrefKey); if (string.IsNullOrEmpty(rawPaths) == false) { string[] paths = rawPaths.Split(UnityInstalls.Separator); if (paths.Length > 0) { UnityInstalls.installPaths = new List <string>(paths); UnityInstalls.unityInstalls = new Dictionary <string, string>(); UnityInstalls.UpdateUnityInstalls(); } } } catch (Exception ex) { Debug.LogException(ex); } finally { if (UnityInstalls.installPaths == null) { UnityInstalls.installPaths = new List <string>(); } if (UnityInstalls.unityInstalls == null) { UnityInstalls.unityInstalls = new Dictionary <string, string>(); } } } }