private void Save() { WebCamEntity.Save.Will(); ObservableImageRWHandler .WriteAsObservable( UriBuilder(Arguments.Name), WebCamEntity.StorableTextureProperty.Value ) // WebCamEntity.Save の先で UnityEngine 系の API を触るため、MainThread に戻す .ObserveOnMainThread() .Subscribe(_ => WebCamEntity.Save.Did()); }
private void Load() { WebCamEntity.Load.Will(); ObservableImageRWHandler .ReadAsObservable( UriBuilder(Arguments.Name) ) // MainThread に戻す前に配列の変換を行っておく .Select(x => new { StorableTexture = x, Data = ArrayConverter.ByteArrayToColor32Array(x.Data) }) // CreateTexture2D 内で UnityEngine.Texture2D などの API を触るため、MeinThread に戻す .ObserveOnMainThread() .Select(x => new { Texture2D = CreateTexture2D(x.StorableTexture, x.Data), x.StorableTexture.RotationAngle, x.StorableTexture.VerticallyMirrored }) // OnCompleted は流さない .Subscribe( x => { WebCamEntity.Load.Did(); WebCamEntity.ConfirmRenderableTexture.Did(RenderableTextureTranslator.Translate(x.Texture2D, x.RotationAngle, x.VerticallyMirrored)); } ); }