IEnumerator Start() { if (!Caching.enabled) { Debug.LogError("対応端末ではありません。"); yield break; } while (!Caching.ready) { yield return(null); } Caching.maximumAvailableDiskSpace = RequiredDiskSpaceByte; DownloadProgresSlider.maxValue = 1; ObservableAssetBundle.Initialize() .Subscribe(_ => ObservableAssetBundle.LoadAssetBundle <AudioClip>(AssetBundlePath, AssetName, this) .Subscribe(clip => { DownloadProgresSlider.value = 1; DonwloadStatusText.text = "BGMダウンロード完了"; BgmAudioSource.clip = clip; BgmAudioSource.outputAudioMixerGroup = Mixer.FindMatchingGroups("BGM").FirstOrDefault(); BgmAudioSource.Play(); AssetBundleManager.UnloadAssetBundle(AssetBundlePath); })); }
//private string panelName; void Start() { Debug.Log("SamplePresnter"); //panelName = this.gameObject.name; button = this.gameObject.Child("Button") .GetComponent <Button> (); //buttonText = this.gameObject.Descendants ( x => x.name == "Text" ) // .SingleOrDefault() // .GetComponent<Text> (); buttonText = this.gameObject.Descendants() .OfComponent <Text>() .SingleOrDefault(); buttonText.text = "ImgDownload"; var size = this.gameObject.Children() .Where(x => x.name.StartsWith("Image")) .Select(x => x.GetComponent <Image> ()) .ToArrayNonAlloc(ref imgs); /* * button.OnClickAsObservable () * .First () * .Select(_=> buttonText.text = "Loding") * .SelectMany ( ObservableAssetBundle.LoadAssetBundle<Sprite> ( "sprites/weapons" , "weapon7" ) ) * .Delay(TimeSpan.FromMilliseconds(300f)) * .Subscribe ( sprite => * { * imgs[ 0 ].sprite = sprite; * buttonText.text = "end"; * }, err => Debug.LogError("errr") ); */ var temp = Observable.WhenAll( ObservableAssetBundle.LoadAssetBundle <Sprite> ("sprites/weapons", "weapon1"), ObservableAssetBundle.LoadAssetBundle <Sprite> ("sprites/weapons", "weapon5"), ObservableAssetBundle.LoadAssetBundle <Sprite> ("sprites/weapons", "weapon7")); button.OnClickAsObservable() .First() .Select(_ => buttonText.text = "Loding") .SelectMany(temp).Timeout(TimeSpan.FromSeconds(5)) .Delay(TimeSpan.FromMilliseconds(300f)) .Subscribe(sprites => { for (int i = 0; i < sprites.Length; i++) { imgs[i].sprite = sprites[i]; buttonText.text = "end"; } }, err => Debug.LogError("errr")); }
IEnumerator Start() { yield return(StartCoroutine(Initialize())); ObservableAssetBundle.LoadAssetBundle <GameObject> (assetBundlePath, assetName) .Subscribe(assetGameObject => { GameObject obj = Instantiate(assetGameObject) as GameObject; obj.transform.position = new Vector3(0.0f, 0.0f, 0.0f); AssetBundleManager.UnloadAssetBundle(assetBundlePath); }); }
void Start() { InitializeSourceURL(); ObservableAssetBundle.Initialize() .Subscribe(_ => ObservableAssetBundle.LoadAssetBundle <GameObject> (assetBundlePath, assetName) .Subscribe(assetGameObject => { GameObject obj = Instantiate(assetGameObject) as GameObject; obj.transform.position = new Vector3(0.0f, 0.0f, 0.0f); AssetBundleManager.UnloadAssetBundle(assetBundlePath); })); }
// Use this for initialization void Start() { ObservableAssetBundle.Initialize().Subscribe(_ => { foreach (var monster in Monsters) { var obj = new GameObject("monster" + monster); var script = obj.AddComponent <AssetBundleSpriteImage>(); script.AssetBundlePath = "monsters"; script.AssetName = monster.ToString(); obj.transform.SetParent(ParentTransform, false); } }); }
public IEnumerator LoadAssetAsync <T> (string assetBundlePath, string assetName, System.Action <T> Callback = null, bool isNowFree = true) where T : UnityEngine.Object { var temp = ObservableAssetBundle.LoadAssetBundle <T> (assetBundlePath , assetName) .Subscribe(obj => { Callback(obj as T); if (isNowFree) { AssetBundleManager.UnloadAssetBundle(assetBundlePath); } }); yield return(temp); }
// Use this for initialization IEnumerator Start() { Mixer = Resources.Load("SampleAudioMixer") as AudioMixer; BgmAudioSource = this.gameObject.AddComponent <AudioSource> (); yield return(StartCoroutine(Initialize())); Caching.maximumAvailableDiskSpace = requiredDiskSpaceByte; ObservableAssetBundle.LoadAssetBundle <AudioClip> (assetBundlePath, assetName) .Subscribe(clip => { Debug.Log("BGM Download complete!!"); BgmAudioSource.clip = clip as AudioClip; BgmAudioSource.outputAudioMixerGroup = Mixer.FindMatchingGroups("BGM").FirstOrDefault(); BgmAudioSource.Play(); AssetBundleManager.UnloadAssetBundle(assetBundlePath); }); }
IEnumerator Start() { if (!Caching.enabled) { yield break; } while (!Caching.ready) { yield return(null); } if (string.IsNullOrEmpty(AssetBundlePath)) { yield return(null); } Sprite sprite; var key = Tuple.Create(AssetBundlePath, AssetName); if (Loaded.TryGetValue(key, out sprite)) { _targetImage.sprite = sprite; _targetImage.enabled = true; IsDone = true; yield break; } //ObservableAssetBundle.Initialize() // .Subscribe(_ => ObservableAssetBundle.LoadAssetBundle <Sprite> (AssetBundlePath, AssetName) .Subscribe(x => { _targetImage.sprite = x; _targetImage.enabled = true; IsDone = true; Loaded[key] = x; }); //); }
IEnumerator Start() { yield return(StartCoroutine(Initialize())); //개별적으로 처리 /* * for (int i = 0 ; i < 3 ; i++ ) { * * var temp = i; * * ObservableAssetBundle.LoadAssetBundle<GameObject> ( assetBundlePath , assetName + i ) * .Subscribe ( assetGameObject => { * * GameObject obj = Instantiate ( assetGameObject ) as GameObject; * obj.transform.position = new Vector3 ( 0.0f + temp , 0.0f , 0.0f ); * * AssetBundleManager.UnloadAssetBundle ( assetBundlePath ); * } ); * } */ //한번에 처리 Observable.WhenAll( ObservableAssetBundle.LoadAssetBundle <GameObject> ("test_box", "TestBox0"), ObservableAssetBundle.LoadAssetBundle <GameObject> ("test_box", "TestBox1"), ObservableAssetBundle.LoadAssetBundle <GameObject> ("test_box", "TestBox2")) .Subscribe(prefabs => { for (int i = 0; i < prefabs.Length; i++) { GameObject obj = Instantiate(prefabs[i]) as GameObject; obj.transform.position = new Vector3(0.0f + i, 0.0f, 0.0f); } AssetBundleManager.UnloadAssetBundle(assetBundlePath); }); }
public void Start() { ObservableAssetBundle.LoadAssetBundle <GameObject> (AssetBundlePath, GuiName) .Timeout(TimeSpan.FromSeconds(5)) .Subscribe(obj => { if (obj == null) { Debug.LogError(" AssetBundle is null. Check Asset Path and Name. \n" + "assetBundlePath : " + AssetBundlePath + " / " + "assetName : " + GuiName ); FailAssetBundle(assetBundlePath, GuiName); return; } var go = Instantiate(obj, gameObject.transform); go.name = GuiName; initCanvasObject(go); //if ( isNowFree ) { AssetBundleManager.UnloadAssetBundle(StaticMethod.GetAssetBundleName(GuiName)); //} }, err => { FailAssetBundle(assetBundlePath, GuiName); }); /* * this.UpdateAsObservable () * .Where ( _ => canvasObject ) * .Where ( _ => callbackQueue.Count > 0 ) * .Select( x => callbackQueue.Dequeue() ) * .Subscribe ( callback => { * callback ( this ); * } ); */ /* * var temp = canvasObject.ObserveEveryValueChanged ( x => x ); * * temp * .TakeUntil(temp) * .Subscribe ( _ => { * * while ( callbackQueue.Count > 0 ) { * var callback = callbackQueue.Dequeue (); * callback( this ); * Debug.Log ( "aaaa" ); * } * * } ); * */ //스트림을 강제로 종료하는 방법은 없는지 고민 //강제로 컴플리트 시키는 방법 //->first this.UpdateAsObservable() .Where(_ => canvasObject) //.DistinctUntilChanged () .First() .Subscribe(_ => { while (callbackQueue.Count > 0) { var callback = callbackQueue.Dequeue(); callback(this); } }, () => Debug.Log("complete")); }