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
個人でもIAM Identity Centerを使おう!(アクセス管理編)
ryder472
3
200
Lexical Analysis
shigashiyama
1
150
Application Development WG Intro at AppDeveloperCon
salaboy
0
190
Security-JAWS【第35回】勉強会クラウドにおけるマルウェアやコンテンツ改ざんへの対策
4su_para
0
180
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
780
ノーコードデータ分析ツールで体験する時系列データ分析超入門
negi111111
0
410
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.2k
Adopting Jetpack Compose in Your Existing Project - GDG DevFest Bangkok 2024
akexorcist
0
110
iOSチームとAndroidチームでブランチ運用が違ったので整理してます
sansantech
PRO
0
130
誰も全体を知らない ~ ロールの垣根を超えて引き上げる開発生産性 / Boosting Development Productivity Across Roles
kakehashi
1
230
Amplify Gen2 Deep Dive / バックエンドの型をいかにしてフロントエンドへ伝えるか #TSKaigi #TSKaigiKansai #AWSAmplifyJP
tacck
PRO
0
380
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
160
Featured
See All Featured
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Making Projects Easy
brettharned
115
5.9k
Rails Girls Zürich Keynote
gr2m
94
13k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
How GitHub (no longer) Works
holman
310
140k
Fireside Chat
paigeccino
34
3k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Building Adaptive Systems
keathley
38
2.3k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
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͢Δɺͱ͍͏ڍಈ͕ Ͱ͖Δɻ