Exemple #1
0
        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);
        }
Exemple #2
0
        public void OnEnable()
        {
            EditorApplication.update += Update;

            //Correct paths if necessary

            var projectPath = Application.dataPath;

            if (projectPath.EndsWith("/Assets"))
            {
                projectPath = projectPath.Remove(projectPath.Length - ("Assets".Length));
            }

            if (!File.Exists(projectPath + EditorAssets + "/Google2uAssets"))
            {
                var foundPath = string.Empty;
                if (Google2uGUIUtil.FindPathContaining("Google2uAssets", ref foundPath))
                {
                    foundPath = foundPath.Replace(projectPath, "");

                    if (foundPath.StartsWith("/"))
                    {
                        foundPath = foundPath.Remove(0, 1);
                    }

                    EditorAssets = foundPath;
                    Debug.Log("Located editor assets folder to '" + EditorAssets + "'");
                }
                else
                {
                    Debug.LogWarning("Could not locate editor assets folder\nGoogle2u");
                    return;
                }
            }

            GUISkin google2USkin;

            if (EditorGUIUtility.isProSkin)
            {
                google2USkin =
                    AssetDatabase.LoadAssetAtPath(EditorAssets + "/DarkSkin/Google2uDark.guiskin", typeof(GUISkin)) as
                    GUISkin;
            }
            else
            {
                google2USkin =
                    AssetDatabase.LoadAssetAtPath(EditorAssets + "/LightSkin/Google2uLight.guiskin", typeof(GUISkin))
                    as GUISkin;
            }


            HelpBoxHeader = google2USkin.FindStyle("HelpHeaderStyle");
            HelpBoxText   = google2USkin.FindStyle("HelpTextStyle");
        }
        public static void IntInput(string in_label, ref int in_currentValue, string in_savedName)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(in_label + ": ", GUILayout.MaxWidth(MaxWidth));
            var tmpvar = EditorGUILayout.IntField(in_currentValue);

            if (!string.IsNullOrEmpty(in_savedName) && tmpvar != in_currentValue)
            {
                Google2uGUIUtil.SetInt(in_savedName, tmpvar);
            }
            in_currentValue = tmpvar;
            EditorGUILayout.EndHorizontal();
        }
        public static void FloatInput(string in_label, ref float in_currentValue, string in_savedName)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(in_label + ": ", GUILayout.MaxWidth(MaxWidth));
            var tmpvar = EditorGUILayout.FloatField(in_currentValue);

            if (!string.IsNullOrEmpty(in_savedName) && Math.Abs(tmpvar - in_currentValue) > float.Epsilon)
            {
                Google2uGUIUtil.SetFloat(in_savedName, tmpvar);
            }
            in_currentValue = tmpvar;
            EditorGUILayout.EndHorizontal();
        }
        public static bool ToggleInput(string in_label, bool in_currentValue, string in_savedName)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(in_label + ": ", GUILayout.MaxWidth(MaxWidth));
            var tmpvar = EditorGUILayout.Toggle(in_currentValue);

            if (!string.IsNullOrEmpty(in_savedName) && tmpvar != in_currentValue)
            {
                Google2uGUIUtil.SetBool(in_savedName, tmpvar);
            }
            EditorGUILayout.EndHorizontal();
            return(tmpvar);
        }
        public bool DrawGUIList(EditorGUILayoutEx in_layout)
        {
            if (!_Initialized)
            {
                _Initialized        = true;
                UseTypeRow          = Google2uGUIUtil.GetBool(Prefix + "UseTypeRow", UseTypeRow);
                WorksheetExportType = Google2uGUIUtil.GetEnum(Prefix + "ExportType", WorksheetExportType);
            }

            var old = GUI.enabled;

            if (WorksheetQueryStatus != QueryStatus.Idle && RowsDisplay.Length == 0)
            {
                GUI.enabled = false;
            }


            var newExportType = WorksheetExportType;

            if (IsDataValid)
            {
                newExportType = (ExportType)EditorGUILayout.EnumPopup(WorksheetName, WorksheetExportType);
            }
            else if (WorksheetQueryStatus != QueryStatus.Idle)
            {
                EditorGUILayout.LabelField(WorksheetName,
                                           Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_QUERYING_CELLS) +
                                           Google2u.Ellipses);
            }
            else
            {
                var oldColor = GUI.color;
                if (GUI.GetNameOfFocusedControl() != WorksheetName + "Invalid")
                {
                    GUI.color = Color.red;
                }
                GUI.SetNextControlName(WorksheetName + "Invalid");
                newExportType = (ExportType)EditorGUILayout.EnumPopup(WorksheetName, WorksheetExportType);
                GUI.color     = oldColor;
            }

            if (newExportType != WorksheetExportType)
            {
                WorksheetExportType = Google2uGUIUtil.SetEnum(Prefix + "ExportType", newExportType);
            }

            GUI.enabled = old;

            return(WorksheetExportType != ExportType.DoNotExport);
        }
Exemple #7
0
        public void ShowFade(string in_label, string in_savedVar, bool in_isOuter, FadeOpenCallback[] in_callbacks)
        {
            var savedVar = Google2uGUIUtil.GetBool(in_savedVar, false);
            var fadeVar  = MyGUILayout.BeginFadeArea(savedVar, in_label, in_savedVar,
                                                     in_isOuter ? MyGUILayout.OuterBox : MyGUILayout.InnerBox,
                                                     in_isOuter ? MyGUILayout.OuterBoxHeader : MyGUILayout.InnerBoxHeader);

            Google2uGUIUtil.SetBool(in_savedVar, fadeVar.Open);
            if (fadeVar.Show())
            {
                foreach (var fadeOpenCallback in in_callbacks)
                {
                    fadeOpenCallback();
                }
            }
            MyGUILayout.EndFadeArea();
        }
        public void DoExport()
        {
            switch (WorksheetExportType)
            {
            default:
                return;

            case ExportType.CSV:
                _CSVPath = Google2uGUIUtil.GetString("g2ucsvDirectory", Google2u.Google2uGenPath("CSV"));
                break;

            case ExportType.JSON:
                _JSONPath = Google2uGUIUtil.GetString("g2ujsonDirectory", Google2u.Google2uGenPath("JSON"));
                break;

            case ExportType.NGUI:
                _NGUIPath = Google2uGUIUtil.GetString("g2unguiDirectory", Google2u.Google2uGenPath("NGUI"));
                break;

            case ExportType.StaticDatabase:
                _StaticDbPath = Google2uGUIUtil.GetString("g2uStaticDBResourcesDirectory", Google2u.Google2uGenPath("STATICDBRESOURCES"));
                break;

            case ExportType.XML:
                _XMLPath = Google2uGUIUtil.GetString("g2uxmlDirectory", Google2u.Google2uGenPath("XML"));
                break;

            case ExportType.ObjectDatabase:
                _ObjdbResourcesPath = Google2uGUIUtil.GetString("g2uobjDBResourcesDirectory", Google2u.Google2uGenPath("OBJDBRESOURCES"));
                _ObjdbEditorPath    = Google2uGUIUtil.GetString("g2uobjDBEditorDirectory", Google2u.Google2uGenPath("OBJDBEDITOR"));
                _PlaymakerPath      = Google2uGUIUtil.GetString("g2uplaymakerDirectory", Google2u.Google2uGenPath("PLAYMAKER"));
                break;
            }



            if (_ExportThread == null || _ExportThread.IsAlive == false)
            {
                _ExportThread = new Thread(ExportThread)
                {
                    Name = "ExportThread"
                };
                _ExportThread.Start(this);
            }
        }
Exemple #9
0
        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();
            }
        }
        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);
        }
Exemple #11
0
        public void DoExport()
        {
            _JSONPath     = Google2uGUIUtil.GetString("g2ujsonDirectory", Google2u.Google2uGenPath("JSON"));
            _CSVPath      = Google2uGUIUtil.GetString("g2ucsvDirectory", Google2u.Google2uGenPath("CSV"));
            _XMLPath      = Google2uGUIUtil.GetString("g2uxmlDirectory", Google2u.Google2uGenPath("XML"));
            _NGUIPath     = Google2uGUIUtil.GetString("g2unguiDirectory", Google2u.Google2uGenPath("NGUI"));
            _StaticDbPath = Google2uGUIUtil.GetString("g2uStaticDBResourcesDirectory",
                                                      Google2u.Google2uGenPath("STATICDBRESOURCES"));
            _ObjdbResourcesPath = Google2uGUIUtil.GetString("g2uobjDBResourcesDirectory",
                                                            Google2u.Google2uGenPath("OBJDBRESOURCES"));
            _ObjdbEditorPath = Google2uGUIUtil.GetString("g2uobjDBEditorDirectory",
                                                         Google2u.Google2uGenPath("OBJDBEDITOR"));
            _PlaymakerPath = Google2uGUIUtil.GetString("g2uplaymakerDirectory", Google2u.Google2uGenPath("PLAYMAKER"));


            if (_ExportThread == null || _ExportThread.IsAlive == false)
            {
                _ExportThread = new Thread(ExportThread)
                {
                    Name = "ExportThread"
                };
                _ExportThread.Start(this);
            }
        }
Exemple #12
0
        // 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++;
                }
            }
        }
Exemple #13
0
        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;
        }
        public void DrawGUIFull(EditorGUILayoutEx in_layout)
        {
            if (!_Initialized)
            {
                _Initialized        = true;
                UseTypeRow          = Google2uGUIUtil.GetBool(Prefix + "UseTypeRow", UseTypeRow);
                WorksheetExportType = Google2uGUIUtil.GetEnum(Prefix + "ExportType", WorksheetExportType);
            }

            if (WorksheetQueryStatus != QueryStatus.QueryComplete && WorksheetQueryStatus != QueryStatus.Idle &&
                RowsDisplay.Length == 0)
            {
                EditorGUILayout.LabelField(
                    Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_QUERYING_CELLS) +
                    Google2u.Ellipses);
            }
            else if (RowsDisplay.Length == 0)
            {
                if (WorksheetQueryStatus == QueryStatus.QueryComplete || WorksheetQueryStatus == QueryStatus.Idle)
                {
                    EditorGUILayout.LabelField(
                        Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_EMPTY_WORKSHEET));
                }
            }
            else
            {
                if (DoInitialSizeCheck)
                {
                    DoInitialSizeCheck = false;
                    for (var i = 0; i < ColOptions.Count; ++i)
                    {
                        CalculateColumnWidth(i, this);
                    }
                }

                if ((DateTime.Now - LastUpdateTime).TotalSeconds > 15)
                {
                    DoUpdateQuery = true;
                }

                if (ActiveCell != null)
                {
                    if (!ActiveCell.SkipValidation && !string.IsNullOrEmpty(ActiveCell.Tooltip))
                    {
                        EditorGUILayoutEx.SetColor(Color.red);
                        GUILayout.Label(ActiveCell.Tooltip);
                        EditorGUILayoutEx.ResetColor();
                    }
                    if (ActiveCell.DrawCellValue(in_layout))
                    {
                        WorksheetQueryStatus = QueryStatus.Idle;
                        LastUpdateTime       = DateTime.MinValue;
                        DoUpdateQuery        = true;
                        UpdateValidation     = true;
                    }
                }
                else
                {
                    var old = GUI.enabled;
                    GUI.enabled = false;
                    EditorGUILayout.TextField(string.Empty);
                    GUI.enabled = old;
                }

                // Calculate the total width and height of the scroll area
                var totalHeight = Math.Max(120, 22 + (24 * RowsDisplay.Length));
                var totalWidth  = 40 + ColOptions.Sum(in_colOption => in_colOption.Width);

                EditorGUILayout.Separator();
                if (Event.current.type == EventType.Repaint)
                {
                    _LastRect = GUILayoutUtility.GetLastRect();
                }
                var scrollHeight = Screen.height - _LastRect.y - 30;
                var screenRect   = new Rect(0f, _LastRect.y, Screen.width, scrollHeight);
                var viewRect     = new Rect(0f, 0f, totalWidth, totalHeight);

                _MyScrollPos = GUI.BeginScrollView(screenRect, _MyScrollPos, viewRect);

                var curRect = new Rect(0.0f, 0.0f, 40.0f, 22.0f);

                // Blank
                GUI.Label(curRect, string.Empty, in_layout.CellHeader);

                // Column Letters (Resizable Columns)
                for (var i = 0; i < RowsDisplay[0].Count; i++)
                {
                    var label = GetColumnName(i + 1);
                    curRect.x    += curRect.width;
                    curRect.width = ColOptions[i].Width;
                    GUI.Label(curRect, label, in_layout.CellHeader);

                    ColOptions[i].ColumnRect       = curRect;
                    ColOptions[i].ColumnRect.width = ColOptions[i].Width;

                    if (ColOptions[i].ColumnRect.Contains(Event.current.mousePosition))
                    {
                        ColOptions[i].HasMouse = true;
                    }

                    if (!ColOptions[i].HasMouse)
                    {
                        continue;
                    }

                    if ((Event.current.type == EventType.MouseDown) && (Event.current.clickCount >= 2))
                    {
                        // Doubleclick
                        CalculateColumnWidth(i, this);
                    }
                    if (Event.current.type == EventType.MouseDrag)
                    {
                        ColOptions[i].CurPos = Event.current.mousePosition;

                        if (!ColOptions[i].Dragging)
                        {
                            ColOptions[i].Dragging = true;
                            ColOptions[i].StartPos = ColOptions[i].CurPos;
                        }
                    }

                    if (Event.current.type == EventType.MouseUp)
                    {
                        ColOptions[i].Dragging = false;
                        ColOptions[i].HasMouse = false;
                    }

                    if (!ColOptions[i].Dragging)
                    {
                        continue;
                    }

                    if (Event.current.isMouse)
                    {
                        Event.current.Use();
                    }

                    ColOptions[i].Width +=
                        Convert.ToInt32((ColOptions[i].CurPos.x - ColOptions[i].StartPos.x));
                    ColOptions[i].StartPos = ColOptions[i].CurPos;
                    ColOptions[i].Width    = Math.Max(26, ColOptions[i].Width);
                }


                curRect = new Rect(0.0f, 22.0f, 40.0f, 24.0f);

                // The rest of the rows
                for (var i = 0; i < RowsDisplay.Length; i++)
                {
                    if (i == 1)
                    {
                        // Could be type row
                        if (GUI.Button(curRect, UseTypeRow ? "Type" : "2", in_layout.CellTypeButton))
                        {
                            if (UseTypeRow == false)
                            {
                                if (EditorUtility.DisplayDialog(Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_TYPEROWBOX_HEADER),
                                                                Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_TYPEROWBOX_MESSAGE), "OK", "Cancel"))
                                {
                                    UseTypeRow      = !UseTypeRow;
                                    UpdateCellTypes = true;
                                }
                            }
                            else
                            {
                                UseTypeRow      = !UseTypeRow;
                                UpdateCellTypes = true;
                            }
                        }
                    }
                    else
                    {
                        // Row Number
                        GUI.Label(curRect, Convert.ToString(i + 1), in_layout.CellHeader);
                    }

                    // Cell Values

                    if (i == 1 && UseTypeRow)
                    {
                        for (var j = 0; j < RowsDisplay[i].Count; j++)
                        {
                            curRect.x    += curRect.width;
                            curRect.width = ColOptions[j].Width;

                            var myCell = RowsDisplay[i][j];

                            if (myCell.MyType == SupportedType.Unrecognized)
                            {
                                myCell.SetTypeFromValue();
                            }

                            var cellType    = myCell.MyType;
                            var curSelected = 0;
                            foreach (var guiContent in _ComboBoxList)
                            {
                                if (guiContent.text.Equals(Convert.ToString(cellType)))
                                {
                                    break;
                                }
                                curSelected++;
                            }
                            if (curSelected >= _ComboBoxList.Length)
                            {
                                curSelected = 0;
                            }

                            Google2uGUIUtil.ComboBox comboBoxControl;
                            if (!_ComboBoxes.ContainsKey(j))
                            {
                                comboBoxControl = new Google2uGUIUtil.ComboBox(curRect, _ComboBoxList[curSelected],
                                                                               _ComboBoxList, in_layout.CellTypeButton, in_layout.OuterBox, in_layout.CellHeader);
                                _ComboBoxes.Add(j, comboBoxControl);
                            }
                            else
                            {
                                comboBoxControl = _ComboBoxes[j];
                            }
                            comboBoxControl.width  = curRect.width;
                            comboBoxControl.height = curRect.height;
                            comboBoxControl.x      = curRect.x;
                            comboBoxControl.y      = curRect.y;
                            var newSelected = comboBoxControl.Show();
                            if (newSelected != curSelected)
                            {
                                var newType =
                                    (SupportedType)
                                    Enum.Parse(typeof(SupportedType), _ComboBoxList[newSelected].text, true);
                                myCell.MyType = newType;
                                myCell.SetValueFromType();
                                UpdateCellTypes  = true;
                                UpdateValidation = true;
                            }
                        }
                    }
                    else
                    {
                        for (var j = 0; j < RowsDisplay[i].Count; j++)
                        {
                            curRect.x    += curRect.width;
                            curRect.width = ColOptions[j].Width;

                            if (curRect.x + curRect.width > _MyScrollPos.x && curRect.x < _MyScrollPos.x + Screen.width &&
                                curRect.y + curRect.height > _MyScrollPos.y && curRect.y < _MyScrollPos.y + scrollHeight)
                            {
                                if (i < 2 || i > 5 || !_ComboBoxes.ContainsKey(j) || _ComboBoxes[j].IsShown == false)
                                {
                                    var newCell = RowsDisplay[i][j].DrawGUI(in_layout, curRect, ActiveCell);
                                    if (newCell != null)
                                    {
                                        GUI.FocusControl("Blank");
                                        ActiveCell = newCell;
                                    }
                                }
                            }
                        }
                    }


                    curRect.x     = 0.0f;
                    curRect.width = 40.0f;
                    curRect.y    += curRect.height;
                }

                GUI.EndScrollView();
            }
        }
Exemple #15
0
        public override bool DrawGUIList(EditorGUILayoutEx in_layout, bool in_showAll)
        {
            var ret = true;

            var spreadsheetVisibleString = "workbook" + WorkbookName.Replace(' ', '_') + "_Visible";

            SpreadsheetVisible = Google2uGUIUtil.GetBool(spreadsheetVisibleString, SpreadsheetVisible);
            if ((SpreadsheetVisible == false) && !in_showAll)
            {
                return(true);
            }

            ShowSpreadsheet = Google2uGUIUtil.GetBool("workbook" + WorkbookName.Replace(' ', '_') + "_Open",
                                                      ShowSpreadsheet);
            var mainFadeArea = in_layout.BeginFadeArea(ShowSpreadsheet, WorkbookName,
                                                       "workbook" + WorkbookName.Replace(' ', '_'), in_layout.OuterBox, in_layout.OuterBoxHeader,
                                                       spreadsheetVisibleString);

            ShowSpreadsheet = mainFadeArea.Open;
            Google2uGUIUtil.SetBool("workbook" + WorkbookName.Replace(' ', '_') + "_Open", ShowSpreadsheet);

            // We have to do this here. Otherwise there is a threading issue (Can't initialize from EditorPreferences outside the main thread)
            if (ExportOptions == null)
            {
                ExportOptions = new Google2uExportOptions("workbook" + WorkbookName.Replace(' ', '_') + "_Option_");
            }

            if (mainFadeArea.Show())
            {
                var showExport   = false;
                var exportsheets = new List <Google2uWorksheet>();

                switch (WorksheetQueryStatus)
                {
                case QueryStatus.Idle:
                {
                    WorksheetQueryStatus = QueryStatus.Uninitialized;
                }
                break;

                case QueryStatus.Querying:
                    EditorGUILayout.LabelField(
                        Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_QUERYING_WORKSHEETS) +
                        Google2u.Ellipses);
                    break;

                case QueryStatus.QueryComplete:
                    if (WorksheetsDisplay.Length > 0)
                    {
                        foreach (var google2UWorksheet in WorksheetsDisplay)
                        {
                            if (google2UWorksheet.DrawGUIList(in_layout))
                            {
                                exportsheets.Add(google2UWorksheet);
                                showExport = true;
                            }
                        }

                        if (_OpenInvalidSheet)
                        {
                            var stillQuerying = false;
                            for (var i = 0; i < Worksheets.Count; ++i)
                            {
                                if (!exportsheets.Contains(Worksheets[i]))
                                {
                                    continue;
                                }

                                if (Worksheets[i].UpdateValidation || Worksheets[i].Validating)
                                {
                                    stillQuerying = true;
                                }


                                if (Worksheets[i].IsDataValid == false)
                                {
                                    var ed = EditorWindow.GetWindow <Google2uEditor>();
                                    Google2u.ActiveWorkbookWindow = ed;
                                    ed.Workbook = this;
                                    ed.Layout   = in_layout;


#if (UNITY_4)
                                    ed.title = WorkbookName;
#elif (UNITY_5_0)
                                    ed.title = WorkbookName;
#else
                                    ed.titleContent.text = WorkbookName;
#endif

                                    ed.wantsMouseMove    = true;
                                    ActiveWorksheetIndex = i;
                                    Worksheets[i].HighlightFirstInvalidCell();
                                    _OpenInvalidSheet = false;
                                    break;
                                }
                            }
                            if (!stillQuerying)
                            {
                                _OpenInvalidSheet = false;
                            }
                        }

                        EditorGUILayout.BeginHorizontal();
                        var content = new GUIContent(in_layout.RefreshButton,
                                                     Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_REFRESH_WORKBOOK));
                        if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight),
                                             GUILayout.Width(EditorGUILayoutEx.ButtonWidth)))
                        {
                            Worksheets.Clear();
                            WorksheetQueryStatus = QueryStatus.Uninitialized;
                        }


                        var querying            = false;
                        var bAllWorksheetsValid = true;
                        foreach (var google2UWorksheet in exportsheets)
                        {
                            if (google2UWorksheet.IsDataValid == false)
                            {
                                bAllWorksheetsValid = false;
                            }
                            if (google2UWorksheet.WorksheetQueryStatus != QueryStatus.Idle)
                            {
                                querying = true;
                            }
                        }
                        {
                            var guiEnabled = GUI.enabled;
                            if (querying)
                            {
                                GUI.enabled = false;
                            }

                            content = bAllWorksheetsValid
                                    ? new GUIContent(in_layout.ValidateButtonGreen,
                                                     Google2u.LocalizationInfo.Localize(
                                                         Localization.rowIds.ID_LABEL_VALIDATE_WORKBOOK))
                                    : new GUIContent(in_layout.ValidateButtonRed,
                                                     Google2u.LocalizationInfo.Localize(
                                                         Localization.rowIds.ID_LABEL_VALIDATE_WORKBOOK));

                            if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight),
                                                 GUILayout.Width(EditorGUILayoutEx.ButtonWidth)))
                            {
                                // Do Validation for the worksheets we will be exporting
                                foreach (var google2UWorksheet in exportsheets)
                                {
                                    google2UWorksheet.UpdateValidation = true;
                                    google2UWorksheet.Validating       = true;
                                }
                                _OpenInvalidSheet = true;
                            }
                            GUI.enabled = guiEnabled;
                        }

                        content = new GUIContent(in_layout.EditButton,
                                                 Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_EDIT_WORKBOOK));
                        if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight),
                                             GUILayout.Width(EditorGUILayoutEx.ButtonWidth)))
                        {
                            var ed = EditorWindow.GetWindow <Google2uEditor>();
                            Google2u.ActiveWorkbookWindow = ed;
                            ed.Workbook = this;
                            ed.Layout   = in_layout;
#if (UNITY_4)
                            ed.title = WorkbookName;
#elif (UNITY_5_0)
                            ed.title = WorkbookName;
#else
                            ed.titleContent.text = WorkbookName;
#endif
                            ed.wantsMouseMove = true;
                        }

                        GUILayout.FlexibleSpace();

                        if (showExport)
                        {
                            var oldEnabled = GUI.enabled;
                            if (bAllWorksheetsValid == false)
                            {
                                GUI.enabled = false;
                            }
                            content = new GUIContent(in_layout.SaveButton,
                                                     Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_EXPORT));
                            if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight),
                                                 GUILayout.Width(EditorGUILayoutEx.ButtonWidth)))
                            {
                                DoExport(exportsheets);
                            }
                            GUI.enabled = oldEnabled;
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    else
                    {
                        EditorGUILayout.LabelField(
                            Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_NO_WORKSHEETS));
                    }
                    break;
                }
            }
            in_layout.EndFadeArea();
            return(ret);
        }
Exemple #16
0
        private static void AddManualWorkbookByUrl(string in_manualUrl, Google2uData in_instance)
        {
            WorkbookBase info;

            if (string.IsNullOrEmpty(in_manualUrl))
            {
                Debug.LogError(LocalizationInfo.Localize(Localization.rowIds.ID_ERROR_EMPTY_URL));
                return;
            }

            var refreshManualWorkbookCache = false;

            try
            {
                var key =
                    in_manualUrl.Substring(in_manualUrl.IndexOf("key=", StringComparison.InvariantCultureIgnoreCase) + 4);
                key = key.Split('&')[0];

                var singleQuery = new WorksheetQuery(key, "public", "values");

                if (in_instance.ManualService == null && !SetupManualService(in_instance))
                {
                    return;
                }

                var feed = in_instance.ManualService.Query(singleQuery);

                var finalUrl = in_manualUrl.Split('&')[0];

                if (feed != null)
                {
                    info =
                        in_instance.ManualWorkbooks.Find(in_i => Google2uGUIUtil.GfuStrCmp(in_i.WorkbookUrl, finalUrl)) ??
                        in_instance.AccountWorkbooks.Find(in_i => Google2uGUIUtil.GfuStrCmp(in_i.WorkbookUrl, finalUrl))
                        as WorkbookBase;
                    if (info == null)
                    {
                        var newWorkbook = new Google2uManualWorkbook(feed, finalUrl, feed.Title.Text,
                                                                     in_instance.ManualService);
                        in_instance.ManualWorkbooks.Add(newWorkbook);

                        refreshManualWorkbookCache = true;
                    }
                }
            }
            catch
            {
                try
                {
                    var key =
                        in_manualUrl.Substring(
                            in_manualUrl.IndexOf("spreadsheets/d/", StringComparison.InvariantCultureIgnoreCase) + 15);
                    key = key.Split('/')[0];

                    if (in_instance.ManualService == null && !SetupManualService(in_instance))
                    {
                        return;
                    }

                    var singleQuery = new WorksheetQuery(key, "public", "values");
                    var feed        = in_instance.ManualService.Query(singleQuery);
                    var urlParts    = in_manualUrl.Split('/');

                    var    finalUrl = "";
                    var    urlBuild = 0;
                    string urlPart;
                    do
                    {
                        urlPart   = urlParts[urlBuild];
                        finalUrl += urlPart + '/';
                        urlBuild++;
                    } while (urlPart != key);
                    if (feed != null)
                    {
                        info =
                            in_instance.ManualWorkbooks.Find(
                                in_i => Google2uGUIUtil.GfuStrCmp(in_i.WorkbookUrl, finalUrl)) ??
                            in_instance.AccountWorkbooks.Find(
                                in_i => Google2uGUIUtil.GfuStrCmp(in_i.WorkbookUrl, finalUrl)) as WorkbookBase;
                        if (info == null)
                        {
                            var newWorkbook = new Google2uManualWorkbook(feed, finalUrl, feed.Title.Text,
                                                                         in_instance.ManualService);
                            in_instance.ManualWorkbooks.Add(newWorkbook);

                            refreshManualWorkbookCache = true;
                        }
                    }
                }
                catch
                {
                    Debug.LogError(LocalizationInfo.Localize(Localization.rowIds.ID_ERROR_INVALID_URL));
                }
            }

            if (refreshManualWorkbookCache)
            {
                in_instance.ManualWorkbookCache = string.Empty;
                foreach (var Google2uSpreadsheet in in_instance.ManualWorkbooks)
                {
                    in_instance.ManualWorkbookCache += Google2uSpreadsheet.WorkbookUrl + "|";
                }
            }
        }
Exemple #17
0
        public override void DrawGUIFull(EditorGUILayoutEx in_layout)
        {
            switch (WorksheetQueryStatus)
            {
            case QueryStatus.Idle:
            {
                WorksheetQueryStatus = QueryStatus.Uninitialized;
            }
            break;

            case QueryStatus.Querying:
                EditorGUILayout.LabelField(
                    Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_QUERYING_WORKSHEETS) +
                    Google2u.Ellipses);
                break;

            case QueryStatus.QueryComplete:
                if (WorksheetsDisplay.Length > 0)
                {
                    EditorGUILayout.BeginHorizontal();


                    var worksheetNames = new string[WorksheetsDisplay.Length];
                    for (var i = 0; i < WorksheetsDisplay.Length; ++i)
                    {
                        worksheetNames[i] = WorksheetsDisplay[i].WorksheetName;
                    }

                    var activeWorksheet = WorksheetsDisplay[ActiveWorksheetIndex];
                    if (activeWorksheet == null)
                    {
                        throw new ArgumentNullException("ActiveWorksheet");
                    }

                    var content = new GUIContent(in_layout.RefreshButton,
                                                 Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_REFRESH_WORKBOOK));
                    if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight),
                                         GUILayout.Width(EditorGUILayoutEx.ButtonWidth)))
                    {
                        Worksheets.Clear();
                        WorksheetQueryStatus = QueryStatus.Uninitialized;
                    }

                    {
                        var guiEnabled = GUI.enabled;
                        if (activeWorksheet.WorksheetQueryStatus != QueryStatus.Idle)
                        {
                            GUI.enabled = false;
                        }
                        content = activeWorksheet.IsDataValid
                                ? new GUIContent(in_layout.ValidateButtonGreen,
                                                 Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_VALIDATE_WORKSHEET))
                                : new GUIContent(in_layout.ValidateButtonRed,
                                                 Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_VALIDATE_WORKSHEET));

                        if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight),
                                             GUILayout.Width(EditorGUILayoutEx.ButtonWidth)))
                        {
                            // Do Validation for the active worksheet
                            activeWorksheet.UpdateValidation = true;
                            _OpenInvalidSheet = true;
                        }
                        GUI.enabled = guiEnabled;
                    }

                    content = new GUIContent(in_layout.GoogleButton,
                                             Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_OPEN_IN_GOOGLE));
                    if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight),
                                         GUILayout.Width(EditorGUILayoutEx.ButtonWidth)))
                    {
                        Application.OpenURL(WorkbookUrl);
                    }

                    GUILayout.FlexibleSpace();

                    var oldEnabled = GUI.enabled;
                    if ((activeWorksheet.WorksheetExportType == ExportType.DoNotExport) ||
                        activeWorksheet.IsDataValid == false)
                    {
                        GUI.enabled = false;
                    }
                    content = new GUIContent(in_layout.SaveButton,
                                             Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_EXPORT));
                    if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight),
                                         GUILayout.Width(EditorGUILayoutEx.ButtonWidth)))
                    {
                        DoExport(new List <Google2uWorksheet> {
                            activeWorksheet
                        });
                    }

                    GUI.enabled = oldEnabled;

                    EditorGUILayout.EndHorizontal();

                    var newActiveWorksheetIndex =
                        EditorGUILayout.Popup(
                            Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_ACTIVE_WORKSHEET) + ": ",
                            ActiveWorksheetIndex,
                            worksheetNames);

                    if (newActiveWorksheetIndex != ActiveWorksheetIndex)
                    {
                        WorksheetsDisplay[ActiveWorksheetIndex].ActiveCell = null;
                        ActiveWorksheetIndex = newActiveWorksheetIndex;
                    }

                    var newExportType =
                        (ExportType)
                        EditorGUILayout.EnumPopup(
                            Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_EXPORT_AS) + ": ",
                            activeWorksheet.WorksheetExportType);
                    if (newExportType != activeWorksheet.WorksheetExportType)
                    {
                        activeWorksheet.WorksheetExportType =
                            Google2uGUIUtil.SetEnum(activeWorksheet.Prefix + "ExportType", newExportType);
                    }

                    DrawSpreadsheetOptions(in_layout, activeWorksheet.WorksheetExportType, activeWorksheet);

                    EditorGUILayout.Separator();

                    activeWorksheet.DrawGUIFull(in_layout);
                }
                else
                {
                    EditorGUILayout.LabelField(
                        Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_NO_WORKSHEETS));
                }
                break;
            }
        }
Exemple #18
0
        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);
        }
Exemple #19
0
        // 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);
                }
            }
        }
Exemple #20
0
        public Google2uExportOptions(string in_prefix)
        {
            _Prefix = in_prefix;

            LowercaseHeader = Google2uGUIUtil.GetBool(in_prefix + "LowercaseHeader", LowercaseHeader);

            TrimStrings      = Google2uGUIUtil.GetBool(in_prefix + "TrimStrings", TrimStrings);
            TrimStringArrays = Google2uGUIUtil.GetBool(in_prefix + "TrimStringArrays", TrimStringArrays);

            ArrayDelimiters        = Google2uGUIUtil.GetInt(in_prefix + "ArrayDelimiters", ArrayDelimiters);
            StringArrayDelimiters  = Google2uGUIUtil.GetInt(in_prefix + "StringArrayDelimiters", StringArrayDelimiters);
            ComplexTypeDelimiters  = Google2uGUIUtil.GetInt(in_prefix + "ComplexTypeDelimiters", ComplexTypeDelimiters);
            ComplexArrayDelimiters = Google2uGUIUtil.GetInt(in_prefix + "ComplexArrayDelimiters", ComplexArrayDelimiters);

            #region ObjectDatabase Options

            var dbObjName = Google2uGUIUtil.GetString(_Prefix + "GameObjectDatabaseName", string.Empty);
            if (string.IsNullOrEmpty(dbObjName) == false)
            {
                var go = GameObject.Find(dbObjName);
                if (go)
                {
                    ExportDatabaseGameObjectName = dbObjName;
                    _ExportDatabaseGameObject    = go;
                }
            }


            _OverrideObjectDatabaseNames = new Dictionary <string, string>();


            var tmpOverrides = Google2uGUIUtil.GetString(_Prefix + "OverrideObjectDatabaseNames",
                                                         string.Empty);
            var tmpOverrideSplit = tmpOverrides.Split(',');
            foreach (var s in tmpOverrideSplit)
            {
                var sSplit = s.Split('|');
                if (sSplit.Length == 2)
                {
                    _OverrideObjectDatabaseNames.Add(sSplit[0], sSplit[1]);
                }
            }

            GeneratePlaymakerActions = Google2uGUIUtil.GetBool(in_prefix + "GeneratePlaymakerActions",
                                                               GeneratePlaymakerActions);
            UseDoNotDestroy     = Google2uGUIUtil.GetBool(in_prefix + "UseDoNotDestroy", UseDoNotDestroy);
            ObjectDBCullColumns = Google2uGUIUtil.GetBool(in_prefix + "ObjectDBCullColumns", ObjectDBCullColumns);
            ObjectDBCullRows    = Google2uGUIUtil.GetBool(in_prefix + "ObjectDBCullRows", ObjectDBCullRows);

            #endregion

            #region Static DB Options

            StaticDBCullColumns = Google2uGUIUtil.GetBool(in_prefix + "StaticDBCullColumns", StaticDBCullColumns);
            StaticDBCullRows    = Google2uGUIUtil.GetBool(in_prefix + "StaticDBCullRows", StaticDBCullRows);

            #endregion

            #region JSON Options

            EscapeUnicode         = Google2uGUIUtil.GetBool(in_prefix + "EscapeUnicode", EscapeUnicode);
            JSONCellArrayToString = Google2uGUIUtil.GetBool(in_prefix + "JSONCellArrayToString", JSONCellArrayToString);
            JSONExportClass       = Google2uGUIUtil.GetBool(in_prefix + "JSONExportClass", JSONExportClass);
            JSONExportType        = Google2uGUIUtil.GetEnum(in_prefix + "JSONExportType", JSONExportType);
            JSONCullColumns       = Google2uGUIUtil.GetBool(in_prefix + "JSONCullColumns", JSONCullColumns);
            JSONCullRows          = Google2uGUIUtil.GetBool(in_prefix + "JSONCullRows", JSONCullRows);
            JSONIgnoreIDColumn    = Google2uGUIUtil.GetBool(in_prefix + "JSONIgnoreIDColumn", JSONIgnoreIDColumn);
            JSONExportPretty      = Google2uGUIUtil.GetBool(in_prefix + "JSONExportPretty", JSONExportPretty);
            #endregion

            #region XML Options

            XMLCellArrayToString = Google2uGUIUtil.GetBool(in_prefix + "XMLCellArrayToString", XMLCellArrayToString);
            XMLCullColumns       = Google2uGUIUtil.GetBool(in_prefix + "XMLCullColumns", XMLCullColumns);
            XMLCullRows          = Google2uGUIUtil.GetBool(in_prefix + "XMLCullRows", XMLCullRows);

            #endregion

            #region CSV Options

            EscapeCSVStrings     = Google2uGUIUtil.GetBool(in_prefix + "EscapeCSVStrings", EscapeCSVStrings);
            CSVCullColumns       = Google2uGUIUtil.GetBool(in_prefix + "CSVCullColumns", CSVCullColumns);
            CSVCullRows          = Google2uGUIUtil.GetBool(in_prefix + "CSVCullRows", CSVCullRows);
            CSVConvertLineBreaks = Google2uGUIUtil.GetBool(in_prefix + "CSVConvertLineBreaks", CSVConvertLineBreaks);

            #endregion

            #region NGUI Options

            EscapeNGUIStrings     = Google2uGUIUtil.GetBool(in_prefix + "EscapeNGUIStrings", EscapeNGUIStrings);
            NGUICullColumns       = Google2uGUIUtil.GetBool(in_prefix + "NGUICullColumns", NGUICullColumns);
            NGUICullRows          = Google2uGUIUtil.GetBool(in_prefix + "NGUICullRows", NGUICullRows);
            NGUIConvertLineBreaks = Google2uGUIUtil.GetBool(in_prefix + "NGUIConvertLineBreaks", NGUIConvertLineBreaks);
            NGUILegacyExport      = Google2uGUIUtil.GetBool(in_prefix + "NGUILegacyExport", NGUILegacyExport);

            #endregion
        }
        public FadeArea BeginFadeArea(bool in_open, string in_label, string in_id, GUIStyle in_areaStyle,
                                      GUIStyle in_labelStyle, string in_WorkbookVisibilityString)
        {
            var tmp1 = GUI.color;

            var fadeArea = BeginFadeArea(in_open, in_id, 26, in_areaStyle);

            var tmp2 = GUI.color;

            GUI.color = tmp1;

            EditorGUILayout.BeginHorizontal();

            if (!in_open)
            {
                if (GUILayout.Button(string.Empty, PlusButton))
                {
                    fadeArea.Open = !fadeArea.Open;
                    GuiEditor.Repaint();
                }
            }
            else
            {
                if (GUILayout.Button(string.Empty, MinusButton))
                {
                    fadeArea.Open = !fadeArea.Open;
                    GuiEditor.Repaint();
                }
            }

            if (in_label != "")
            {
                if (GUILayout.Button(in_label, in_labelStyle))
                {
                    fadeArea.Open = !fadeArea.Open;
                    GuiEditor.Repaint();
                }
            }

            GUILayout.FlexibleSpace();

            var spreadsheetVisible = true;

            if (!string.IsNullOrEmpty(in_WorkbookVisibilityString))
            {
                spreadsheetVisible = Google2uGUIUtil.GetBool(in_WorkbookVisibilityString, true);
            }
            if (spreadsheetVisible)
            {
                if (GUILayout.Button(string.Empty, VisibilityButton))
                {
                    Google2uGUIUtil.SetBool(in_WorkbookVisibilityString, false);
                }
            }
            else
            {
                if (GUILayout.Button(string.Empty, VisibilityHiddenButton))
                {
                    Google2uGUIUtil.SetBool(in_WorkbookVisibilityString, true);
                }
            }

            EditorGUILayout.EndHorizontal();

            GUI.color = tmp2;
            return(fadeArea);
        }