コード例 #1
0
        public static void GoMain()
        {
            string[] sprites = new string[] {
                "DarkGrey_Box128x128Measured", "DarkGrey_TrimmedBox128x128", "DarkGrey_Angle128x128",
                "LightGrey_Box128x128Measured", "LightGrey_TrimmedBox128x128", "LightGrey_Angle128x128",
                "Orange_Box128x128Measured", "Orange_TrimmedBox128x128", "Orange_Angle128x128"
            };

            LoadingJobData jobData = new LoadingJobData ("HellgateMain");

            List<AssetBundleData> assetBundles = new List<AssetBundleData> ();

            for (int i = 0; i < sprites.Length; i++) {
                AssetBundleData aBD = new AssetBundleData ("hellgatemain");
                aBD.type = typeof(Sprite);
                aBD.objName = sprites [i];
                assetBundles.Add (aBD);
            }

            jobData.assetBundles = assetBundles;
            jobData.PutExtra ("title", "Main");

            SceneManager.Instance.LoadingJob (jobData);
        }
コード例 #2
0
        public void OnClickSound()
        {
            string[] sounds = new string[] {
                "bgm2", "sound1", "sound2"
            };

            List<AssetBundleData> assetBundles = new List<AssetBundleData> ();

            for (int i = 0; i < sounds.Length; i++) {
                AssetBundleData aBD = new AssetBundleData ("hellgatesound");
                aBD.type = typeof(AudioClip);
                aBD.objName = sounds [i];
                assetBundles.Add (aBD);
            }

            LoadingJobData jobData = new LoadingJobData ();
            jobData.assetBundles = assetBundles;

            jobData.finishedDelegate = delegate(List<object> obj, LoadingJobController job) {
                List<AudioClip> clips = obj.GetListObjects<AudioClip> ();
                for (int i = 0; i < clips.Count; i++) {
                    if (clips [i].name == "bgm2") {
                        SoundManager.Instance.AddBGM (clips [i]);
                    } else {
                        SoundManager.Instance.AddSound (clips [i]);
                    }
                }

                SoundManager.Instance.PlayBGM ("bgm2");
                SceneManager.Instance.Close (delegate() {
                    SceneManager.Instance.PopUp ("The bgm and menu sound has been set.", PopUpType.Ok);
                });
            };

            SceneManager.Instance.LoadingJob (jobData);
        }
コード例 #3
0
        public void OnClickSprite()
        {
            string[] loads = new string[] {
                "Inventory_Arrow", "Inventory_Bone"
            };

            System.Random ran = new System.Random ();

            AssetBundleData data = new AssetBundleData ("hellgateasset");
            data.objName = loads [ran.Next (0, loads.Length)];
            data.type = typeof(Sprite);

            AssetBundleManager.Instance.LoadAssetBundle (data, delegate(object obj) {
                Sprite temp = obj as Sprite;
                Set2DSpriteValue (sprites [1], temp);
            });
        }
コード例 #4
0
        public void OnClickPrefab()
        {
            string[] loads = new string[] {
                "CubeGreen", "CubeYellow"
            };

            List<AssetBundleData> datas = new List<AssetBundleData> ();
            for (int i = 0; i < loads.Length; i++) {
                AssetBundleData data = new AssetBundleData ("hellgateasset", loads [i]);
                datas.Add (data);
            }

            AssetBundleManager.Instance.LoadAssetBundle (datas, delegate(object obj) {
                List<object> objs = obj as List<object>;
                cubes = Util.GetListObjects<GameObject> (objs);

                System.Random ran = new System.Random ();

                Vector3 position = Vector3.zero;
                if (SceneManager.Instance._UIType == UIType.NGUI) {
                    position = CameraUtil.GetViewportToWorldPoint (containers [1].gameObject, mCam);
                } else {
                    position = containers [1].gameObject.transform.position;
                }

                GameObject cube = Instantiate (cubes [ran.Next (0, loads.Length)]) as GameObject;
                cube.transform.localPosition = position;
                cube.transform.parent = gObj.transform;

                StartCoroutine (DelayDestory (cube));
            });
        }
コード例 #5
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 Log(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 ());
            }
        }
コード例 #6
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
        }
コード例 #7
0
        /// <summary>
        /// Loads the asset async.
        /// </summary>
        /// <returns>The asset async.</returns>
        /// <param name="data">Data.</param>
        /// <param name="finished">Finished.</param>
        protected IEnumerator LoadAssetAsync(AssetBundleData data, AssetBundleClient.FinishedDelegate finished)
        {
            AssetBundleRequest request = data.assetBundle.LoadAssetAsync (data.objName, data.type);
            yield return request;

            object obj = request.asset as object;
            if (data.type == typeof(Sprite)) {
                obj = Util.TextureConvertSprite (obj);
            }

            Log (data, obj);
            finished (obj);
        }
コード例 #8
0
        /// <summary>
        /// Debug the specified data and www.
        /// </summary>
        /// <param name="data">Data.</param>
        /// <param name="www">Www.</param>
        protected void Log(AssetBundleData data, WWW www)
        {
            time = Time.time - time;

            if (!debug) {
                return;
            }

            System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder ();
            stringBuilder.AppendFormat ("[Download time] {0}\n[WWW.LoadFromCacheOrDownload] {1}\n[Version] {2}\n", time, data.url, data.version);

            if (www.error != null) {
                stringBuilder.AppendFormat ("[WWW.error]\n{0}\n", www.error);
                HDebug.LogError (stringBuilder.ToString ());
            } else {
                HDebug.Log (stringBuilder.ToString ());
            }
        }
コード例 #9
0
        /// <summary>
        /// Loads the asset.
        /// </summary>
        /// <param name="data">Data.</param>
        /// <param name="finished">Finished.</param>
        protected void LoadAsset(AssetBundleData data, AssetBundleClient.FinishedDelegate finished)
        {
            object obj = data.assetBundle.LoadAsset (data.objName, data.type) as object;
            if (data.type == typeof(Sprite)) {
                obj = Util.TextureConvertSprite (obj);
            }

            Log (data, obj);
            finished (obj);
        }
コード例 #10
0
 /// <summary>
 /// Loads the asset bundle.
 /// </summary>
 /// <param name="list">List.</param>
 /// <param name="finished">Finished.</param>
 public void LoadAssetBundle(AssetBundleData[] list, AssetBundleClient.FinishedDelegate finished)
 {
     LoadAssetBundle (new List<AssetBundleData> (list), finished);
 }
コード例 #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);
                    }
                };

                if (data.assetBundle == null) {
                    data.assetBundle = assetBundleClient.GetAssetBundle (data.url, data.version);
                    if (data.assetBundle == null) {
                        DownloadAssetBundle (data, delegate(object obj) {
                            WWW www = obj as WWW;
                            if (www.error != null) {
                                return;
                            } else {
                                data.assetBundle = assetBundleClient.GetAssetBundle (data.url, data.version);
                            }

                            InnerLoadAsset ();
                        });
                    } else {
                        InnerLoadAsset ();
                    }
                } else {
                    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;
                }

                Log (data, temp);
                finished (temp);
            } else {
                InnerLoadAssetBundle ();
            }
            #else
            InnerLoadAssetBundle ();
            #endif
        }
コード例 #12
0
        /// <summary>
        /// Downloads the asset bundle.
        /// </summary>
        /// <param name="data">Data.</param>
        /// <param name="finished">Finished.</param>
        public void DownloadAssetBundle(AssetBundleData data, AssetBundleClient.FinishedDelegate finished)
        {
            time = Time.time;

            StartCoroutine (assetBundleClient.DownloadAssetBundle (data.url, data.version, delegate(object obj) {
                Log (data, obj as WWW);

                if (finished != null) {
                    finished (obj);
                }
            }));
        }
コード例 #13
0
        /// <summary>
        /// Downloads the asset bundle.
        /// </summary>
        protected void DownloadAssetBundle()
        {
            string name = downloads [index].Name;
            int version = downloads [index]._Version;

            AssetBundleData aBD = new AssetBundleData (name, version);
            assetBundleManager.DownloadAssetBundle (aBD, delegate(object obj) {
                Register.SetInt (name, version);
                index++;

                if (index < downloads.Count) {
                    DownloadAssetBundle ();
                } else {
                    Register.SetInt (assetBundleData._Resource.Name + AssetBundleInitialData.MAJOR, assetBundleData._Resource.Major);
                    Register.SetInt (assetBundleData._Resource.Name + AssetBundleInitialData.MINOR, assetBundleData._Resource.Minor);

                    if (aEvent != null) {
                        aEvent (AssetBundleInitalStatus.DownloadOver);
                    }
                }
            });
        }