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
RubyのWebアプリケーションを50倍速くする方法 / How to Make a Ruby Web Application 50 Times Faster
hogelog
3
950
OS 標準のデザインシステムを超えて - より柔軟な Flutter テーマ管理 | FlutterKaigi 2024
ronnnnn
0
200
The Rise of LLMOps
asei
7
1.7k
Lexical Analysis
shigashiyama
1
150
【Startup CTO of the Year 2024 / Audience Award】アセンド取締役CTO 丹羽健
niwatakeru
0
1.3k
iOS/Androidで同じUI体験をネ イティブで作成する際に気をつ けたい落とし穴
fumiyasac0921
1
110
Why App Signing Matters for Your Android Apps - Android Bangkok Conference 2024
akexorcist
0
130
Shopifyアプリ開発における Shopifyの機能活用
sonatard
4
250
組織成長を加速させるオンボーディングの取り組み
sudoakiy
2
210
TanStack Routerに移行するのかい しないのかい、どっちなんだい! / Are you going to migrate to TanStack Router or not? Which one is it?
kaminashi
0
600
OCI Network Firewall 概要
oracle4engineer
PRO
0
4.2k
マルチモーダル / AI Agent / LLMOps 3つの技術トレンドで理解するLLMの今後の展望
hirosatogamo
37
12k
Featured
See All Featured
10 Git Anti Patterns You Should be Aware of
lemiorhan
655
59k
KATA
mclloyd
29
14k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Raft: Consensus for Rubyists
vanstee
136
6.6k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
The Pragmatic Product Professional
lauravandoore
31
6.3k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
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͢Δɺͱ͍͏ڍಈ͕ Ͱ͖Δɻ