/// <summary> /// Debug the specified data and www. /// </summary> /// <param name="data">Data.</param> /// <param name="www">Www.</param> protected void LogDownload(AssetBundleData data, object obj) { if (obj == null) { return; } time = Time.time - time; if (!debug) { return; } System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); stringBuilder.AppendFormat("[Download time] {0}\n[URL] {1}\n[Version] {2}\n", time, data.url, data.version); #if UNITY_5_4_OR_NEWER UnityEngine.Networking.UnityWebRequest www = obj as UnityEngine.Networking.UnityWebRequest; #else WWW www = obj as WWW; #endif if (www.error != null) { stringBuilder.AppendFormat("[WWW.error]\n{0}\n", www.error); HDebug.LogError(stringBuilder.ToString()); } else { HDebug.Log(stringBuilder.ToString()); } }
/// <summary> /// Executes the non query. /// </summary> /// <param name="query">Query.</param> public void ExecuteNonQuery(string query) { if (!canQuery) { HDebug.LogWarning("Can't execute the query, verify DB origin file"); return; } if (!isConnectionOpen) { Open(pathDB); } #if !UNITY_WEBPLAYER if ((ConnectionState)dbconn.State != ConnectionState.Open) { HDebug.LogWarning("Sqlite DB is not open"); return; } dbcmd.CommandText = query; try { dbcmd.ExecuteNonQuery(); } catch (Exception e) { HDebug.Log("Query : " + query); HDebug.LogError(e.Message); return; } #endif if (!isConnectionOpen) { Close(); } }
/// <summary> /// Executes the query. /// </summary> /// <returns>The query.</returns> /// <param name="query">Query.</param> public DataTable ExecuteQuery(string query) { if (!canQuery) { HDebug.LogWarning("Can't execute the query, verify DB origin file"); return(null); } if (!isConnectionOpen) { Open(pathDB); } #if !UNITY_WEBPLAYER if ((ConnectionState)dbconn.State != ConnectionState.Open) { HDebug.LogWarning("Sqlite DB is not open"); return(null); } dbcmd.CommandText = query; try { reader = dbcmd.ExecuteReader(); } catch (Exception e) { HDebug.Log("Query : " + query); HDebug.LogError(e.Message); return(null); } #endif DataTable dataTable = new DataTable(); #if !UNITY_WEBPLAYER for (int i = 0; i < reader.FieldCount; i++) { dataTable.Columns.Add(reader.GetName(i)); } while (reader.Read()) { DataRow row = new DataRow(); for (int i = 0; i < reader.FieldCount; i++) { row.Add(reader.GetName(i), reader.GetValue(i)); } dataTable.Rows.Add(row); } #endif if (!isConnectionOpen) { Close(); } return(dataTable); }
/// <summary> /// Initializes a new instance of the <see cref="Hellgate.Sqlite"/> class. /// The DB name '/' Do not put /// Data Base name. (the file needs exist in the streamingAssets folder) /// </summary> /// <param name="db">DB name && path.</param> /// <param name="resetDB">reset DB.</param> public Sqlite(string db, bool resetDB = false) { canQuery = true; if (db.Contains("/")) { pathDB = db; return; } pathDB = Path.Combine(Application.persistentDataPath, db); #if !UNITY_WEBPLAYER // StreamingAssets folder string resourcePath = Path.Combine(Application.streamingAssetsPath, db); #if UNITY_EDITOR AutoDDL(db, false); #endif if (!File.Exists(pathDB) || resetDB) { if (resourcePath.Contains("://")) // android { WWW www = new WWW(resourcePath); while (!www.isDone) { ; } if (www.error == null) { File.WriteAllBytes(pathDB, www.bytes); } else { canQuery = false; HDebug.LogWarning(www.error); } } else { if (File.Exists(resourcePath)) { File.Copy(resourcePath, pathDB, true); } else { canQuery = false; HDebug.LogError("The file DB named " + db + " doesn't exist in the StreamingAssets Folder, please copy it there."); } } } #endif }
/// <summary> /// Commit this DB. /// </summary> public void Commit() { #if !UNITY_WEBPLAYER try { dbtrans.Commit(); } catch { try { dbtrans.Rollback(); } catch (Exception e) { HDebug.LogError(e.Message); } } #endif Close(); }
/// <summary> /// Debug the specified data and www. /// warring is timeover /// </summary> /// <param name="data">Data.</param> /// <param name="www">Www.</param> protected void Log() { time = Time.time - time; if (!debug) { return; } System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); stringBuilder.AppendFormat("[Request time] {0}\n[URL] {1}\n", time, data.url); if (data.headers != null) { stringBuilder.Append("[WWWForm.headers]\n"); foreach (KeyValuePair <string, string> pair in data.headers) { stringBuilder.AppendFormat("{0} : {1}\n", pair.Key, pair.Value); } stringBuilder.Append("\n"); } if (data.headers != null) { stringBuilder.Append("[WWWForm.data]\n"); foreach (KeyValuePair <string, string> pair in data.datas) { stringBuilder.AppendFormat("{0} : {1}\n", pair.Key, pair.Value); } stringBuilder.Append("\n"); } if (www == null) { HDebug.LogWarning(stringBuilder.ToString()); } else if (www.error != null) { stringBuilder.AppendFormat("[WWW.error]\n{0}\n", www.error); HDebug.LogError(stringBuilder.ToString()); } else { HDebug.Log(stringBuilder.ToString()); } }
/// <summary> /// Gets the name of the table. /// </summary> /// <returns>The table name.</returns> /// <param name="type">Type.</param> public static string GetTableName(Type type) { TableAttribute table = type.GetAttributeValue <TableAttribute> (); if (table == null) { HDebug.LogError("Not set the table attribute."); return(""); } else if (table.TableName == "") { return(type.Name); } else { return(table.TableName); } }
/// <summary> /// Creates the Sqlite db file. /// </summary> /// <param name="db">DB Name or Path.</param> /// <param name="resetDB">If set to <c>true</c> Reset Db.</param> public bool CreateFile(string db, bool resetDB = false) { string path = Application.streamingAssetsPath; string file = db; if (db.Contains("/")) { path = Path.GetDirectoryName(db); } else { file = Path.Combine(path, db); } if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (!resetDB) { if (File.Exists(file)) { return(false); } } #if !UNITY_WEBPLAYER try { SqliteConnection.CreateFile(file); } catch (Exception e) { HDebug.LogError(e.Message); return(false); } #endif pathDB = file; UnityEditor.AssetDatabase.Refresh(); return(true); }
/// <summary> /// Loads the level. /// </summary> /// <param name="loadLevelData">Load level data.</param> protected virtual void LoadLevel(LoadLevelData loadLevelData) { switch (loadLevelData.type) { case SceneType.Popup: case SceneType.Screen: case SceneType.AddScreen: if (scenes.ContainsKey(loadLevelData.sceneName)) { GameObject root = scenes [loadLevelData.sceneName]; if (!root.activeSelf) { if (loadLevelData.type == SceneType.Popup) { DistancePopUp(root); popups.Push(loadLevelData.sceneName); } if (loadLevelData.type != SceneType.Popup) { ClearScene(loadLevelData.sceneName); } if (loadLevelData.type == SceneType.AddScreen) { screens.Push(loadLevelData.sceneName); } } OnActiveScreen(root); SSceneController ctrl = root.GetComponent <SSceneController> (); ctrl.OnReset(loadLevelData.data); return; } // ugui if (uIType == UIType.UGUI) { if (loadLevelData.type != SceneType.Popup) { ClearEventSystem(loadLevelData.sceneName); } } break; case SceneType.Menu: if (menus.ContainsKey(loadLevelData.sceneName)) { GameObject root = menus [loadLevelData.sceneName]; OnActiveScreen(root); return; } break; } bool isAddtive = false; if (loadLevelData.type == SceneType.Menu || loadLevelData.type == SceneType.Popup) { isAddtive = true; } SSceneApplication.LoadLevel(loadLevelData.sceneName, delegate(GameObject root) { root.transform.parent = scene.transform; root.transform.localPosition = Vector3.zero; SSceneRoot sRoot = root.GetComponent <SSceneRoot> (); foreach (Camera cam in sRoot.Cameras) { AudioListener audio = cam.GetComponent <AudioListener> (); if (audio != null) { audio.enabled = false; } // ngui if (uIType == UIType.NGUI) { if (nGUICamera == null) { if (cam.GetComponent("UICamera") != null) { cam.clearFlags = CameraClearFlags.Depth; nGUICamera = Instantiate(cam.gameObject) as GameObject; nGUICamera.name = "UICamera"; nGUICamera.transform.parent = gCamera.transform; nGUICamera.transform.localPosition = Vector3.zero; nGUICamera.SetActive(true); cam.gameObject.SetActive(false); } } else { if (loadLevelData.type != SceneType.Popup && cam.GetComponent("UICamera") != null) { cam.gameObject.SetActive(false); } } } } if (sRoot.EventSystem != null) { eventSystem = sRoot.EventSystem.gameObject; } SSceneController ctrl = root.GetComponent <SSceneController> (); if (ctrl == null) { HDebug.LogError("No SceneController."); return; } ctrl.active = loadLevelData.active; ctrl.deactive = loadLevelData.deactive; switch (loadLevelData.type) { case SceneType.Screen: case SceneType.AddScreen: ctrl.OnSet(loadLevelData.data); scenes.Add(loadLevelData.sceneName, root); ClearScene(loadLevelData.sceneName); if (screenStartChange != null) { screenStartChange(loadLevelData.sceneName); } if (loadLevelData.type == SceneType.AddScreen) { screens.Push(loadLevelData.sceneName); } break; case SceneType.Popup: scenes.Add(loadLevelData.sceneName, root); DistancePopUp(root); popups.Push(loadLevelData.sceneName); ctrl.OnSet(loadLevelData.data); if (popUpStart != null) { popUpStart(loadLevelData.sceneName); } break; case SceneType.Menu: ctrl.OnSet(loadLevelData.data); menus.Add(loadLevelData.sceneName, root); if (menuStart != null) { menuStart(loadLevelData.sceneName); } break; } if (uIType == UIType.NGUI) // ngui { if (nGUICamera != null) { MonoBehaviour uicam = nGUICamera.GetComponent <MonoBehaviour> (); uicam.enabled = false; uicam.enabled = true; } } }, isAddtive); }