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
レンジャーシステムズ | 会社紹介(採用ピッチ)
rssytems
0
150
事業貢献を考えるための技術改善の目標設計と改善実績 / Targeted design of technical improvements to consider business contribution and improvement performance
oomatomo
0
100
10分で学ぶKubernetesコンテナセキュリティ/10min-k8s-container-sec
mochizuki875
3
350
Oracle Cloud Infrastructure:2024年12月度サービス・アップデート
oracle4engineer
PRO
0
200
非機能品質を作り込むための実践アーキテクチャ
knih
5
1.5k
GitHub Copilot のテクニック集/GitHub Copilot Techniques
rayuron
37
14k
複雑性の高いオブジェクト編集に向き合う: プラガブルなReactフォーム設計
righttouch
PRO
0
120
多領域インシデントマネジメントへの挑戦:ハードウェアとソフトウェアの融合が生む課題/Challenge to multidisciplinary incident management: Issues created by the fusion of hardware and software
bitkey
PRO
2
110
NilAway による静的解析で「10 億ドル」を節約する #kyotogo / Kyoto Go 56th
ytaka23
3
380
Amazon SageMaker Unified Studio(Preview)、Lakehouse と Amazon S3 Tables
ishikawa_satoru
0
160
10個のフィルタをAXI4-Streamでつなげてみた
marsee101
0
170
re:Invent をおうちで楽しんでみた ~CloudWatch のオブザーバビリティ機能がスゴい!/ Enjoyed AWS re:Invent from Home and CloudWatch Observability Feature is Amazing!
yuj1osm
0
130
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
Code Review Best Practice
trishagee
65
17k
Six Lessons from altMBA
skipperchong
27
3.5k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Unsuck your backbone
ammeep
669
57k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Why Our Code Smells
bkeepers
PRO
335
57k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Adopting Sorbet at Scale
ufuk
73
9.1k
Become a Pro
speakerdeck
PRO
26
5k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
The Invisible Side of Design
smashingmag
298
50k
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͢Δɺͱ͍͏ڍಈ͕ Ͱ͖Δɻ