public void OnDestroy() { Google2uGUIUtil.Save(); InstanceData.AccountWorkbooks.Clear(); InstanceData.Service = null; EditorApplication.update -= Update; var ed = GetWindow <Google2uEditor>(); if (ed != null) { ed.Close(); } var help = GetWindow <Google2uDocs>(); if (help != null) { help.Close(); } }
// Update is called once per frame private void Update() { if (Instance == null) { Init(); } var notification = PopNotification(); if (!string.IsNullOrEmpty(notification)) { Debug.Log(notification); ShowNotification(new GUIContent(notification)); } if (!string.IsNullOrEmpty(UpdateMessage)) { Debug.Log(UpdateMessage); UpdateMessage = string.Empty; } if ((DateTime.Now - LastEllipses).Milliseconds > 500) { LastEllipses = DateTime.Now; EllipsesCount += 1; if (EllipsesCount > 5) { EllipsesCount = 2; } Ellipses = string.Empty; for (var i = 0; i < EllipsesCount; ++i) { Ellipses += "."; } Repaint(); } // Detect Skin Changes var oldUseDarkSkin = UseDarkSkin; if (EditorGUIUtility.isProSkin) { UseDarkSkin = true; if (oldUseDarkSkin != UseDarkSkin) { LoadStyles(); } } if (IsDirty) { Google2uGUIUtil.Save(); IsDirty = false; } // Prevent Google2u from doing anything while in play mode if (EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isCompiling) { return; } if ((DateTime.Now - LastCheckedRSS).Hours > 0) { LastCheckedRSS = DateTime.Now; var t = new Thread(CheckForService); t.Start(); } if (InstanceData.Commands.Contains(GFCommand.DoLogout)) { InstanceData.Commands.Remove(GFCommand.DoLogout); var t = new Thread(DoLogout) { Name = "DoLogout" }; t.Start(InstanceData); } if (InstanceData.Commands.Contains(GFCommand.RetrieveWorkbooks)) { InstanceData.Commands.Remove(GFCommand.RetrieveWorkbooks); InstanceData.Commands.Add(GFCommand.WaitForRetrievingWorkbooks); InstanceData.AccountWorkbooks.Clear(); var t = new Thread(DoWorkbookQuery) { Name = "RetrieveWorkbooks" }; t.Start(InstanceData); } if (InstanceData.Commands.Contains(GFCommand.RetrieveManualWorkbooks)) { InstanceData.Commands.Remove(GFCommand.RetrieveManualWorkbooks); InstanceData.Commands.Add(GFCommand.WaitForRetrievingManualWorkbooks); var t = new Thread(DoManualWorkbookRetrieval) { Name = "ManualWorkbookRetrieval" }; t.Start(InstanceData); } if (InstanceData.Commands.Contains(GFCommand.ManualWorkbooksRetrievalComplete)) { InstanceData.Commands.Remove(GFCommand.ManualWorkbooksRetrievalComplete); var manualWorkbooksString = InstanceData.ManualWorkbooks.Aggregate(string.Empty, (in_current, in_wb) => in_current + (in_wb.WorkbookUrl + "|")); Google2uGUIUtil.SetString(InstanceData.ProjectPath + "_ManualWorkbookCache", manualWorkbooksString); } if (InstanceData.Commands.Contains(GFCommand.DoUpload)) { InstanceData.Commands.Remove(GFCommand.DoUpload); InstanceData.Commands.Add(GFCommand.WaitingForUpload); var t = new Thread(DoWorkbookUpload) { Name = "WorkbookUpload" }; t.Start(InstanceData); } if (InstanceData.Commands.Contains(GFCommand.UploadComplete)) { InstanceData.Commands.Remove(GFCommand.UploadComplete); InstanceData.WorkbookUploadProgress = 0; InstanceData.AccountWorkbooks.Clear(); InstanceData.Commands.Add(GFCommand.RetrieveWorkbooks); } foreach (var Google2uSpreadsheet in InstanceData.AccountWorkbooksDisplay) { Google2uSpreadsheet.Update(); } foreach (var Google2uSpreadsheet in InstanceData.ManualWorkbooksDisplay) { Google2uSpreadsheet.Update(); } if (ObjDbExport != null && ObjDbExport.Count > 0) { var dbInfo = ObjDbExport[0]; if (dbInfo == null) { ObjDbExport.RemoveAt(0); return; } if ((DateTime.Now - dbInfo.LastAttempt).TotalSeconds < 2) { return; } if (dbInfo.ReloadedAssets == false) { AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); dbInfo.ReloadedAssets = true; return; } dbInfo.LastAttempt = DateTime.Now; Component comp = null; var myAssetPath = string.Empty; Debug.Log("Looking for Database Script: " + dbInfo.ScriptName); var findAssetArray = AssetDatabase.FindAssets(dbInfo.ScriptName); if (findAssetArray.Length > 0) { foreach (var s in findAssetArray) { var mypath = AssetDatabase.GUIDToAssetPath(s); if (mypath.EndsWith(".cs")) { myAssetPath = mypath; Debug.Log("Found Database Script at: " + mypath); } } var myType = GetAssemblyType("Google2u." + dbInfo.ScriptName); Debug.Log(dbInfo.ScriptName + ": GetAssemblyType returns " + myType); if (myType != null) { var go = GameObject.Find(dbInfo.ObjectName) ?? new GameObject(dbInfo.ObjectName); var toDestroy = go.GetComponent(dbInfo.ScriptName); if (toDestroy != null) { DestroyImmediate(toDestroy); } #if UNITY_5 comp = go.AddComponent(myType); #else comp = go.AddComponent(dbInfo.ScriptName); #endif } } if (comp == null) { if (!string.IsNullOrEmpty(myAssetPath)) { Debug.Log("Attempting to compile: " + myAssetPath); AssetDatabase.ImportAsset(myAssetPath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate); } if (_ImportTryCount < 5) { _ImportTryCount++; return; } Debug.LogError("Could not add Google2u component base " + dbInfo.ScriptName); ObjDbExport.Clear(); _ImportTryCount = 0; return; } _ImportTryCount = 0; Debug.Log("Database Script Attached!"); ObjDbExport.Remove(dbInfo); var rowInputs = new List <string>(); List <Google2uCell> colHeaders = null; var currow = 0; foreach (var row in dbInfo.Data.Rows) { if (currow == 0) { colHeaders = row.Cells; currow++; continue; } // if types in first row if (dbInfo.Data.UseTypeRow && currow == 1) { currow++; continue; } var rowType = row[0].GetTypeFromValue(); var rowHeader = row[0].CellValueString; if (string.IsNullOrEmpty(rowHeader)) // if this header is empty { if (dbInfo.CullEmptyRows) { break; } currow++; continue; } if (rowType == SupportedType.Void || rowHeader.Equals("void", StringComparison.InvariantCultureIgnoreCase)) // if this cell is void, then skip the row completely { currow++; continue; } var curCol = 0; foreach (var cell in row.Cells) { if (cell.MyType == SupportedType.Void || dbInfo.Data.Rows[0][curCol].CellValueString.Equals("void", StringComparison.InvariantCultureIgnoreCase) || dbInfo.Data.Rows[0][curCol].CellValueString.Equals("ignore", StringComparison.InvariantCultureIgnoreCase)) { curCol++; continue; } if (dbInfo.CullEmptyCols && colHeaders[curCol].MyType == SupportedType.Void) { break; } rowInputs.Add(cell.CellValueString); curCol++; } (comp as Google2uComponentBase).AddRowGeneric(rowInputs); rowInputs.Clear(); currow++; } } }
// Update is called once per frame private void Update() { if (Instance == null) { Init(); } var notification = PopNotification(); if (!string.IsNullOrEmpty(notification)) { Debug.Log(notification); ShowNotification(new GUIContent(notification)); } if (!string.IsNullOrEmpty(UpdateMessage)) { Debug.Log(UpdateMessage); UpdateMessage = string.Empty; } if ((DateTime.Now - LastEllipses).Milliseconds > 500) { LastEllipses = DateTime.Now; EllipsesCount += 1; if (EllipsesCount > 5) { EllipsesCount = 2; } Ellipses = string.Empty; for (var i = 0; i < EllipsesCount; ++i) { Ellipses += "."; } Repaint(); } // Detect Skin Changes var oldUseDarkSkin = UseDarkSkin; if (EditorGUIUtility.isProSkin) { UseDarkSkin = true; if (oldUseDarkSkin != UseDarkSkin) { LoadStyles(); } } if (IsDirty) { Google2uGUIUtil.Save(); IsDirty = false; } // Prevent Google2u from doing anything while in play mode if (EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isCompiling) { return; } if ((DateTime.Now - LastCheckedRSS).Hours > 0) { LastCheckedRSS = DateTime.Now; var t = new Thread(CheckForService); t.Start(); } if (InstanceData.Commands.Contains(GFCommand.AssetDatabaseRefresh)) { InstanceData.Commands.Remove(GFCommand.AssetDatabaseRefresh); AssetDatabase.Refresh(); } if (InstanceData.Commands.Contains(GFCommand.DoLogout)) { InstanceData.Commands.Remove(GFCommand.DoLogout); var t = new Thread(DoLogout) { Name = "DoLogout" }; t.Start(InstanceData); } if (InstanceData.Commands.Contains(GFCommand.RetrieveWorkbooks)) { InstanceData.Commands.Remove(GFCommand.RetrieveWorkbooks); InstanceData.Commands.Add(GFCommand.WaitForRetrievingWorkbooks); InstanceData.AccountWorkbooks.Clear(); var t = new Thread(DoWorkbookQuery) { Name = "RetrieveWorkbooks" }; t.Start(InstanceData); } if (InstanceData.Commands.Contains(GFCommand.RetrieveManualWorkbooks)) { InstanceData.Commands.Remove(GFCommand.RetrieveManualWorkbooks); InstanceData.Commands.Add(GFCommand.WaitForRetrievingManualWorkbooks); var t = new Thread(DoManualWorkbookRetrieval) { Name = "ManualWorkbookRetrieval" }; t.Start(InstanceData); } if (InstanceData.Commands.Contains(GFCommand.ManualWorkbooksRetrievalComplete)) { InstanceData.Commands.Remove(GFCommand.ManualWorkbooksRetrievalComplete); var manualWorkbooksString = InstanceData.ManualWorkbooks.Aggregate(string.Empty, (in_current, in_wb) => in_current + (in_wb.WorkbookUrl + "|")); Google2uGUIUtil.SetString(InstanceData.ProjectPath + "_ManualWorkbookCache", manualWorkbooksString); } if (InstanceData.Commands.Contains(GFCommand.DoUpload)) { InstanceData.Commands.Remove(GFCommand.DoUpload); InstanceData.Commands.Add(GFCommand.WaitingForUpload); var t = new Thread(DoWorkbookUpload) { Name = "WorkbookUpload" }; t.Start(InstanceData); } if (InstanceData.Commands.Contains(GFCommand.UploadComplete)) { InstanceData.Commands.Remove(GFCommand.UploadComplete); InstanceData.WorkbookUploadProgress = 0; InstanceData.AccountWorkbooks.Clear(); InstanceData.Commands.Add(GFCommand.RetrieveWorkbooks); } foreach (var Google2uSpreadsheet in InstanceData.AccountWorkbooksDisplay) { Google2uSpreadsheet.Update(); } foreach (var Google2uSpreadsheet in InstanceData.ManualWorkbooksDisplay) { Google2uSpreadsheet.Update(); } if (ObjDbExport != null && ObjDbExport.Count > 0) { var dbInfo = ObjDbExport[0]; if (dbInfo == null) { ObjDbExport.RemoveAt(0); return; } if ((DateTime.Now - dbInfo.LastAttempt).TotalSeconds < 5) { return; } if (dbInfo.ReloadedAssets == false) { AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); dbInfo.ReloadedAssets = true; return; } dbInfo.LastAttempt = DateTime.Now; Component comp = null; var myAssetPath = string.Empty; Debug.Log("Looking for Database Script: " + dbInfo.ScriptName); var findAssetArray = AssetDatabase.FindAssets(dbInfo.ScriptName); if (findAssetArray.Length > 0) { foreach (var s in findAssetArray) { var mypath = AssetDatabase.GUIDToAssetPath(s); if (mypath.EndsWith(".cs")) { myAssetPath = mypath; Debug.Log("Found Database Script at: " + mypath); } } var myType = GetAssemblyType("Google2u." + dbInfo.ScriptName); Debug.Log(dbInfo.ScriptName + ": GetAssemblyType returns " + myType); if (myType != null) { var go = GameObject.Find(dbInfo.ObjectName) ?? new GameObject(dbInfo.ObjectName); var toDestroy = go.GetComponent(dbInfo.ScriptName); if (toDestroy != null) { DestroyImmediate(toDestroy); } #if UNITY_5_6_OR_NEWER comp = go.AddComponent(myType); #else comp = go.AddComponent(dbInfo.ScriptName); #endif } } if (comp == null) { if (!string.IsNullOrEmpty(myAssetPath)) { Debug.Log("Attempting to compile: " + myAssetPath); AssetDatabase.ImportAsset(myAssetPath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate); } if (_ImportTryCount < 5) { _ImportTryCount++; return; } Debug.LogError("Could not add Google2u component base " + dbInfo.ScriptName); ObjDbExport.Clear(); _ImportTryCount = 0; return; } _ImportTryCount = 0; Debug.Log("Database Script Attached!"); ObjDbExport.Remove(dbInfo); var tmpFilePath = dbInfo.DataLocation; using (var fs = File.Open(tmpFilePath, FileMode.Open, FileAccess.Read)) { var bin = new BinaryFormatter(); var binData = (List <List <string> >)bin.Deserialize(fs); foreach (var binDataRow in binData) { (comp as Google2uComponentBase).AddRowGeneric(binDataRow); } } try { File.Delete(tmpFilePath); } catch (Exception ex) { Debug.Log("G2U is unable to delete the temporary file: " + tmpFilePath + " - " + ex.Message); } } }