예제 #1
0
        /// <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());
            }
        }
예제 #2
0
        /// <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);
            }
        }
예제 #3
0
        /// <summary>
        /// Log the specified data and obj.
        /// Warning is object null.
        /// </summary>
        /// <param name="data">Data.</param>
        /// <param name="obj">Object.</param>
        protected void LogLoadAsset(AssetBundleData data, object obj)
        {
            if (!debug)
            {
                return;
            }

            System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
            stringBuilder.AppendFormat("[AssetBundle] {0} [Version] {1} [Object name] {2} [Type] {3} ",
                                       data.assetBundleName,
                                       data.version,
                                       data.objName,
                                       data.type);

            if (obj == null)
            {
                stringBuilder.Append("is object null.");
                HDebug.LogWarning(stringBuilder.ToString());
            }
        }
예제 #4
0
        /// <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);
        }
예제 #5
0
        /// <summary>
        /// Plaies the sound.
        /// </summary>
        /// <param name="name">Name.</param>
        /// <param name="createCount">Create count.</param>
        public void PlaySound(string name, int createCount = ObjectPool.createCount)
        {
            if (sounds == null)
            {
                HDebug.LogWarning("Please add a " + name + " sound");
                return;
            }

            SoundData sound = sounds.Find(x => x.name == name);

            if (sound == null || sound.clip == null)
            {
                HDebug.LogWarning("Please add a " + name + " sound");
                return;
            }

            if (objectPool == null)
            {
                objectPool = new ObjectPool(this.sound.gameObject, gameObject, createCount);
            }

            objectPool.GetObject().GetComponent <Sound> ().Play(sound.clip);
        }
예제 #6
0
        /// <summary>
        /// Loadings the job.
        /// </summary>
        /// <param name="data">Data.</param>
        /// <param name="popUp">If set to <c>true</c> pop up.</param>
        /// <param name="active">Active.</param>
        /// <param name="deactive">Deactive.</param>
        public virtual void LoadingJob(LoadingJobData data, bool popUp, SceneCallbackDelegate active = null, SceneCallbackDelegate deactive = null)
        {
            if (LoadingJobSceneName == "")
            {
                HDebug.LogWarning("The default loading job scene is not set");
                return;
            }

            data.popUp = popUp;
            if (popUp)
            {
                if (!data.active)
                {
                    shieldAlpha = 0f;
                }

                PopUp(LoadingJobSceneName, data, active, deactive);
            }
            else
            {
                Screen(LoadingJobSceneName, data, active, deactive);
            }
        }
예제 #7
0
        /// <summary>
        /// Invoke the specified iDic, obj and flag.
        /// </summary>
        /// <param name="iDic">IDictionary.</param>
        /// <param name="obj">Object.</param>
        /// <param name="flag">BindingFlags.</param>
        public static void Invoke(IDictionary iDic, object obj, BindingFlags flag = BindingFlags.NonPublic)
        {
            if (obj == null)
            {
                return;
            }

            if (iDic == null)
            {
                return;
            }

            foreach (object o in iDic.Keys)
            {
                IList       asList = null;
                IDictionary asDic  = null;
                string      field  = o.ToString();
                object      data   = iDic [field];
                Type        type   = GetFieldType(obj, field, flag);

                if (type == null)
                {
                    continue;
                }

                if (data == null)
                {
                    continue;
                }
                else if ((asList = data as IList) != null)
                {
                    object value   = GetFieldVale(obj, field, flag);
                    Type   element = type.GetElementType();
                    if (element == null)
                    {
                        element = type.GetGenericArguments() [0];
                    }

                    if (value != null)
                    {
                        if (Util.IsValueType(element))
                        {
                            data = CreateArrayInstance(asList, element);
                        }
                        else
                        {
                            Invoke(asList, value, flag);
                            continue;
                        }
                    }
                    else
                    {
                        object[] datas = Convert <object> (asList, flag, element);
                        if (element == null)
                        {
                            element = type.GetGenericArguments() [0];
                            IList iList = CreateIListInstance(element);

                            for (int i = 0; i < datas.Length; i++)
                            {
                                iList.Add(System.Convert.ChangeType(datas [i], element));
                            }

                            data = iList;
                        }
                        else
                        {
                            data = CreateArrayInstance(new List <object> (datas), element);
                        }
                    }
                }
                else if ((asDic = data as IDictionary) != null)
                {
                    object value = GetFieldVale(obj, field, flag);
                    if (value == null)
                    {
                        data = Convert <object> (asDic, null, flag, type);
                    }
                    else
                    {
                        Invoke(asList, value, flag);
                        continue;
                    }
                }

                if (data == null)
                {
                    continue;
                }

                if (type != data.GetType())
                {
                    try {
                        data = System.Convert.ChangeType(data, type);
                    } catch (Exception e) {
                        HDebug.LogWarning(string.Format("{0}\nclass : {1}, field : {2}", e.Message, obj, field));
                        continue;
                    }
                }

                if (flag == BindingFlags.NonPublic)
                {
                    SetPrivateFieldInvoke(obj, field, data);
                }
                else
                {
                    SetFieldInvoke(obj, field, data);
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Simples the migration.
        /// </summary>
        /// <param name="force">If set to <c>true</c> force.</param>
        public void SimpleMigration(bool force = true)
        {
            // StreamingAssets folder
            string path = Path.Combine(Application.streamingAssetsPath, Path.GetFileName(pathDB));

            if (path.Contains("://"))    // android
            {
                WWW www = new WWW(path);
                while (!www.isDone)
                {
                    ;
                }

                if (www.error == null)
                {
                    path = string.Format("{0}_copy{1}", Path.GetFileNameWithoutExtension(path), Path.GetExtension(path));
                    path = Path.Combine(Application.persistentDataPath, path);
                    File.WriteAllBytes(path, www.bytes);
                }
                else
                {
                    HDebug.LogWarning(www.error);
                    return;
                }

                path = Path.GetFileName(path);
            }

            Query query = new Query(path);

            SqliteMastser[]      resources = query.SELECT <SqliteMastser> ();
            List <SqliteMastser> list      = new List <SqliteMastser> (resources);

            query = new Query(pathDB);
            SqliteMastser[] masters = query.SELECT <SqliteMastser> ();

            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < masters.Length; i++)
            {
                SqliteMastser master = list.Find(x => x.Name == masters [i].Name);
                if (master != null)
                {
                    list.Remove(master);
                }

                if (force)
                {
                    if (master != null)
                    {
                        if (masters [i].Sql != master.Sql)
                        {
                            stringBuilder.Append(query.GenerateDropTableSQL(master.Name));
                            stringBuilder.AppendLine();
                            stringBuilder.AppendFormat("{0};", master.Sql);
                            stringBuilder.AppendLine();
                        }
                    }
                    else
                    {
                        stringBuilder.Append(query.GenerateDeleteSQL(masters [i].Name));
                        stringBuilder.AppendLine();
                    }
                }
            }

            if (list.Count > 0)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    stringBuilder.AppendFormat("{0};", list [i].Sql);
                    stringBuilder.AppendLine();
                }
            }

            if (stringBuilder.ToString() != "")
            {
                query.ExecuteNonQuery(stringBuilder.ToString());
            }

            if (path.Contains("://"))    // android
            {
                File.Delete(path);
            }
        }
예제 #9
0
        /// <summary>
        /// Request the specified data and post.
        /// </summary>
        /// <param name="data">HttpData.</param>
        /// <param name="post">If set to <c>true</c> post.</param>
        public void Request(HttpData data, Http.FinishedDelegate finish = null)
        {
            time = Time.time;

            Action innerRequest = () => {
                if (preReuqest != null)
                {
                    data = preReuqest(data);
                }

                this.data = data;
                Http http;

#if UNITY_5_4_OR_NEWER
                if (data.method == UnityWebRequest.kHttpVerbPOST)
                {
#else
                if (data.post)
                {
#endif

                    http = new Http(this, data.url);
                    http.AddRangeData(data.datas);
                }
                else
                {
                    http = new Http(this, data.url, data.datas);
                }

#if UNITY_5_4_OR_NEWER
                http.method    = data.method;
                http.audioType = data.audioType;

                http.OnFail = (UnityWebRequest www) => {
                    this.www = www;
                    OnFail();
                };

                http.OnDisposed = (UnityWebRequest www) => {
                    this.www = www;
                    OnDisposed();
                };

                http.OnDone = (UnityWebRequest www) => {
                    this.www = www;
                    OnDone();
                };
#else
                http.OnFail = (WWW www) => {
                    this.www = www;
                    OnFail();
                };

                http.OnDisposed = (WWW www) => {
                    this.www = www;
                    OnDisposed();
                };

                http.OnDone = (WWW www) => {
                    this.www = www;
                    OnDone();
                };
#endif

                // set headers
                http.Headers = data.headers;

                // set timeout time
                http.Timeout = data.timeout;

                http.Request();
            };

            if (finish != null)
            {
                data.finishedDelegate = finish;
            }

            if (data.popUp)
            {
                if (SceneManager.Instance.DefaultLoadingJobSceneName != "")
                {
                    if (SceneManager.Instance.IsLoadingJob)
                    {
                        HDebug.LogWarning("Now loading scene active");
                    }

                    SceneManager.Instance.PopUp(SceneManager.Instance.DefaultLoadingJobSceneName, null, delegate(SSceneController ctrl) {
                        popUp = ctrl;
                        innerRequest();
                    });
                }
                else
                {
                    HDebug.LogWarning("The default loading scene is not set");
                }
            }
            else
            {
                innerRequest();
            }
        }
예제 #10
0
        /// <summary>
        /// Convert the specified dic, fieldInfo, flag and type.
        /// </summary>
        /// <param name="dic">Dic.</param>
        /// <param name="fieldInfo">Field info.</param>
        /// <param name="flag">Flag.</param>
        /// <param name="type">Type.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public static T Convert <T> (IDictionary dic, List <FieldInfo> fieldInfos = null, BindingFlags flag = BindingFlags.NonPublic, Type type = null)
        {
            if (dic == null)
            {
                return(default(T));
            }

            object obj = (T)Activator.CreateInstance(typeof(T), null);

            if (type != null)
            {
                obj = Activator.CreateInstance(type, null);
            }

            if (fieldInfos == null)
            {
                fieldInfos = GetFields(obj.GetType(), flag);
            }

            foreach (FieldInfo field in fieldInfos)
            {
                if (!dic.Contains(field.Name))
                {
                    continue;
                }

                object data = dic [field.Name];
                data = ConvertIgnoreData(field, data);

                if (field.FieldType.IsClass && field.FieldType != typeof(String))
                {
                    if (Util.IsArray(field.FieldType))
                    {
                        IList iList   = (IList)data;
                        Type  element = field.FieldType.GetElementType();
                        if (element == null)
                        {
                            Type[] types = field.FieldType.GetGenericArguments();
                            if (types.Length <= 0)
                            {
                                continue;
                            }

                            element = types [0];
                        }

                        if (Util.IsValueType(element))
                        {
                            field.SetValue(obj, CreateArrayInstance(iList, element));
                        }
                        else
                        {
                            data = Convert <object> (iList, flag, element);
                            Array someArray = data as Array;
                            if (someArray == null)
                            {
                                continue;
                            }

                            if (field.FieldType.GetElementType() == null)    // list
                            {
                                iList = CreateIListInstance(element);
                                for (int i = 0; i < someArray.Length; i++)
                                {
                                    iList.Add(System.Convert.ChangeType(someArray.GetValue(i), element));
                                }

                                field.SetValue(obj, iList);
                            }
                            else     // array
                            {
                                Array filledArray = Array.CreateInstance(element, someArray.Length);
                                Array.Copy(someArray, filledArray, someArray.Length);

                                field.SetValue(obj, filledArray);
                            }
                        }

                        continue;
                    }
                    else
                    {
                        IDictionary      iDic   = (IDictionary)data;
                        List <FieldInfo> fields = GetFields(field.FieldType, flag);
                        data = Convert <object> (iDic, fields, flag, field.FieldType);
                    }
                }

                if (data == null)
                {
                    continue;
                }

                if (field.FieldType != data.GetType())
                {
                    try {
                        data = System.Convert.ChangeType(data, field.FieldType);
                    } catch (Exception e) {
                        HDebug.LogWarning(string.Format("{0}\nclass : {1}, field : {2}", e.Message, obj, field.Name));
                        continue;
                    }
                }

                field.SetValue(obj, data);
            }

            return((T)obj);
        }
예제 #11
0
        /// <summary>
        /// Loads the asset bundle.
        /// </summary>
        /// <param name="data">Data.</param>
        /// <param name="finished">Finished.</param>
        public void LoadAssetBundle(AssetBundleData data, AssetBundleClient.FinishedDelegate finished)
        {
            System.Action InnerLoadAssetBundle = () => {
                System.Action InnerLoadAsset = () => {
                    if (data.objName == string.Empty)
                    {
                        HDebug.LogWarning("Set the object name in the assetbundle.");
                        finished(null);
                        return;
                    }

                    if (data.async)
                    {
                        StartCoroutine(LoadAssetAsync(data, finished));
                    }
                    else
                    {
                        LoadAsset(data, finished);
                    }
                };

                DownloadAssetBundle(data, delegate(object obj) {
                    data.assetBundle = assetBundleClient.GetAssetBundle(data.url, data.version);
                    if (data.assetBundle != null)
                    {
                        InnerLoadAsset();
                    }
                });
            };

//          HDebug.Log (data.assetBundleName + " / " + data.objName);
#if UNITY_EDITOR
            if (SceneManager.Instance.EditorLocalLoadAssetBundle)
            {
                string[] paths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(data.assetBundleName, data.objName);
                string   path  = "";
                if (paths.Length <= 0)
                {
                    paths = AssetDatabase.GetAssetPathsFromAssetBundle(data.assetBundleName);
                    if (paths.Length <= 0)
                    {
                        InnerLoadAssetBundle();
                        return;
                    }

                    string[] files = Directory.GetFiles(paths [0], data.objName + ".*");
                    if (files.Length <= 0)
                    {
                        InnerLoadAssetBundle();
                        return;
                    }

                    path = files [0];
                }
                else
                {
                    path = paths [0];
                }

                object temp = AssetDatabase.LoadMainAssetAtPath(path);
                if (data.type == typeof(Sprite))
                {
                    temp = Util.TextureConvertSprite(temp);
                }

                if (Path.GetFileNameWithoutExtension(path) != data.objName)
                {
                    temp = null;
                }

                LogLoadAsset(data, temp);
                finished(temp);
            }
            else
            {
                InnerLoadAssetBundle();
            }
#else
            InnerLoadAssetBundle();
#endif
        }
예제 #12
0
        /// <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);
        }