private void AsyncDeployAll() { for (int i = 0; i < ProfilesManager.Profile.projects.Count; i++) { try { if (Directory.Exists(ProfilesManager.Profile.projects[i]) == true) { string unityVersion = Utility.GetUnityVersion(ProfilesManager.Profile.projects[i]); if (string.IsNullOrEmpty(unityVersion) == false) { string unityExe = NGUnityDetectorWindow.GetUnityExecutable(this.unityInstalls, unityVersion); if (File.Exists(unityExe) == true) { this.AsyncDeploy(ProfilesManager.Profile.projects[i]); } } } } catch (Exception ex) { InternalNGDebug.LogException("Deployment at \"" + ProfilesManager.Profile.projects[i] + "\" failed.", ex); } } }
public static void StartBackgroundTask(IEnumerator update, Action end = null) { EditorApplication.CallbackFunction closureCallback = null; closureCallback = () => { try { if (update.MoveNext() == false) { if (end != null) { end(); } EditorApplication.update -= closureCallback; } } catch (Exception ex) { if (end != null) { end(); } InternalNGDebug.LogException(ex); EditorApplication.update -= closureCallback; } }; EditorApplication.update += closureCallback; }
static ProfilesManager() { EditorApplication.delayCall += () => { try { string profilesPref = EditorPrefs.GetString(ProfilesManager.ProfilesPrefKey); if (string.IsNullOrEmpty(profilesPref) == false) { ProfilesManager.profiles = Utility.DeserializeField <List <Profile> >(Convert.FromBase64String(profilesPref)); } } catch (Exception ex) { InternalNGDebug.LogException(ex); } if (ProfilesManager.profiles == null) { ProfilesManager.profiles = new List <Profile>(); } if (ProfilesManager.profiles.Count == 0) { ProfilesManager.profiles.Add(new Profile() { name = "Profile 1" }); } ProfilesManager.current = Mathf.Clamp(EditorPrefs.GetInt(ProfilesManager.CurrentProfilePrefKey), 0, ProfilesManager.profiles.Count - 1); ProfilesManager.Profile.outputPath = ProfilesManager.Profile.outputPath ?? string.Empty; ProfilesManager.Profile.outputEditorPath = ProfilesManager.Profile.outputEditorPath ?? string.Empty; if (ProfilesManager.SetProfile != null) { ProfilesManager.SetProfile(); } InternalEditorUtility.RepaintAllViews(); }; }
public override void Load(object instance, FieldInfo field, string prefix) { IList list = field.GetValue(instance) as IList; int count = NGEditorPrefs.GetInt(prefix + instance.GetType().FullName + '.' + field.Name, -1); Type subType = Utility.GetArraySubType(field.FieldType); if (count != -1) { list.Clear(); prefix += instance.GetType().FullName + '.' + field.Name + '.'; try { for (int i = 0; i < count; i++) { object element = null; string v = NGEditorPrefs.GetString(prefix + i, null); if (v != null) { element = Utility.DeserializeField <object>(Convert.FromBase64String(v)); } else if (subType.IsValueType == true) { element = Activator.CreateInstance(subType); } list.Add(element); } field.SetValue(instance, list); } catch (Exception ex) { InternalNGDebug.LogException(prefix, ex); } } }
private bool CheckProjectCompile(string projectPath) { lock (this.deployingProjects) { this.deployingProjects.Add(projectPath, 101); } try { string unityVersion = Utility.GetUnityVersion(projectPath); if (string.IsNullOrEmpty(unityVersion) == true) { return(false); } string unityExe = NGUnityDetectorWindow.GetUnityExecutable(this.unityInstalls, unityVersion); if (File.Exists(unityExe) == false) { return(false); } string token = Guid.NewGuid().ToString(); int time; string tempLogPath = Path.GetTempPath() + token + ".log"; lock (this.compileLock) { time = Environment.TickCount; lock (this.deployingProjects) { this.deployingProjects[projectPath] = 102; } InternalNGDebug.Log("Compiler Token " + token + " for \"" + projectPath + '"'); Process unityProcess = new Process(); unityProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; unityProcess.StartInfo.CreateNoWindow = true; unityProcess.StartInfo.UseShellExecute = false; unityProcess.StartInfo.FileName = unityExe; unityProcess.StartInfo.Arguments = "-nographics -batchmode -logFile \"" + tempLogPath + "\" -quit -projectPath \"" + projectPath + '"'; if (unityProcess.Start() == false) { InternalNGDebug.Log("Process Unity stopped with code " + unityProcess.ExitCode + "."); return(false); } unityProcess.WaitForExit(); if (unityProcess.ExitCode == 1) { for (int j = 0; j < this.unityProcessesDetected.Count; j++) { if (this.unityProcessesDetected[j].Contains(unityVersion) == true) { InternalNGDebug.LogWarning("Unity " + unityVersion + " is running, deployment can not compile the project."); return(false); } } InternalNGDebug.LogError("Unity " + unityVersion + " has aborted."); return(false); } } using (FileStream fs = File.Open(tempLogPath, FileMode.Open, FileAccess.Read, FileShare.Read)) using (BufferedStream bs = new BufferedStream(fs)) using (StreamReader sr = new StreamReader(bs)) { string line; while ((line = sr.ReadLine()) != null) { // Token spotted. if (line.Contains(token) == true) { bool hasCompiled = false; while ((line = sr.ReadLine()) != null) { if (line.Contains("- starting compile") == true) { hasCompiled = true; } // Check compilation result. if (line.Contains("compilationhadfailure") == true) { if (line.Contains("True") == true) { InternalNGDebug.LogWarning("Project \"" + projectPath + "\" did not compile correctly. (" + ((Environment.TickCount - time) / 1000F).ToString("#.##") + "s)"); } else { InternalNGDebug.LogWarning("Project \"" + projectPath + "\" compiled but have warnings. (" + ((Environment.TickCount - time) / 1000F).ToString("#.##") + "s)"); } // Stop at errors. while ((line = sr.ReadLine()) != null) { if (line.Contains("CompilerOutput:-stderr") == true) { break; } } while ((line = sr.ReadLine()) != null) { if (line.Length == 0) { continue; } if (line.Contains("EndCompilerOutput") == true) { break; } if (line[0] == '-') { continue; } if (line.Contains("): warning CS")) { Debug.LogWarning(line); } else { Debug.LogError(line); } } return(true); } } if (hasCompiled == true) { InternalNGDebug.Log("Project \"" + projectPath + "\" compiled. (" + ((Environment.TickCount - time) / 1000F).ToString("#.##") + "s)"); } else { InternalNGDebug.Log("Project \"" + projectPath + "\" has not changed. (" + ((Environment.TickCount - time) / 1000F).ToString("#.##") + "s)"); } return(true); } } } InternalNGDebug.LogWarning("Project \"" + projectPath + "\" did not found the token. (" + ((Environment.TickCount - time) / 1000F).ToString("#.##") + "s)"); return(true); } catch (Exception ex) { InternalNGDebug.LogException(ex); } finally { lock (this.deployingProjects) { this.deployingProjects.Remove(projectPath); } } return(false); }
private bool CopyPackage(string path) { lock (this.deployingProjects) { this.deployingProjects.Add(path, 0); } try { string unityVersion = Utility.GetUnityVersion(path); bool isEditorRooted = unityVersion.StartsWith("20") == false && unityVersion.CompareTo("5.2.2") < 0; string package = Path.Combine("Assets", ProfilesManager.Profile.packagePath); string fullPath = Path.Combine(path, package); if (package.StartsWith(@"Assets\Plugins") == false) { isEditorRooted = false; } if (Directory.Exists(fullPath) == true) { Directory.Delete(fullPath, true); } if (isEditorRooted == true) { string pathEditor = fullPath.Replace("Plugins", Path.Combine("Plugins", "Editor")); if (Directory.Exists(pathEditor) == true) { Directory.Delete(pathEditor, true); } } Directory.CreateDirectory(fullPath); string packagePath = "Assets/" + ProfilesManager.Profile.packagePath + "/"; for (int i = 0; i < this.exported.Count; i++) { string destination = Path.Combine(fullPath, this.exported[i].Remove(0, packagePath.Length)).Replace('\\', '/'); if (isEditorRooted == true) { int n = destination.IndexOf("/Editor/"); if (n != -1) { destination = destination.Remove(n, "/Editor/".Length - 1).Replace("Plugins/", "Plugins/Editor/"); } } Directory.CreateDirectory(Path.GetDirectoryName(destination)); File.Copy(this.exported[i], destination); if (ProfilesManager.Profile.deployMeta == true) { File.Copy(this.exported[i] + ".meta", destination + ".meta"); } lock (this.deployingProjects) { this.deployingProjects[path] = (int)((float)i / (float)this.exported.Count * 100F); } } InternalNGDebug.Log("Copy into \"" + fullPath + "\" completed." + (isEditorRooted == true ? " Unity < 5.2.2 detected, Editor files are correctly copied into Plugins/Editor." : "")); return(true); } catch (Exception ex) { InternalNGDebug.LogException("Deployment at \"" + path + "\" failed.", ex); } finally { lock (this.deployingProjects) { this.deployingProjects.Remove(path); } } return(false); }