コード例 #1
0
        public void Instantiate(Transform t = null)
        {
            StartCoroutine(
                _manager.GetObjectsBundleAsync(DataModel, (ab) =>
            {
                _bundle = ab;
                if (_bundle == null || _bundle.AllObjects.Length.Equals(0))
                {
                    Debug.LogError("Asset Bundle is null or empty");
                }
                else
                {
                    if (_child != null)
                    {
                        GameObject.Destroy(_child);
                    }

                    _child = null;

                    var obj = _bundle.Asset;

                    if (t == null)
                    {
                        _child = Instantiate(obj, transform) as GameObject;
                    }
                    else
                    {
                        _child = Instantiate(obj, t) as GameObject;
                    }

                    _child.GetComponentsInChildren <Camera>().ToList().ForEach(c => c.enabled = false);

                    if (_autoRescaleObject)
                    {
                        var resize = _child.AddComponent <AutoResizeObject>();

                        resize.TargetSize = _targetScale;
                    }
                }
            }));
        }
コード例 #2
0
        IEnumerator GetAssetBundleAsync(BundleData data, System.Action <ObjectsBundle> callback)
        {
            _currentRequests.Add(name);

            //Path.Split is to negate breaking change to bundlepath for multiple platforms
            var path = Path.Combine(AWS.ProjectPath, data.bundlepath.Split('.')[0]);

            switch (Application.platform)
            {
            case RuntimePlatform.Android:
                path += ".android";
                break;

            case RuntimePlatform.IPhonePlayer:
                path += ".ios";
                break;

            default:
                path += ".android";
                break;
            }

            Debug.Log("Attempting to get AssetBundle from: " + path);

            var webRequest = UnityWebRequestAssetBundle.GetAssetBundle(path);

            yield return(webRequest.SendWebRequest());

            if (webRequest.isNetworkError || webRequest.isHttpError)
            {
                Debug.LogError(webRequest.error);
            }
            else
            {
                AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(webRequest);

                Debug.Log("Got Asset Bundle: " + bundle.name);

                bundle.GetAllAssetNames().ToList().ForEach(t =>
                {
                    Debug.Log(t);
                });

                var objects = bundle.LoadAllAssetsAsync();

                yield return(objects);

                ObjectsBundle b = new ObjectsBundle()
                {
                    Name       = name,
                    Bundle     = bundle,
                    AllObjects = objects.allAssets,
                    Asset      = objects.asset
                };

                _bundles.Add(b);
                ObjectsBundleDictionary.Add(data.id, b);

                Debug.Log("Loaded AllAssets");

                _currentRequests.Remove(name);

                if (callback != null)
                {
                    callback(b);
                }
            }
        }