예제 #1
0
        void Start()
        {
            //be sure to use the same location you specified as Export Location in the Bundle Creator
            // or if this is in the web player, direct the path to your online folder where the bundles are uploaded
            //BundleCreator에서 추출하는 경로를 확인해라
            //만약 웹빌드를 하는것이면 너가 업로드할 온라인 경로를 기입해라
            //baseURL = Application.dataPath + "/../AssetBundles/";


            if (local)
            {
                baseURL = filePrefix + Application.dataPath + "/../AssetBundles/";
            }
            else
            {
                baseURL = "http://bubblemon.hs.llnwd.net/v1/bubblemon/qa1/AssetBundles/";
            }



            bool bFileExist = false;

            if (local)
            {
                bFileExist = File.Exists(baseURL + "logobundle_01.unity3d");
            }
            else
            {
                bFileExist = WebFileExists(baseURL + "logobundle_02.unity3d");
            }


            //Load the bundles
            //번들을 로드한다
            if (bFileExist)
            {
                //Load the two logo files stored in the bundle
                //번을에 포함되어있는 두개의 로고를 로드한다.
                LoadAssetFromBundle cryWolfLogo = this.gameObject.AddComponent <LoadAssetFromBundle>();
                cryWolfLogo.QueueBundleDownload("pre_cryWolfLogo", "logobundle_02.unity3d", 1);
                cryWolfLogo.baseURL = baseURL;

                LoadAssetFromBundle cryWolfLogoURL = this.gameObject.AddComponent <LoadAssetFromBundle>();
                cryWolfLogoURL.QueueBundleDownload("pre_cryWolfLogo_url", "logobundle_02.unity3d", 1);
                cryWolfLogoURL.baseURL = baseURL;

                //Add them to the download list
                //로드할 것들을 다운로드 리스트에 넣는다
                assetsToLoad.Add(cryWolfLogo);
                assetsToLoad.Add(cryWolfLogoURL);
            }
            else
            {
                //The file does not exist, you need to build the bundle first
                Debug.LogError("Bundles are not built! Open the Bundle Creator in Assets->BundleCreator>Asset Bundle Creator to build your bundles.");
            }
        }
예제 #2
0
        private string filePrefix = "file://"; // I use this prefix to show that i'm currently loading the bundle from my
        //local computer, if i were to load it from the web - this wouldn't be necessary.
        //컴퓨터로부터 로드할때. 만약 웹에서 로드한다면 이 변수는 굳이 사용할 필요는 없다

        void Start()
        {
            //This command ONLY works if you run in the editor, because i'm just getting whatever value I got stored in
            // the AssetBundleCreator as export folder.
            //이 커멘드는 에디터에서만 작동한다, 왜냐하면 어떤 값이든 AssetBundleCreator에있는 추출폴더에 저장할 것이기 때문이다

            //If I would want to load this from let's say an iPhone,
            //이를테면 아이폰에서 이것을 작동하고자 한다면

            // I would have to store them in a specific folder on the phone(Which wouldn't make any sense because I could just use Resources.Load instead.
            // 반드시 특정 폴더에 저장해야 한다(근데 이건 생각할 필요도 없는듯 하다, 왜냐하면 그냥 Resource.Load 메소드를 사용하면 되기 때문이다)

            // So the option on testing on the iOS device itself would either be from the editor like this,
            // 따라서 iOS기기에서 테스트할 수 있는 조건은 에디터와 같이 세팅하거나
            // OR store them online on a server and set the baseURL to its http address.
            // 그것을 온라인 서버에 저장해서 그 웹주소를 사용하는 것이다
            baseURL = filePrefix + Application.dataPath + PlayerPrefs.GetString("cws_exportFolder");

            //So.. on to the loading of the bundles.
            // 번들을 로드하자
            //When loading them this way, I put each "loading command" in a list
            //아래와 같은 방식으로 로딩할때, 매 로딩 커멘드를 목록에 넣어둘 것이다
            // That list is being checked and maintained in the Update() method.
            //그 목록은 Update함수에서 관리할 것이다
            //Whenever a download is complete, it instantiates it as a gameobject
            //다운로드가 끝나면 생성을 한다
            // and proceeds to the next bundle to download.
            // 그리고 그다음 작업을 진행한다

            //To do that, I create a new LoadAssetFromBundle component
            // 앞서이야기한 것을 하기위해 LoadAssetFromBundle 스크립트를 추가한다
            LoadAssetFromBundle myAssetToLoad = this.gameObject.AddComponent <LoadAssetFromBundle>();

            //I set the asset name, the name of the bundle, and the current version of the bundle
            //에셋의 이름과 번들이름과 버전을 기록한다
            myAssetToLoad.QueueBundleDownload("MY_ASSET_NAME", "MY_BUNDLE_NAME.unity3d", 1);

            //Then, I set the URL from where it should download the bundle
            //with the value I set in the beginning of Start()
            //에셋을 다운 받을 주소록 기입한다
            myAssetToLoad.baseURL = baseURL;

            //To start the download, I add them to the "things to download list"
            // and it will start the download in the Update() method.
            //다운로드를 시작할 때에 다운받을 목록을 작성한다
            //그뒤 update함수에서 다운로드를 시작한다
            assetsToLoad.Add(myAssetToLoad);

            //To load more than on asset this way, just create another LoadAssetFromBundle component
            // and make sure to add it to the assetsToLoad list.
            //추가로 다운을 받고자 하면 LoadAssetFromBundle 스크립트를 추가하고
            //목록에 넣으면 끝!
        }
예제 #3
0
        void Update()
        {
            if (assetsToLoad.Count > 0)
            {
                for (int i = (assetsToLoad.Count - 1); i >= 0; i--)
                {
                    LoadAssetFromBundle asset = assetsToLoad[i];
                    if (asset.IsDownloadDone)
                    {
                        //The download is done, instantiate the asset from the bundle
                        //다운로드가 완료 되면 번들에 있는 에셋을 생성한다
                        asset.InstantiateAsset();
                        //Remove the asset from the loading list
                        //다운로드 목록에 있는 에셋을 제거한다
                        assetsToLoad.RemoveAt(i);
                        //Destroy the LoadAssetFromBundle Script
                        //다운로드가 완료되었으므로 다운로드에 사용한 다운로드 스크립트를 제거한다
                        Destroy(asset);
                        //This means an asset is downloaded, which means you can start on the next one
                        //하나의 에셋이 다운로드 완료 되었으므로 다음 것을 다운 받을 준비가 되었다
                        isDownloaded = true;
                    }
                }

                if (isDownloaded) //The download is complete //에셋이 하나 다운로드되었다
                {
                    //Start the next download
                    //다음 에셋을 다운로드한다
                    foreach (LoadAssetFromBundle asset in assetsToLoad)
                    {
                        if (!asset.HasDownloadStarted)
                        {
                            //Start the download
                            //다운로드를 시작한다
                            asset.DownloadAsset();

                            //set the isDownloaded to false again
                            //다시 다운로드 플래그를 False로 바꾼다
                            isDownloaded = false;

                            //break the loop
                            //루프를 벗어난다
                            break;
                        }
                    }
                }
            }
            else //If there is nothing left to load, then destroy this game object //더이상 다운 받을 것이 없다면, 이 오브젝트를 제거한다
            {
                Destroy(this.gameObject);
            }
        }
        IEnumerator Start()
        {
            if (local)
            {
                baseURL = filePrefix + Application.dataPath + "/../AssetBundles/";
            }
            else if (baseURL == "")
            {
                switch (typeUrl)
                {
                case URL_TYPE.dev:
                    baseURL = baseUrlDev;
                    break;

                case URL_TYPE.qa:
                    baseURL = baseUrlQa;
                    break;

                case URL_TYPE.real:
                    baseURL = baseUrlReal;
                    break;
                }


                //baseURL = "http://bubblemon.hs.llnwd.net/v1/bubblemon/qa1/AssetBundles/";
            }


            string strVersionControlXml = "";

            // Set Version Control List
            using (WWW www = new WWW(baseURL + "bundleControlFile.xml"))
            {
                yield return(www);

                if (www.error != null)
                {
                    throw new System.Exception("XML - WWW download:" + www.error);
                }
                strVersionControlXml = www.text;
                Debug.Log(strVersionControlXml);

                www.Dispose();
            }

            if (strVersionControlXml != "")
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(strVersionControlXml);


                XmlNodeList bundles = xmlDoc.GetElementsByTagName("bundle");


                foreach (XmlNode bundle in bundles)
                {
                    int    nVersionNumber = System.Convert.ToInt32(bundle.Attributes["VersionNumber"].InnerText);
                    string strBundleName  = bundle.Attributes["BundleName"].InnerText;

                    if (strBundleName != null)
                    {
                        if (dicBundleVersion.ContainsKey(strBundleName))
                        {
                            dicBundleVersion[strBundleName] = nVersionNumber;
                        }
                        else
                        {
                            dicBundleVersion.Add(strBundleName, nVersionNumber);
                        }
                    }
                }
            }


            string strContentsXml = "";


            // Set Contents Information
            using (WWW www = new WWW(baseURL + "bundleContents.xml"))
            {
                yield return(www);

                if (www.error != null)
                {
                    throw new System.Exception("XML - WWW download:" + www.error);
                }
                strContentsXml = www.text;
                Debug.Log(strContentsXml);

                www.Dispose();
            }

            if (strContentsXml != "")
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(strContentsXml);


                XmlNodeList bundles = xmlDoc.GetElementsByTagName("bundle");

                int nTotalSize = 0;


                foreach (XmlNode bundle in bundles)
                {
                    int    nFileSize     = System.Convert.ToInt32(bundle.Attributes["FileSize"].InnerText);
                    int    nNumOfAssets  = System.Convert.ToInt32(bundle.Attributes["NumberOfAssets"].InnerText);
                    string strBundleName = bundle.Attributes["BundleName"].InnerText;

                    int nVersion = 0;
                    if (dicBundleVersion.ContainsKey(strBundleName))
                    {
                        nVersion = dicBundleVersion[strBundleName];
                    }



                    if (strBundleName != null && nVersion != 0)
                    {
                        nTotalSize += nFileSize;



                        foreach (XmlNode asset in bundle.ChildNodes)
                        {
                            if (asset.Name == "asset")
                            {
                                string strAssetName = asset.Attributes["AssetName"].InnerText;

                                bool bInstantiateWhenReady = strAssetName.GetExtentionFromPath() == "prefab";


                                LoadAssetFromBundle oLoadAsset = this.gameObject.AddComponent <LoadAssetFromBundle>();
                                oLoadAsset.baseURL = baseURL;
                                oLoadAsset.QueueBundleDownload(strAssetName.GetFilenameFromPath(), strBundleName, nVersion, bInstantiateWhenReady);
                                assetsToLoad.Add(oLoadAsset);
                            }
                        }


                        if (dicBundleSize.ContainsKey(strBundleName))
                        {
                            dicBundleSize[strBundleName] = nFileSize;
                        }
                        else
                        {
                            dicBundleSize.Add(strBundleName, nFileSize);
                        }
                    }
                }


                foreach (int nSize in dicBundleSize.Values)
                {
                    totalSize += nSize;
                }


                StartCoroutine(LoadContents());
            }
        }
        IEnumerator LoadContents()
        {
            while (assetsToLoad.Count > 0)
            {
                Dictionary <string, int> dicAssetForDownload = new Dictionary <string, int>();

                string strCurrentDnBundleName = "";

                int nDnFileSize     = 0;
                int nDnFileProgress = 0;

                for (int i = (assetsToLoad.Count - 1); i >= 0; i--)
                {
                    LoadAssetFromBundle asset = assetsToLoad[i];
                    if (asset.IsDownloadDone)
                    {
                        //다운로드가 완료 되면 번들에 있는 에셋을 생성한다
                        asset.InstantiateAsset();
                        //다운로드 목록에 있는 에셋을 제거한다
                        assetsToLoad.RemoveAt(i);
                        //다운로드가 완료되었으므로 다운로드에 사용한 다운로드 스크립트를 제거한다
                        Destroy(asset);
                        //하나의 에셋이 다운로드 완료 되었으므로 다음 것을 다운 받을 준비가 되었다
                        isDownloaded = true;
                    }
                    else
                    {
                        int nFileSize = dicBundleSize[asset.AssetBundleName];
                        nFileSize = (int)(nFileSize * (1.0f - asset.DownloadProgress));

                        if (dicAssetForDownload.ContainsKey(asset.AssetBundleName))
                        {
                            dicAssetForDownload[asset.AssetBundleName] = nFileSize;
                        }
                        else
                        {
                            dicAssetForDownload.Add(asset.AssetBundleName, nFileSize);
                        }


                        if (asset.HasDownloadStarted)
                        {
                            strCurrentDnBundleName = asset.AssetBundleName;
                            nDnFileSize            = nFileSize;
                            nDnFileProgress        = (int)(asset.DownloadProgress * 100.0f);
                        }
                    }
                }

                if (isDownloaded) //에셋이 하나 다운로드되었다
                {
                    //다음 에셋을 다운로드한다
                    foreach (LoadAssetFromBundle asset in assetsToLoad)
                    {
                        if (!asset.HasDownloadStarted)
                        {
                            //다운로드를 시작한다
                            asset.DownloadAsset();

                            //다시 다운로드 플래그를 False로 바꾼다
                            isDownloaded = false;

                            //루프를 벗어난다
                            break;
                        }
                    }
                }

                int nTotalRemainSize = 0;
                foreach (int nFilesize in dicAssetForDownload.Values)
                {
                    nTotalRemainSize += nFilesize;
                }

                //Broadcast to listener that progress changed
                DispatchEvent(UPDATE_DOWNLOADER, new FrameWork.Event.BasicEventArgs(totalSize, nTotalRemainSize, strCurrentDnBundleName, nDnFileProgress));
                Debug.Log(nTotalRemainSize);
                yield return(new WaitForSeconds(updateInterval));
            }

            //Destroy(this.gameObject);
        }