public void SetOverrideObjectDatabaseGameObject(string in_sheetName, GameObject in_gameObject) { var sheetName = in_sheetName.Replace(",", string.Empty); var goName = string.Empty; if (in_gameObject != null) { goName = in_gameObject.name; } if (!_OverrideObjectDatabaseNames.ContainsKey(_Prefix + sheetName)) { _OverrideObjectDatabaseNames.Add(_Prefix + sheetName, goName); } _OverrideObjectDatabaseNames[_Prefix + sheetName] = goName; var namesString = string.Empty; var index = 0; foreach (var pair in _OverrideObjectDatabaseNames) { namesString += pair.Key + "|" + pair.Value; if (index < _OverrideObjectDatabaseNames.Count - 1) { namesString += ","; } index++; } Google2uGUIUtil.SetString(_Prefix + "OverrideObjectDatabaseNames", namesString); }
public static string PasswordInput(string in_label, string in_currentValue, string in_savedName, bool in_doStore) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(in_label + ": ", GUILayout.MaxWidth(MaxWidth)); var tmpvar = EditorGUILayout.PasswordField(in_currentValue); if (!string.IsNullOrEmpty(in_savedName)) { if (in_doStore) { if (tmpvar != in_currentValue) { Google2uGUIUtil.SetString(in_savedName, tmpvar); } } else { Google2uGUIUtil.SetString(in_savedName, string.Empty); } } EditorGUILayout.EndHorizontal(); return(tmpvar); }
public static string Google2uGenPath(string in_pathType) { var retPath = string.Empty; if (Google2uGUIUtil.GfuStrCmp(in_pathType, "Google2uGEN")) { retPath = Path.Combine(Instance.InstanceData.ProjectPath, "Google2uGen").Replace('\\', '/'); if (!Directory.Exists(retPath)) { Debug.Log("Generating: " + retPath); Directory.CreateDirectory(retPath); } } // Standard Assets else if (Google2uGUIUtil.GfuStrCmp(in_pathType, "OBJDB")) { { var Google2ugenPath = Google2uGenPath("Google2uGEN"); retPath = Path.Combine(Google2ugenPath, "ObjDB").Replace('\\', '/'); if (!Directory.Exists(retPath)) { Debug.Log("Generating: " + retPath); Directory.CreateDirectory(retPath); } } } else if (Google2uGUIUtil.GfuStrCmp(in_pathType, "OBJDBRESOURCES")) { { retPath = Google2uGUIUtil.GetString("g2uobjDBResourcesDirectory", retPath); if (!Directory.Exists(retPath)) { var objdbPath = Google2uGenPath("OBJDB"); retPath = Path.Combine(objdbPath, "Resources").Replace('\\', '/'); if (!Directory.Exists(retPath)) { Debug.Log("Generating: " + retPath); Directory.CreateDirectory(retPath); } Google2uGUIUtil.SetString("g2uobjDBResourcesDirectory", retPath); } } } else if (Google2uGUIUtil.GfuStrCmp(in_pathType, "OBJDBEDITOR")) { { retPath = Google2uGUIUtil.GetString("g2uobjDBEditorDirectory", retPath); if (!Directory.Exists(retPath)) { var objdbPath = Google2uGenPath("OBJDB"); retPath = Path.Combine(objdbPath, "Editor").Replace('\\', '/'); if (!Directory.Exists(retPath)) { Debug.Log("Generating: " + retPath); Directory.CreateDirectory(retPath); } Google2uGUIUtil.SetString("g2uobjDBEditorDirectory", retPath); } } } else if (Google2uGUIUtil.GfuStrCmp(in_pathType, "STATICDB")) { { var Google2ugenPath = Google2uGenPath("Google2uGEN"); retPath = Path.Combine(Google2ugenPath, "StaticDB").Replace('\\', '/'); if (!Directory.Exists(retPath)) { Debug.Log("Generating: " + retPath); Directory.CreateDirectory(retPath); } } } else if (Google2uGUIUtil.GfuStrCmp(in_pathType, "STATICDBRESOURCES")) { { retPath = Google2uGUIUtil.GetString("g2uStaticDBResourcesDirectory", retPath); if (Directory.Exists(retPath)) { return(retPath); } var staticdbPath = Google2uGenPath("STATICDB"); retPath = Path.Combine(staticdbPath, "Resources").Replace('\\', '/'); if (!Directory.Exists(retPath)) { Debug.Log("Generating: " + retPath); Directory.CreateDirectory(retPath); } Google2uGUIUtil.SetString("g2uStaticDBResourcesDirectory", retPath); } } else if (Google2uGUIUtil.GfuStrCmp(in_pathType, "JSON")) { { retPath = Google2uGUIUtil.GetString("g2ujsonDirectory", retPath); if (Directory.Exists(retPath)) { return(retPath); } var Google2ugenPath = Google2uGenPath("Google2uGEN"); retPath = Path.Combine(Google2ugenPath, "JSON").Replace('\\', '/'); if (!Directory.Exists(retPath)) { Debug.Log("Generating: " + retPath); Directory.CreateDirectory(retPath); } Google2uGUIUtil.SetString("g2ujsonDirectory", retPath); } } else if (Google2uGUIUtil.GfuStrCmp(in_pathType, "CSV")) { { retPath = Google2uGUIUtil.GetString("g2ucsvDirectory", retPath); if (Directory.Exists(retPath)) { return(retPath); } var Google2ugenPath = Google2uGenPath("Google2uGEN"); retPath = Path.Combine(Google2ugenPath, "CSV").Replace('\\', '/'); if (!Directory.Exists(retPath)) { Debug.Log("Generating: " + retPath); Directory.CreateDirectory(retPath); } Google2uGUIUtil.SetString("g2ucsvDirectory", retPath); } } else if (Google2uGUIUtil.GfuStrCmp(in_pathType, "XML")) { { retPath = Google2uGUIUtil.GetString("g2uxmlDirectory", retPath); if (Directory.Exists(retPath)) { return(retPath); } var Google2ugenPath = Google2uGenPath("Google2uGEN"); retPath = Path.Combine(Google2ugenPath, "XML").Replace('\\', '/'); if (!Directory.Exists(retPath)) { Debug.Log("Generating: " + retPath); Directory.CreateDirectory(retPath); } Google2uGUIUtil.SetString("g2uxmlDirectory", retPath); } } else if (Google2uGUIUtil.GfuStrCmp(in_pathType, "NGUI")) { { retPath = Google2uGUIUtil.GetString("g2unguiDirectory", retPath); if (Directory.Exists(retPath)) { return(retPath); } var Google2ugenPath = Google2uGenPath("Google2uGEN"); retPath = Path.Combine(Google2ugenPath, "NGUI").Replace('\\', '/'); if (!Directory.Exists(retPath)) { Debug.Log("Generating: " + retPath); Directory.CreateDirectory(retPath); } Google2uGUIUtil.SetString("g2unguiDirectory", retPath); } } else if (Google2uGUIUtil.GfuStrCmp(in_pathType, "PLAYMAKER")) { { retPath = Google2uGUIUtil.GetString("g2uplaymakerDirectory", retPath); if (Directory.Exists(retPath)) { return(retPath); } // attempt to find the playmaker actions directory // We already know that the playmaker dll exists, but we need to find the actual path var playmakerPaths = Directory.GetFiles(Application.dataPath, "PlayMaker.dll", SearchOption.AllDirectories); var playmakerPath = string.Empty; if (playmakerPaths.Length > 0) { // We are just going to use the first entry. If there is more than 1 entry, there are bigger issues var fileName = playmakerPaths[0]; var fileInfo = new FileInfo(fileName); playmakerPath = fileInfo.DirectoryName; } if (playmakerPath != string.Empty) { if (playmakerPath != null) { retPath = Path.Combine(playmakerPath, "Actions"); } if (Directory.Exists(retPath)) { // We have found the Playmaker Actions dir! Google2uGUIUtil.SetString("g2uplaymakerDirectory", retPath); } else { // The actions subdirectory doesn't exist? Rather than making it in the playmaker directory, // We will just use our Google2uGen path instead and let the user figure it out var Google2ugenPath = Google2uGenPath("Google2uGEN"); retPath = Path.Combine(Google2ugenPath, "PlayMaker").Replace('\\', '/'); if (!Directory.Exists(retPath)) { Directory.CreateDirectory(retPath); } Google2uGUIUtil.SetString("g2uplaymakerDirectory", retPath); } } } } return(retPath); }
// 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++; } } }
private void Init() { var lastChecked = Convert.ToDateTime(Google2uGUIUtil.GetString("Google2uLastCheckedForUpdate", Convert.ToString(DateTime.MinValue))); if ((DateTime.Now - lastChecked).Days >= 1) { Google2uGUIUtil.SetString("Google2uLastCheckedForUpdate", Convert.ToString(DateTime.Now)); var t = new Thread(CheckForUpdate); t.Start(); } ShowDocsAtStartup = Google2uGUIUtil.GetBool("ShowDocsAtStartup", ShowDocsAtStartup); if (ShowDocsAtStartup) { Google2uDocs.ShowWindow(MyGUILayout, LocalizationInfo); } ServicePointManager.ServerCertificateValidationCallback = Validator; OAuthToken = Google2uGUIUtil.GetString("OAuthToken", OAuthToken); RefreshToken = Google2uGUIUtil.GetString("RefreshToken", RefreshToken); RefreshTimeout = DateTime.ParseExact(Google2uGUIUtil.GetString("RefreshTimeout", RefreshTimeout.ToString("O")), "O", CultureInfo.InvariantCulture); if (InstanceData.Service == null && !string.IsNullOrEmpty(OAuthToken)) { SetupParameters(); _authParameters.AccessToken = OAuthToken; var requestFactory = new GOAuth2RequestFactory("structuredcontent", "Google2Unity", _authParameters); InstanceData.Service = new SpreadsheetsService("Google2Unity") { RequestFactory = requestFactory }; Thread.Sleep(100); if (!InstanceData.Commands.Contains(GFCommand.RetrieveWorkbooks)) { InstanceData.Commands.Add(GFCommand.RetrieveWorkbooks); } } // Close lingering editor windows var ed = GetWindow <Google2uEditor>(); if (ed != null) { ed.Close(); } if (ObjDbExport == null) { ObjDbExport = new List <Google2uObjDbExport>(); } Instance = this; }
// 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); } } }