public override void DrawCustomInspector() { GUILayout.Label("Custom filename:"); customFileName = GUILayout.TextField(customFileName); GUILayout.Label("Databox Object:"); databoxObject = (DataboxObject)EditorGUILayout.ObjectField(databoxObject, typeof(DataboxObject), false); }
void DeserializeWithFullSerializer(string _text, DataboxObject _databoxObject, bool _callEvent) { if (_databoxObject.encryption) { _text = _databoxObject.XOREncryptDecrypt(_text, _databoxObject.encryptionKey); } fsSerializer _serializer = new fsSerializer(); fsData data = fsJsonParser.Parse(_text); // step 2: deserialize the data object deserialized = null; _serializer.TryDeserialize(data, typeof(OrderedDictionary <string, DataboxObject.Database>), ref deserialized); var _a = (OrderedDictionary <string, DataboxObject.Database>)deserialized as OrderedDictionary <string, DataboxObject.Database>; _databoxObject.DB = _a; if (_callEvent && _databoxObject.OnDatabaseLoaded != null && Application.isPlaying) { _databoxObject.OnDatabaseLoaded(); } _databoxObject.databaseLoaded = true; if (_databoxObject.debugMode) { Debug.Log("Databox: Database loaded"); } // destroy this object //Destroy(this.gameObject); }
public override void DrawCustomInspector() { GUILayout.Label("Databox Object:"); databoxObject = (DataboxObject)EditorGUILayout.ObjectField(databoxObject, typeof(DataboxObject), false); GUILayout.Label("Import type:"); importType = (ImportType)EditorGUILayout.EnumPopup(importType); }
private void Start() { if (databoxObjectManager != null) { databoxObject = databoxObjectManager.GetDataboxObject("Profile"); } }
public static void ForceDownloadRuntime(DataboxObject _database) { serverRootURL = _database.cloudServer; id = _database.cloudId; database = _database; instance.StartCoroutine(GetDataIE()); //this will launch the coroutine on our instance }
public static void SyncRuntime(DataboxObject _database) { serverRootURL = _database.cloudServer; id = _database.cloudId; database = _database; instance.StartCoroutine(SyncIE()); }
public override void OnInspectorGUI() { DataboxObject dbObject = (DataboxObject)target; DataboxEditor.DrawEditor(dbObject); EditorUtility.SetDirty(dbObject); }
public static void Check(string _serverUrl, string _uniqueId, DataboxObject _databoxObject) { serverRootURL = _serverUrl; id = _uniqueId; database = _databoxObject; #if UNITY_EDITOR Databox.Utils.EditorCoroutines.Execute(CheckIE()); #endif }
public IEnumerator LoadCoroutineIE(string _savePath, DataboxObject _databoxObject, bool _callEvent) { string _j = ""; using (UnityEngine.Networking.UnityWebRequest _download = UnityEngine.Networking.UnityWebRequest.Get(_savePath)) { yield return(_download.SendWebRequest()); while (!_download.isDone) { #if UNITY_2020_1_OR_NEWER if (_download.result == UnityWebRequest.Result.ConnectionError) #else if (_download.isNetworkError || _download.isHttpError || !string.IsNullOrEmpty(_download.error)) #endif { break; } yield return(null); } #if UNITY_2020_1_OR_NEWER if (_download.result == UnityWebRequest.Result.ConnectionError) #else if (_download.isNetworkError || _download.isHttpError || !string.IsNullOrEmpty(_download.error)) #endif { Debug.Log(_download.error); } else { _j = _download.downloadHandler.text; } } if (!string.IsNullOrEmpty(_j)) { if (_databoxObject.serializer == DataboxObject.Serializer.FullSerializer) { DeserializeWithFullSerializer(_j, _databoxObject, _callEvent); } else { #if NET_4_6 DeserializeWithOdin(_j, _databoxObject, _callEvent); #endif } } else { // destroy this object //Destroy(this.gameObject); } }
protected void Awake() { base.Awake(); itemDatabox = OS.Utils.DataboxObjectManager.GetDataboxObject("ItemData"); itemDatabox.OnDatabaseLoaded += DataReady; itemDatabox.LoadDatabase(); }
protected void Awake() { base.Awake(); textDatabox = OS.Utils.DataboxObjectManager.GetDataboxObject("Text"); textDatabox.OnDatabaseLoaded += DataReady; textDatabox.LoadDatabase(); SetLanguage(Application.systemLanguage); }
protected void Awake() { base.Awake(); enemyDataBox = OS.Utils.DataboxObjectManager.GetDataboxObject("EnemyData"); enemyDataBox.OnDatabaseLoaded += DataReady; enemyDataBox.LoadDatabase(); //Debug.Log(listEnemy.Count()); }
public override void DrawCustomInspector() { GUILayout.Label("Databox Object:"); databoxObject = (DataboxObject)EditorGUILayout.ObjectField(databoxObject, typeof(DataboxObject), false); FRVariableGUIUtility.DrawVariable("Table ID:", tableID, this, false, editorSkin); FRVariableGUIUtility.DrawVariable("Entry ID:", entryID, this, false, editorSkin); GUILayout.Label("Register to:"); databoxObjectToRegister = (DataboxObject)EditorGUILayout.ObjectField(databoxObjectToRegister, typeof(DataboxObject), false); FRVariableGUIUtility.DrawVariable("New entry ID:", newEntryID, this, false, editorSkin); }
private void Start() { SettingsFileDb = databoxManager.GetDataboxObject("UserSettings"); var settingsExists = File.Exists(SettingsFileDb.savePath); if (settingsExists) { SettingsFileDb.LoadDatabase(); } BaseSettingObj.InsertAllSettingsData(SettingsFileDb, CONFIG_TABLE_NAME); SettingsFileDb.SaveDatabase(); }
public static void InsertAllSettingsData(DataboxObject settingsFile, string tableName) { System.Type[] types = System.Reflection.Assembly.GetExecutingAssembly().GetTypes(); System.Type[] found = (from System.Type type in types where type.IsSubclassOf(typeof(BaseSettingObj)) && !type.IsAbstract select type).ToArray(); foreach (var item in found) { item.BaseType.GetMethod("InsertInto").Invoke(item, new object[] { settingsFile, tableName }); } }
public void Bind(DataboxObjectManager _manager, string _dbID, string _tableID, string _entryID, string _valueID) { databox = _manager.GetDataboxObject(_dbID); if (databox != null) { tableID = _tableID; entryID = _entryID; valueID = _valueID; BindInternal(); } else { Debug.LogWarning("Binding failed: " + gameObject.name); } }
public void Bind(DataboxObject _databoxObject, string _tableID, string _entryID, string _valueID) { if (_databoxObject != null) { databox = _databoxObject; tableID = _tableID; entryID = _entryID; valueID = _valueID; BindInternal(); } else { Debug.LogWarning("Binding failed: " + gameObject.name); } }
public static void AppendToDB(DataboxObject _database, string _tableName, List <Entry> _entries) { // Add entries for (int e = 0; e < _entries.Count; e++) { for (int a = 0; a < _entries[e].values.Count; a++) { var _type = System.Type.GetType(_entries[e].types[a]); var _instance = System.Activator.CreateInstance(_type) as DataboxType; // Convert csv string value to DataboxType value _instance.Convert(_entries[e].values[a]); _database.AddData(_tableName, _entries[e].entryName, _entries[e].fields[a], _instance as DataboxType); } } }
public ProfileSaveFile(DataboxObjectManager DataboxManager) { DataboxObject = DataboxManager.GetDataboxObject(CONFIG_TABLE_NAME); if (DataboxObject != null) { var profileExists = File.Exists(DataboxObject.savePath); if (profileExists) { DataboxObject.LoadDatabase(); } BaseProfileObj.InsertAllProfileData(DataboxObject, CONFIG_TABLE_NAME); DataboxObject.SaveDatabase(); } }
void DeserializeWithOdin(string _text, DataboxObject _databoxObject, bool _callEvent) { var bytes = Convert.FromBase64String(_text); if (_databoxObject.encryption) { bytes = _databoxObject.ByteXOREncryptDecrypt(bytes, _databoxObject.encryptionKey); } DataFormat _format = DataFormat.Binary; switch (_databoxObject.dataFormat) { case DataboxObject.OdinDataFormat.binary: _format = DataFormat.Binary; break; case DataboxObject.OdinDataFormat.json: _format = DataFormat.JSON; break; } Stream _stream = new MemoryStream(bytes); using (var reader = new BinaryReader(_stream)) { _databoxObject.DB = SerializationUtility.DeserializeValue <OrderedDictionary <string, DataboxObject.Database> >(reader.ReadBytes((int)_stream.Length), _format); } if (_callEvent && _databoxObject.OnDatabaseLoaded != null && Application.isPlaying) { _databoxObject.OnDatabaseLoaded(); } _databoxObject.databaseLoaded = true; if (_databoxObject.debugMode) { Debug.Log("Databox: Database loaded"); } // destroy this object //Destroy(this.gameObject); }
public static void ReplaceDB(DataboxObject _database, string _tableName, List <Entry> _entries) { if (firstTimeReplace) { _database.DB = new Databox.Dictionary.OrderedDictionary <string, DataboxObject.Database>(); firstTimeReplace = false; } // Add entries for (int e = 0; e < _entries.Count; e++) { for (int a = 0; a < _entries[e].values.Count; a++) { var _type = System.Type.GetType(_entries[e].types[a]); var _instance = System.Activator.CreateInstance(_type) as DataboxType; // Convert csv string value to DataboxType value _instance.Convert(_entries[e].values[a]); _database.AddData(_tableName, _entries[e].entryName, _entries[e].fields[a], _instance as DataboxType); } } }
} // draw custom editor gui fields public virtual void DrawEditor(DataboxObject _databoxObject) { } // same as DrawEditor() but with additional DataboxObject parameter.
// Start is called before the first frame update public static void DrawCloudConfigUI(DataboxObject database) { using (new GUILayout.VerticalScope("Window")) { //if (GUILayout.Button("Remove Agreement")) //{ // EditorPrefs.DeleteKey("DataboxCloudAgreement"); //} #if UNITY_EDITOR DataboxEditor.cloudAgreementAccepted = EditorPrefs.GetBool("DataboxCloudAgreement"); #endif if (!DataboxEditor.cloudAgreementAccepted) { using (new GUILayout.VerticalScope("Box")) { GUI.color = Color.yellow; GUILayout.Label("Please accept this short agreement: "); GUI.color = Color.white; GUILayout.Label(DataboxEditor.cloudAgreement); DataboxEditor.cloudAgreementAccepted = GUILayout.Toggle(DataboxEditor.cloudAgreementAccepted, "Accept"); #if UNITY_EDITOR if (DataboxEditor.cloudAgreementAccepted) { EditorPrefs.SetBool("DataboxCloudAgreement", DataboxEditor.cloudAgreementAccepted); } #endif } } else { using (new GUILayout.VerticalScope("Box")) { // ONLY FOR DEBUG //GUILayout.Label("server time: " + DataboxCloud.serverTime); //GUILayout.Label("server version: " + DataboxCloud.serverVersion); //GUILayout.Label("database version: " + database.cloudVersion); GUILayout.Label("Cloud server url:"); database.cloudServer = GUILayout.TextField(database.cloudServer); GUILayout.Label("Unique Id: (only integer numbers)"); //database.cloudId = GUILayout.TextField(database.cloudId); if (!string.IsNullOrEmpty(database.cloudId)) { var _cloudId = int.Parse(database.cloudId); database.cloudId = GUIIntField.IntField(_cloudId).ToString(); } else { database.cloudId = "0"; } if (string.IsNullOrEmpty(database.cloudId)) { #if UNITY_EDITOR EditorGUILayout.HelpBox("Please enter an unique id", MessageType.Warning); #else GUILayout.Label("Please enter an unique id"); #endif } } if (!string.IsNullOrEmpty(database.cloudId)) { using (new GUILayout.HorizontalScope("Box")) { if (GUILayout.Button("1. Check")) { #if UNITY_EDITOR DataboxCloud.Check(database.cloudServer, database.cloudId, database); #else if (database.databoxCloudService == null) { database.databoxCloudService = new GameObject("DataboxCloudService").AddComponent <DataboxCloud>() as DataboxCloud; } DataboxCloud.CheckRuntime(database); #endif database.cloudCheck = true; } if ((database.cloudWarnings == DataboxObject.CloudWarnings.ok || database.cloudWarnings == DataboxObject.CloudWarnings.warning) && database.cloudCheck) { GUI.enabled = true; } else { GUI.enabled = false; } if (GUILayout.Button("2. Sync & Compare")) { #if UNITY_EDITOR DataboxCloud.Sync(database.cloudServer, database.cloudId, database); //databoxCloudInstance.Sync(database.cloudServer, database.cloudId, database); #else if (database.databoxCloudService == null) { database.databoxCloudService = new GameObject("DataboxCloudService").AddComponent <DataboxCloud>() as DataboxCloud; } DataboxCloud.SyncRuntime(database); #endif database.cloudCheck = false; } GUI.enabled = true; if (database.oldDB == null) { GUI.enabled = false; } else { if (database.oldDB.Keys.Count > 0) { if (DataboxEditor.deletedCompare.tables.Count > 0 || DataboxEditor.deletedCompare.entries.Count > 0 || DataboxEditor.deletedCompare.fields.Count > 0 || DataboxEditor.deletedCompare.values.Count > 0 || DataboxEditor.newCompare.tables.Count > 0 || DataboxEditor.newCompare.entries.Count > 0 || DataboxEditor.newCompare.fields.Count > 0 || DataboxEditor.newCompare.values.Count > 0) { GUI.enabled = true; } else { GUI.enabled = false; } } else { GUI.enabled = false; } } if (GUILayout.Button("3. Revert")) { database.DB = new OrderedDictionary <string, DataboxObject.Database>(); database.DB = database.DeepCopy <OrderedDictionary <string, DataboxObject.Database> >(database.oldDB); DataboxEditor.deletedCompare = new DataboxCloud.ChangeLog(); DataboxEditor.newCompare = new DataboxCloud.ChangeLog(); database.oldDB = new OrderedDictionary <string, DataboxObject.Database>(); database.cloudVersion = database.oldCloudVersion; database.cloudStatus += "- Reverted back to before sync" + "\n"; } GUI.enabled = true; } using (new GUILayout.HorizontalScope()) { if ((database.cloudWarnings == DataboxObject.CloudWarnings.ok || database.cloudWarnings == DataboxObject.CloudWarnings.warning) && database.cloudCheck) { GUI.enabled = true; } else { GUI.enabled = false; } if (GUILayout.Button("Force Upload")) { #if UNITY_EDITOR DataboxCloud.ForceUploadEditor(); #else if (database.databoxCloudService == null) { database.databoxCloudService = new GameObject("DataboxCloudService").AddComponent <DataboxCloud>() as DataboxCloud; } DataboxCloud.ForceUploadRuntime(database); #endif database.cloudCheck = false; } if (GUILayout.Button("Force Download")) { #if UNITY_EDITOR DataboxCloud.ForceDownloadEditor(); #else if (database.databoxCloudService == null) { database.databoxCloudService = new GameObject("DataboxCloudService").AddComponent <DataboxCloud>() as DataboxCloud; } DataboxCloud.ForceDownloadRuntime(database); #endif database.cloudCheck = false; } GUI.enabled = true; } } GUILayout.Label("Cloud status:"); switch (database.cloudWarnings) { case DataboxObject.CloudWarnings.ok: GUI.color = Color.green; break; case DataboxObject.CloudWarnings.warning: GUI.color = Color.yellow; break; case DataboxObject.CloudWarnings.error: GUI.color = Color.red; break; } using (new GUILayout.VerticalScope("Box")) { GUI.color = Color.white; GUILayout.Label(database.cloudStatus); } // COMPARE GUI GUILayout.Label("Changes to cloud version:"); var _changelog = ""; // DELETED // Tables if (DataboxEditor.deletedCompare != null) { GUI.color = Color.red; for (int m = 0; m < DataboxEditor.deletedCompare.tables.Count; m++) { //Debug.Log("deleted table: " + deletedCompare.tables[m]); using (new GUILayout.VerticalScope("Box")) { GUILayout.Label("deleted table: " + DataboxEditor.deletedCompare.tables[m]); } _changelog += "deleted table: " + DataboxEditor.deletedCompare.tables[m] + "\n"; } // Entries for (int m = 0; m < DataboxEditor.deletedCompare.entries.Count; m++) { //Debug.Log("deleted entry: " + deletedCompare.entries[m]); using (new GUILayout.VerticalScope("Box")) { GUILayout.Label("deleted entry: " + DataboxEditor.deletedCompare.entries[m]); } _changelog += "deleted entry: " + DataboxEditor.deletedCompare.entries[m] + "\n"; } // Values for (int m = 0; m < DataboxEditor.deletedCompare.fields.Count; m++) { //Debug.Log("deleted field: " + deletedCompare.fields[m]); using (new GUILayout.VerticalScope("Box")) { GUILayout.Label("deleted value: " + DataboxEditor.deletedCompare.fields[m]); } _changelog += "deleted value: " + DataboxEditor.deletedCompare.fields[m] + "\n"; } GUI.color = Color.white; } if (DataboxEditor.newCompare != null) { // NEW // Tables GUI.color = Color.green; for (int m = 0; m < DataboxEditor.newCompare.tables.Count; m++) { //Debug.Log("new table: " + newCompare.tables[m]); using (new GUILayout.VerticalScope("Box")) { GUILayout.Label("new table: " + DataboxEditor.newCompare.tables[m]); } _changelog += "new table: " + DataboxEditor.newCompare.tables[m] + "\n"; } // Entries for (int m = 0; m < DataboxEditor.newCompare.entries.Count; m++) { //Debug.Log("new entry: " + newCompare.entries[m]); using (new GUILayout.VerticalScope("Box")) { GUILayout.Label("new entry: " + DataboxEditor.newCompare.entries[m]); } _changelog += "new entry: " + DataboxEditor.newCompare.entries[m] + "\n"; } // Values for (int m = 0; m < DataboxEditor.newCompare.fields.Count; m++) { //Debug.Log("new fields: " + newCompare.fields[m]); using (new GUILayout.VerticalScope("Box")) { GUILayout.Label("new value: " + DataboxEditor.newCompare.fields[m]); } _changelog += "new value: " + DataboxEditor.newCompare.fields[m] + "\n"; } GUI.color = Color.white; //Modified GUI.color = Color.yellow; for (int m = 0; m < DataboxEditor.newCompare.values.Count; m++) { //Debug.Log("modified: " + newCompare.values[m]); using (new GUILayout.VerticalScope("Box")) { GUILayout.Label("modified value: " + DataboxEditor.newCompare.values[m]); } _changelog += "modified value: " + DataboxEditor.newCompare.values[m] + "\n"; } GUI.color = Color.white; } if (DataboxEditor.deletedCompare == null && DataboxEditor.newCompare == null) { using (new GUILayout.VerticalScope("Box")) { GUILayout.Label("none"); } } #if UNITY_EDITOR if (!string.IsNullOrEmpty(_changelog)) { if (GUILayout.Button("Save changelog to .txt file")) { var _path = EditorUtility.SaveFilePanel("Save to:", Application.dataPath, "changelog", ".txt"); if (!string.IsNullOrEmpty(_path)) { SaveChangelog(_path, _changelog); } } } #endif } } }
/// <summary> /// Import google sheet runtime coroutine /// </summary> /// <param name="database"></param> /// <param name="_importType"></param> /// <returns></returns> public void ImportFromGoogle(DataboxObject _database, DataboxGoogleSheetDownloader.ImportType _importType) { StartCoroutine(ImportFromGoogleIE(_database, _importType)); }
public override void DrawCustomInspector() { GUILayout.Label("Databox Object:"); databoxObject = (DataboxObject)EditorGUILayout.ObjectField(databoxObject, typeof(DataboxObject), false); }
/// <summary> /// Android runtime load coroutine /// </summary> /// <param name="_savePath"></param> /// <param name="_databoxObject"></param> /// <param name="_callEvent"></param> public void LoadCoroutine(string _savePath, DataboxObject _databoxObject, bool _callEvent) { StartCoroutine(LoadCoroutineIE(_savePath, _databoxObject, _callEvent)); }
/// <summary> /// same as DrawEditor() but with additional DataboxObject parameter. /// </summary> /// <param name="_databoxObject"></param> public virtual void DrawEditor(DataboxObject _databoxObject) { }
public bool editorOpen; // setting for runtime editor public DataboxObjects(string _id, DataboxObject _dataObject) { id = _id; dataObject = _dataObject; }
public MuteSettingObj(DataboxObject databoxObject, string tableName) : base(databoxObject, tableName) { }
IEnumerator ImportFromGoogleIE(DataboxObject database, DataboxGoogleSheetDownloader.ImportType _importType) { DataboxCSVConverter.firstTimeReplace = true; for (int i = 0; i < database.googleWorksheets.Count; i++) { var _url = database.googleSheetUrl; _url = FixURL(_url, database.googleWorksheets[i].id); UnityWebRequest _download = UnityWebRequest.Get(_url); yield return(_download.SendWebRequest()); while (_download.isDone == false) { yield return(null); } // handle an unknown internet error if (_download.isNetworkError || _download.isHttpError) { Debug.LogWarningFormat("Couldn't retrieve file at <{0}> and error message was: {1}", _download.url, _download.error); } else { // make sure the fetched file isn't just a Google login page if (_download.downloadHandler.text.Contains("google-site-verification")) { Debug.LogWarningFormat("Couldn't retrieve file at <{0}> because the Google Doc didn't have public link sharing enabled", _download.url); continue; } List <DataboxCSVConverter.Entry> entries = new List <DataboxCSVConverter.Entry>(); DataboxCSVConverter.ConvertCSV(_download.downloadHandler.text, out entries); yield return(new WaitForSeconds(1f)); switch (_importType) { case DataboxGoogleSheetDownloader.ImportType.Append: DataboxCSVConverter.AppendToDB(database, database.googleWorksheets[i].name, entries); break; case DataboxGoogleSheetDownloader.ImportType.Replace: DataboxCSVConverter.ReplaceDB(database, database.googleWorksheets[i].name, entries); break; } } _download.Dispose(); } if (database.OnImportFromGoogleComplete != null) { database.OnImportFromGoogleComplete(); } }