コード例 #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
ファイル: MyNewScript.cs プロジェクト: synsayer/synsayer
        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
        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());
            }
        }