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
160
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
980
お前はまだ本当のAssetBundleを知らない
sassembla
0
1.7k
E2.pdf
sassembla
1
2.2k
Unityテスト完全に理解した(実機、自動、利のあるテストに食らいつく話)
sassembla
8
22k
Other Decks in Technology
See All in Technology
新R25、乃木坂46 Mobileなどのファンビジネスを支えるマルチテナンシーなプラットフォームの全体像 / cam-multi-cloud
cyberagentdevelopers
PRO
1
130
Nix入門パラダイム編
asa1984
2
200
リンクアンドモチベーション ソフトウェアエンジニア向け紹介資料 / Introduction to Link and Motivation for Software Engineers
lmi
4
290k
現地でMeet Upをやる場合の注意点〜反省点を添えて〜
shotashiratori
0
520
10分でわかるfreee エンジニア向け会社説明資料
freee
18
520k
Commitment vs Harrisonism - Keynote for Scrum Niseko 2024
miholovesq
6
1.1k
分布で見る効果検証入門 / ai-distributional-effect
cyberagentdevelopers
PRO
4
700
WINTICKETアプリで実現した高可用性と高速リリースを支えるエコシステム / winticket-eco-system
cyberagentdevelopers
PRO
1
190
【若手エンジニア応援LT会】AWS Security Hubの活用に苦労した話
kazushi_ohata
0
160
신뢰할 수 있는 AI 검색 엔진을 만들기 위한 Liner의 여정
huffon
0
340
オーティファイ会社紹介資料 / Autify Company Deck
autifyhq
9
120k
フルカイテン株式会社 採用資料
fullkaiten
0
36k
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
180
21k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
3
370
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.8k
Done Done
chrislema
181
16k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
9
680
Embracing the Ebb and Flow
colly
84
4.4k
How STYLIGHT went responsive
nonsquared
95
5.2k
Statistics for Hackers
jakevdp
796
220k
Designing on Purpose - Digital PM Summit 2013
jponch
115
6.9k
Become a Pro
speakerdeck
PRO
24
5k
Six Lessons from altMBA
skipperchong
26
3.5k
Testing 201, or: Great Expectations
jmmastey
38
7k
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͢Δɺͱ͍͏ڍಈ͕ Ͱ͖Δɻ