Example #1
0
        /// <summary>
        /// Adds the bundle for non prefabs
        /// </summary>
        public void AddBundleForNonIntantiatable(string bundleName, AssetBundle assetBundle)
        {
            //Check if the assetbundle already has a container in the dictionary
            //사전에 이미 에셋번들이 포함되어있는지 체크한다
            if (!assetBundles.ContainsKey(bundleName))
            {
                //Create a new container and store the referenced game object
                //새로운 아이템을 추가한다
                AssetBundleContainer bundleContainer = new AssetBundleContainer();
                bundleContainer.ThisAssetBundle = assetBundle;
                bundleContainer.BundleName      = bundleName;

                // Make Container is not unload auto, becase it is possible to contain null object list
                bundleContainer.AutoUnload = false;


                assetBundles.Add(bundleName, bundleContainer);
            }
            else
            {
                //if the key exists, get the container and add the referenced object to its list.
                //이미 키 값이 있는 경우, 컨테이너에 오브젝트의 주소를 전달한다
                AssetBundleContainer bundleContainer = null;
                assetBundles.TryGetValue(bundleName, out bundleContainer);


                if (assetBundles != null)
                {
                    // Make Container is not unload auto, becase it is possible to contain null object list
                    bundleContainer.AutoUnload = false;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Adds the bundle for removal management, if no gameobjects are using the assetbundle it will be
        /// removed automatically(if you use this method for all objects created from asset bundles)
        /// 제거 관리를 위해 번들을 추가하는 경우에 어떤 게임오브젝트도 에셋번들을 사용하지 않는다. 그것은 자동으로 제거된다
        /// (만약 이 메소드를 에셋번들로부터 생성된 모든 오브젝트에서 사용할 경우)
        /// </summary>
        public void AddBundle(string bundleName, AssetBundle assetBundle, GameObject instantiatedObject)
        {
            //Check if the assetbundle already has a container in the dictionary
            //사전에 이미 에셋번들이 포함되어있는지 체크한다
            if (!assetBundles.ContainsKey(bundleName))
            {
                //Create a new container and store the referenced game object
                //새로운 아이템을 추가한다
                AssetBundleContainer bundleContainer = new AssetBundleContainer();
                bundleContainer.ThisAssetBundle = assetBundle;
                bundleContainer.ObjectList.Add(instantiatedObject);
                bundleContainer.BundleName = bundleName;
                assetBundles.Add(bundleName, bundleContainer);
            }
            else
            {
                //if the key exists, get the container and add the referenced object to its list.
                //이미 키 값이 있는 경우, 컨테이너에 오브젝트의 주소를 전달한다
                AssetBundleContainer bundleContainer = null;
                assetBundles.TryGetValue(bundleName, out bundleContainer);

                if (bundleContainer != null)
                {
                    bundleContainer.ObjectList.Add(instantiatedObject);
                }
                else
                {
                    Debug.LogError("AssetBundleManager.cs: Couldn't get the container for assetbundle: " + bundleName + ". " +
                                   "Removal Management for object:" + instantiatedObject.name + " will not work");
                }
            }
        }
Example #3
0
        /// <summary>
        /// Initiates the download of the asset bundle. Only works if properties have been set with QueueBundleDownload first.
        /// </summary>
        public void DownloadAsset()
        {
            assetManager = AssetBundleManager.Instance;
            //Check from in the assetBundleManager if this bundle is already downloaded.
            AssetBundleContainer thisBundle = assetManager.GetAssetBundle(bundleName);

            if (thisBundle == null)
            {
                //if not, download it
                //없으면 다운로드
                StartCoroutine(DownloadAssetBundle(assetName, bundleName, version));
            }
            else
            {
                //if it is, just load the asset directly
                //있으면 바로 로드한다
#if UNITY_5
                // 5버전이후로 Load라는 메소드는 정상 작동하지 않아 수정하였으나 이 소스코드가 정상작동하는지는 확인하지 않았다.
                if (null != thisBundle.ThisAssetBundle)
                {
                    loadedAsset = thisBundle.ThisAssetBundle.LoadAsset(assetName, typeof(GameObject));
                }
#else
                loadedAsset = thisBundle.ThisAssetBundle.Load(assetName, typeof(GameObject));
#endif

                isDone = true;
            }
        }
Example #4
0
        /// <summary>
        /// Gets the asset bundle for the specified key.
        /// </summary>
        /// <returns>
        /// The asset bundle.
        /// </returns>
        /// <param name='bundleName'>
        /// Bundle name key.
        /// </param>
        public AssetBundleContainer GetAssetBundle(string bundleName)
        {
            AssetBundleContainer thisBundle = null;

            assetBundles.TryGetValue(bundleName, out thisBundle);

            return(thisBundle);
        }
Example #5
0
        /// <summary>
        /// Destroys and unloads an asset bundle and all its referenced objects with
        /// the specified key.
        /// 전달한 키값에 해당하는 번들을 언로드하고 제거한다
        /// </summary>
        /// <param name='bundleName'>
        /// Bundle name.
        /// </param>
        public void DestroyAssetBundle(string bundleName)
        {
            AssetBundleContainer thisBundle = null;

            assetBundles.TryGetValue(bundleName, out thisBundle);
            if (thisBundle != null)
            {
                //Destroy all the game objects that are referencing to this bundle
                foreach (GameObject obj in thisBundle.ObjectList)
                {
                    if (obj != null)
                    {
                        Destroy(obj);
                    }
                }
                thisBundle.ObjectList.Clear();
                thisBundle.Unload();
                assetBundles.Remove(bundleName);
            }
        }
Example #6
0
        public void DestroyObjectInAssetBundle(string bundleName, GameObject objRemove)
        {
            AssetBundleContainer thisBundle = null;

            assetBundles.TryGetValue(bundleName, out thisBundle);
            if (thisBundle != null)
            {
                //Destroy all the game objects that are referencing to this bundle
                foreach (GameObject obj in thisBundle.ObjectList)
                {
                    if (obj == objRemove)
                    {
                        thisBundle.ObjectList.Remove(obj);
                        Destroy(obj);
                    }
                }

                if (thisBundle.IsListEmpty() && thisBundle.AutoUnload)
                {
                    thisBundle.Unload();
                    assetBundles.Remove(bundleName);
                }
            }
        }