Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
URLCaching in Unity
Search
Toru
November 28, 2018
Technology
0
170
URLCaching in Unity
Changing asset in released-app made with Unity is not so easy.
This feature changes it.
Toru
November 28, 2018
Tweet
Share
More Decks by Toru
See All by Toru
remote controlling Oculus Quest even with macOS
sassembla
0
990
お前はまだ本当のAssetBundleを知らない
sassembla
0
1.7k
E2.pdf
sassembla
1
2.2k
Unityテスト完全に理解した(実機、自動、利のあるテストに食らいつく話)
sassembla
8
22k
Other Decks in Technology
See All in Technology
マルチプロダクト開発の現場でAWS Security Hubを1年以上運用して得た教訓
muziyoshiz
2
2.2k
バクラクのドキュメント解析技術と実データにおける課題 / layerx-ccc-winter-2024
shimacos
2
1.1k
新機能VPCリソースエンドポイント機能検証から得られた考察
duelist2020jp
0
220
なぜCodeceptJSを選んだか
goataka
0
160
10分で学ぶKubernetesコンテナセキュリティ/10min-k8s-container-sec
mochizuki875
3
330
Opcodeを読んでいたら何故かphp-srcを読んでいた話
murashotaro
0
180
あの日俺達が夢見たサーバレスアーキテクチャ/the-serverless-architecture-we-dreamed-of
tomoki10
0
440
私なりのAIのご紹介 [2024年版]
qt_luigi
1
120
継続的にアウトカムを生み出し ビジネスにつなげる、 戦略と運営に対するタイミーのQUEST(探求)
zigorou
0
530
NW-JAWS #14 re:Invent 2024(予選落ち含)で 発表された推しアップデートについて
nagisa53
0
260
AI時代のデータセンターネットワーク
lycorptech_jp
PRO
1
280
権威ドキュメントで振り返る2024 #年忘れセキュリティ2024
hirotomotaguchi
2
740
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
Music & Morning Musume
bryan
46
6.2k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Done Done
chrislema
181
16k
GraphQLとの向き合い方2022年版
quramy
44
13k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
The Language of Interfaces
destraynor
154
24k
A Philosophy of Restraint
colly
203
16k
Code Reviewing Like a Champion
maltzj
520
39k
Typedesign – Prime Four
hannesfritz
40
2.4k
Transcript
URLCachingͷ • twitter:@toru_inoue • github:sassembla • Autoya͍ͬͯ͏Unity Framework ࡞ऀ •
࠷ۙIRIAMͬͭʔ৴αʔϏεͬͯ·͢ (͓ख͍తͳҙຯͰ)
Autoya/ URLCaching ࠓ͢͜ͱ
Unityͷৗࣝ AssetBundleͱ͔࡞Βͳ͍ͱ ΞηοτΛߋ৽Ͱ͖ͳ͍ɻ URLCachingɺ͜ͷ෦ʹ ઈົʹޮ͘ɻ
URLCaching
URLCaching ABҎ֎ͷσʔλΛDLͨ͠Γ͠ͳ ͔ͬͨΓͯ͠ʹΩϟογϡɺ దͳAssetͷܗͰར༻Ͱ͖Δ Autoyaͷ1ػೳɻ
URLCaching 1.Web͔ΒσʔλΛऔಘͯ͠ϑΝΠϧԽɺΩϟογϡ Web Device Binary (file cache) byte[ ] DL
store
URLCaching 1.Web͔ΒσʔλΛऔಘͯ͠ϑΝΠϧԽɺΩϟογϡ 2.͖ͳܕʹมͯ͠औΓग़͠ɺΦϯϝϞϦʹΩϟογϡ byte[ ] Device Unity Asset (on memory
cache) Binary (file cache) load convert
URLCaching 1.Web͔ΒσʔλΛऔಘͯ͠ϑΝΠϧԽɺΩϟογϡ 2.͖ͳܕʹมͯ͠औΓग़͠ɺΦϯϝϞϦʹΩϟογϡ 3.దͳ୯ҐͰύʔδͨ͠Γ 4.URLʹରͯ͠ΫΤϦͷมߋͰσʔλΛߋ৽Ͱ͖Δ https://somewhere/image.png?hash=e9e07ad Query
URLCaching 4.URLʹରͯ͠ΫΤϦͷมߋͰσʔλΛߋ৽Ͱ͖Δ https://somewhere/image.png?hash=e9e07ad
URLCaching 4.URLʹରͯ͠ΫΤϦͷมߋͰσʔλΛߋ৽Ͱ͖Δ https://somewhere/image.png?hash=e9e07ad https://somewhere/image.png?hash=kjas80a5 ಉ͡URLͰΫΤϦ෦Λม͑ΔͱɺΩϟογϡࡁΈͷ σʔλʹ͍ͭͯɺurl͔Βͷ࠶औಘΛߦ͏(ߋ৽)ɻ
API public static void Persist_URLCaching_Load<T>( string domain, string url, Func<byte[],
T> bytesToTConverter, Action<T> onLoaded, Action<int, string> onLoadFailed, Dictionary<string, string> requestHeader=null) where T : UnityEngine.Object ͜ͷϝιουҰൃͰɺURLCachingͷͯ͢Λ࣮ߦɻ
public static void Persist_URLCaching_Load<T>( string domain, string url, Func<byte[], T>
bytesToTConverter, Action<T> onLoaded, Action<int, string> onLoadFailed, Dictionary<string, string> requestHeader=null) where T : UnityEngine.Object urlͱ͔ byte[] to Tܕมࣜηοτ࣮ͯ͠ߦ →(ඞཁͳΒurl͔ΒσʔλΛDL) →Tܕσʔλͱͯ͠ඇಉظల։ɻ API
bytes => { var tex = new Texture2D(1, 1); tex.LoadImage(bytes);
var newSprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(.5f, .5f)); return newSprite; } Func<byte[], T> bytesToTConverter ྫ byte[]͔ΒSpriteΛੜͯ͠ฦ͢ͱ͔ͩͱ ͳײ͡ɻ
࣮༻ྫ ৴ऀը૾Ұཡ
࣮༻ྫ ৴ऀը૾Ұཡ ৴ऀ͞Μͨ͘͞Μ͍Βͬ͠ΌΔɻ ը૾ͷߋ৽৴ऀ͞Μଆɻ มߋ͕͋Δͨͼʹશ෦ABԽ͢Δ? Noͩɺ͠ΜͲ͍ɻ →URLCachingͰղܾɻ
࣮༻ྫ ࢹௌऀϥϯΩϯά
࣮༻ྫ ࢹௌऀϥϯΩϯά ϢʔβʔʹΞΠίϯͱ͔͋ͬͯ ͜Ε͕·ͨશһࣗ༝ʹߋ৽Ͱ͖Δɻ ͜͜ͰURLCachingɻ Ϣʔβʔ͕ը૾Λߋ৽͢Δͨͼ URLͷquery෦͕มΘͬͯɺ ͍͍ײ͡ʹը૾͕ߋ৽ɺΩϟογϡɻ
• ແਚଂʹσʔλ͕૿͑Δ • ແݶʹσʔλ͕ߋ৽͞ΕΔ • AssetBundleʹͨ͘͠ͳ͍/Ͱ͖ͳཻ͍ • APIͱ͔͔ΒURL͕Β͑Δ URLCaching͕͍ͯΔͱ͜Ζ
URLCaching͕͍ͯΔͱ͜Ζ Pros: ɾURL͕͋ΕΞηοτ͕औಘͰ͖Δ ɾΩϟογϡͰ͖Δ ɾABͷΑ͏ͳϏϧυෆཁ(ѹॖͱ͔͢ΔͳΒผ) ɾURLύϥϝʔλ࣍ୈͰߋ৽Ͱ͖Δ (AssetBundle <<< खܰ͞ͷน <<<
URLCaching)
URLCaching͕͍ͯΔͱ͜Ζ Cons: ɾURL͕ඞਢ(ͭ·Γ୭͔͕URLΛฦ͢ඞཁ͕) ɾల։࣌ʹͬͺϝϞϦ৯͏(࠷దͳABʹউͯͳ͍) ɾCRCνΣοΫͱ͔ແ͍ͷͰਓྗ(broken or not) ɾABͱಉ༷Unload͢Δͷਓྗ (AssetBundle >>>
࣮ߦޮͷน >>> URLCaching)
Happy URLCachingʂ
Unityͷ2017͋ͨΓ͔ΒՃ͞ΕͨAPIͰɺDownloadHandlerFile ͱ͍͏ͷ͕͋ͬͯɻ https://docs.unity3d.com/ScriptReference/Networking.DownloadHandlerFile.html URLCachingʹ͍ͬͯΔɻ ͜ΕΛ͏ͱɺUnityͷC#ϨΠϠΛ伵·ͣ͞ʹωΠςΟϒͷϑΝΠϧγεςϜʹରͯ͠μΠϨΫτʹ Web͔ΒDLͨ͠ϑΝΠϧΛੜͰ͖Δɻ ͭ·Γ Web -> C#
-> ϑΝΠϧγεςϜ Ͱͳ͘ɺ Web -> ϑΝΠϧγεςϜ ͱΔ͜ͱͰɺͳΜͱ͍͏͔ແବͳྗΛফͤΔɻ ͪͳΈʹϚδͰC#্ʹσʔλΛల։͠ͳ͍ͨΊɺWebRequestͷdataͱ͔Λಡ͏ͱ͢Δͱ Unsupported PlatformΤϥʔ͕ͰΔపఈͬΓɻ ಠࣗʹAssetBundleΛDL͢Δͷʹ͑Δɻ ͳʹΑΓUnity͕ϝϯςͯ͘͠ΕΔωΠςΟϒϨΠϠͷૢ࡞Λߦ͑ΔAPIͳͷͰɺ ࠓ·ͰʮUnityͰWeb͔ΒԿ͔ΛDL͢ΔͱσʔλͷίϐʔͰϝϞϦ͕ʙʯΈ͍ͨͳΛײͯͨ͡ਓʹ ͏͚ͬͯͭɻ ͓·͚:εςΩٕज़ʹ͍ͭͯ
͓·͚ͷ͓·͚ URLCachingCDNͱ͔Ͱ͑ΔTemporaryURLͷ ར༻αϙʔτ͍ͯ͠Δɻ ύοͱݴ͏ͱɺΩʔͱURLΛผʹ࣋ͭ͜ͱ͕Մೳɻ ΩʔͷΫΤϦ͕มΘͬͨΒɺಉ͡Ωʔʹରͯ͠ ผͷURL͔ΒσʔλΛDL͢Δɺͱ͍͏ڍಈ͕ Ͱ͖Δɻ