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();
        }
Exemplo n.º 2
0
        private void Awake()
        {
            // If there is already a DatablockManager, destroy this one
            if (instance)
            {
                if (instance.datablocks.Count == 0)
                {
                    Destroy(instance);
                    instance = this;
                }
                else
                {
                    enabled = false;
                    Destroy(gameObject);
                    return;
                }
            }


            instance = this;

            if (Application.isPlaying)
            {
                ProcessDatablocks();
                DontDestroyOnLoad(gameObject);
            }
            else
            {
#if UNITY_EDITOR
                Instance.RefreshAssets();
#endif
            }
        }
Exemplo n.º 3
0
        public virtual void OnEnable()
        {
            datablock = (Datablock)target;

            renameAssetTempName = datablock.name;

            members = Datablock.GetFields(datablock.GetType());
            DatablockManager.EnsureInitilized();
        }
Exemplo n.º 4
0
 /// <summary>
 ///     Ensure the manager has been created
 /// </summary>
 public static void EnsureInitilized()
 {
     if (!instance)
     {
         instance = FindObjectOfType <DatablockManager>();
         if (!instance)
         {
             var manager = new GameObject("Datablock Manager", typeof(DatablockManager));
             instance = manager.GetComponent <DatablockManager>();
         }
     }
 }
Exemplo n.º 5
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);
            }
        }
        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);
            }
        }