public override void OnInspectorGUI()
        {
            serializedObject.Update();

            DatablockManager datablockManager = DatablockManager.Instance;

            EditorGUIUtility.labelWidth          = 160;
            datablockManager.searchEntireProject = !EditorGUILayout.Toggle("Use custom search paths", !datablockManager.searchEntireProject);

            if (!datablockManager.searchEntireProject)
            {
                SerializedProperty searchPaths = serializedObject.FindProperty("customSearchPaths");
                EditorGUI.indentLevel = 1;
                EditorGUILayout.PropertyField(searchPaths, true);
            }

            GUILayout.BeginHorizontal();

            GUILayout.FlexibleSpace();

            if (GUILayout.Button("View Datablocks", GUILayout.Width(200)))
            {
                DatablockList.ViewDatablocks();
            }

            GUILayout.FlexibleSpace();

            GUILayout.EndHorizontal();

            EditorGUILayout.HelpBox("Tracking " + datablockManager.Count() + " datablocks", MessageType.Info);

            serializedObject.ApplyModifiedProperties();
        }
Ejemplo n.º 2
0
        private void OnGUI()
        {
            DatablockManager datablockManager = DatablockManager.Instance;

            EditorGUILayout.HelpBox("Export your data in CSV format. Can be imported into a Google sheets, Excel, and other spreadsheet porgrams.", MessageType.None);
            List <Type> types = DatablockList.GetInstances(typeof(Datablock));

            if (types.Count == 0)
            {
                EditorGUILayout.LabelField("No datablock types found");
                return;
            }

            datablockTypeIndex = EditorGUILayout.Popup("Choose datablock type", datablockTypeIndex, types.Select(d => d.ToString()).ToArray());
            Type datablockType = types[datablockTypeIndex];

            string exportLabel = exportData ? "Export " + datablockManager.GetDatablocks(datablockType).Count() + " datablocks" : "Export schema";

            GUI.backgroundColor = new Color(0, 0.8f, 0);

            if (GUILayout.Button(exportLabel))
            {
                string saveLocation = EditorUtility.SaveFilePanel("Export datablocks", "", datablockType.Name.ToString() + "s" + ".csv", "csv");
                if (!string.IsNullOrEmpty(saveLocation))
                {
                    ExportDatablocks(datablockType, saveLocation);
                }
            }

            GUI.backgroundColor = new Color(1, 1, 1);

            EditorGUILayout.Separator();

            showExportOptions = EditorGUILayout.Foldout(showExportOptions, "Export options");

            if (showExportOptions)
            {
                EditorGUI.indentLevel = 1;

                fieldDelimiter   = EditorGUILayout.TextField("Field delimiter", fieldDelimiter);
                exportData       = EditorGUILayout.Toggle("Export data", exportData);
                exportFullValues = EditorGUILayout.Toggle(new GUIContent("Include full values", "Exports the full value of a field even if it inherits its value."), exportFullValues);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Attempt to determine the type of datablock based on the spreadsheets headers
        /// </summary>
        /// <param name="headers">1st row headers</param>
        /// <returns></returns>
        protected List <DatablockDetectionInfo> AutoDetectDatablockType(List <string> headers)
        {
            List <Type> types = DatablockList.GetInstances(typeof(Datablock));

            if (types.Count == 0)
            {
                Debug.LogError("No datablocks defined!");
                return(null);
            }

            var typeMatches = new List <DatablockDetectionInfo>();

            foreach (Type datablockType in types)
            {
                var detectionInfo = new DatablockDetectionInfo
                {
                    datablockType = datablockType
                };

                typeMatches.Add(detectionInfo);

                foreach (string header in headers)
                {
                    FieldInfo field = datablockType.GetField(header, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
                    if (field != null)
                    {
                        detectionInfo.fields.Add(field);
                    }
                }
            }

            // Not a single field matched
            if (typeMatches.Sum(t => t.fields.Count) == 0)
            {
                return(null);
            }

            return(typeMatches);
        }
        private void ShowExportUI()
        {
            DatablockManager datablockManager = DatablockManager.Instance;

            EditorGUILayout.HelpBox("Export datablocks of the selected type to a Google sheet. Select the worksheet you want to export to. Note: All exiting data on the first sheet will be overwritten.", MessageType.None);

            EditorGUILayout.BeginHorizontal();

            GUI.backgroundColor = new Color(0, 0.8f, .8f);

            if (GUILayout.Button("Refresh Spreesheets"))
            {
                spreadsheetEntries.Clear();

                var query = new SpreadsheetQuery();

                SpreadsheetFeed feed = null;
                try
                {
                    feed = sheetsAPI.Service.Query(query);
                }
                catch (Exception)
                {
                    Debug.LogError("OAuth error");
                    sheetsAPI.ClearOAuthToken();
                    throw;
                }

                // Iterate through all of the spreadsheets returned
                foreach (SpreadsheetEntry entry in feed.Entries)
                {
                    spreadsheetEntries.Add(entry);
                }
            }

            GUI.backgroundColor = new Color(1f, 0.2f, .4f);

            if (GUILayout.Button("Clear OAuth token"))
            {
                sheetsAPI.ClearOAuthToken();
            }

            GUI.backgroundColor = Color.white;


            EditorGUILayout.EndHorizontal();

            var options = new List <string>(spreadsheetEntries.Select(s => s.Title.Text));

            if (spreadsheetEntries.Count == 0)
            {
                options.Insert(0, "No spreadsheets found");
            }
            else
            {
                options.Insert(0, "Select");
            }

            if (spreadsheetIndex >= options.Count)
            {
                spreadsheetIndex = 0;
            }

            int tempSpreadsheetIndex = EditorGUILayout.Popup("Select spreedsheet", spreadsheetIndex, options.ToArray());

            if (tempSpreadsheetIndex != spreadsheetIndex)
            {
                canBeExported = false;

                spreadsheetIndex = tempSpreadsheetIndex;

                if (spreadsheetIndex != 0)
                {
                    DatablockManager.Instance.RefreshAssets();

                    spreadsheet = spreadsheetEntries.FirstOrDefault(s => s.Title.Text == options[spreadsheetIndex]);

                    if (spreadsheet.Worksheets.Entries.Count == 0)
                    {
                        Debug.LogError("Spreadsheet has no worksheet. Please add a worksheet to use this spreadsheet.");
                        return;
                    }

                    canBeExported = true;
                }
            }

            if (spreadsheetIndex != 0 && canBeExported)
            {
                List <Type> types = DatablockList.GetInstances(typeof(Datablock));

                datablockTypeIndex = EditorGUILayout.Popup("Choose datablock type", datablockTypeIndex, types.Select(d => d.ToString()).ToArray());
                Type datablockType = types[datablockTypeIndex];


                GUI.backgroundColor = new Color(0, 0.8f, 0);
                string exportLabel = exportData ? "Export " + datablockManager.GetDatablocks(datablockType).Count() + " datablocks" : "Export schema";

                if (GUILayout.Button(exportLabel))
                {
                    ExportDatablocks(datablockType);
                }

                GUI.backgroundColor = Color.white;
                EditorGUILayout.HelpBox("All data on the first sheet will be overwritten.", MessageType.Warning);
            }

            showExportOptions = EditorGUILayout.Foldout(showExportOptions, "Export options");

            if (showExportOptions)
            {
                EditorGUI.indentLevel = 1;

                exportData       = EditorGUILayout.Toggle("Export data", exportData);
                exportFullValues = EditorGUILayout.Toggle(new GUIContent("Include full values", "Exports the full value of a field even if it inherits its value."), exportFullValues);
            }
        }