Upgrade to Pro — share decks privately, control downloads, hide ads and more …

URLCaching in Unity

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for Toru Toru
November 28, 2018

URLCaching in Unity

Changing asset in released-app made with Unity is not so easy.
This feature changes it.

Avatar for Toru

Toru

November 28, 2018

More Decks by Toru

Other Decks in Technology

Transcript

  1. URLCachingͷ࿩ • twitter:@toru_inoue • github:sassembla • Autoya͍ͬͯ͏Unity Framework ࡞ऀ •

    ࠷ۙ͸IRIAMͬͭʔ഑৴αʔϏε΍ͬͯ·͢ (͓ख఻͍తͳҙຯͰ)
  2. 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ͷ͢΂ͯΛ࣮ߦɻ
  3. 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
  4. 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Λੜ੒ͯ͠ฦ͢ͱ͔ͩͱ ͳײ͡ɻ
  5. 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͢ΔͱσʔλͷίϐʔͰϝϞϦ͕ʙʯΈ͍ͨͳ໰୊Λײͯͨ͡ਓʹ ͏͚ͬͯͭɻ ͓·͚:εςΩٕज़ʹ͍ͭͯ