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

24時間でゲームをつくるための Unity

24時間でゲームをつくるための Unity

9cdb1d21375062bc2cd0d1358c2fa1f0?s=128

Shoma SATO

April 04, 2019
Tweet

Transcript

  1. 24࣌ؒͰήʔϜΛͭ͘ΔͨΊ ͷ Unity 2019/4/4 cluster.unity #1 Ͷ͓ΓΜ (@noir_neo) 1

  2. Ͷ͓ΓΜ • @noir_neo • ήʔϜΛͭ͘Δ • Ϋϥελʔגࣜձࣾ • ιϑτ΢ΣΞΤϯδχΞ •

    όʔνϟϧϋτ(Ծ) 2
  3. ਪ͠ͷVλϨϯτ 3

  4. somunia • @she_is_wired • youtube.com/c/somuniaroom 4

  5. 24࣌ؒͰήʔϜΛͭ͘ΔͨΊ ͷ Unity ֓ཁ • 24࣌ؒͰήʔϜ࡞Δ΍ͭ • ஌ݟͳͲ • ·ͱΊ

    5
  6. 24࣌ؒͰήʔϜ࡞Δ΍ͭ • 24࣌ؒ(͘Β͍)ͰήʔϜ࡞Δ • Unity1िؒήʔϜδϟϜΛ΍Ζ͏ͱ͚ͯͨ͠Ͳɺ1िؒ௕͍ ͳͬͯ͜ͱͰ࢝Ίͨ • ༑ୡͱ͔ಉ྅ͱ΍ͬͯΔ׬શʹݸਓతͳ࠵͠ • ࣮ࡍʹίʔυॻ͍ͯΔͷ͸12࣌ؒఔ౓

    • Ͱ΋ΞσΟγϣφϧλΠϜ͸΍Γ͕ͪ 6
  7. 24࣌ؒͰήʔϜ࡞Δ΍ͭ • ڈ೥10ճ΍ͬͨ ࠓ೥͸2ճ • Ұ൪ଟ͘΍ͬͯΔߏ੒͸ ΤϯδχΞ2 σβΠφʔ1 • جຊతʹ੒Ռ෺͸

    WebGL Ϗϧυ 7
  8. ࠷ۙͷ੒Ռ෺Λ঺հ͠·͢ • େסഋ THE GREAT KANPAI • POPPO SHOOTER 2019

    • ൥೰ RUN • sun-ma 8
  9. 9

  10. 10

  11. 11

  12. 12

  13. 13

  14. 14

  15. ஌ݟͳͲ • 24࣌ؒͰ׬੒ͤ͞ΔͨΊʹɺࢲୡ͕͍Ζ͍Ζࢼͯ͠ࠓͷॴͨͲ Γண͍ͯΔΞϨίϨ • ڠۀ͢Δʹ͋ͨͬͯͳΔ΂͓͘ޓ͍ͷ࡞ۀΛϒϩοΫ͠ͳ͍ • ͋Δఔ౓ϝϯςφϏϦςΟ͸ࣺͯͯ଎౓ΛऔΔ • ͔͋͠͠·Γʹ΋ແடংͩͱ׬੒͠ͳ͍!

    15
  16. ஌ݟͳͲ • ͜͜Ͱൃද͢Δ͜ͱ͸ϓϩμΫγϣϯίʔυͰ͸௨༻͠·ͤΜ • ήʔϜδϟϜͱ͔ϓϩτλΠϐϯάͷώϯτʹͳΕ͹޾͍ • Ͱ͖Δ͚ͩଟ͘ͷ tips Λ঺հ͢ΔͨΊʹͻͱͭͻͱͭৄ͍͠આ ໌͸͠·ͤΜ

    • ؾʹͳͬͨ͜ͱɺΑ͘Θ͔Βͳ͔ͬͨ͜ͱͳͲ͸͋ͱͰฉ͍ ͍ͯͩ͘͞! 16
  17. ஌ݟͳͲϦετ 1/2 • ઃܭ͸ࡶʹ΍Δ • 1scene ͰλΠτϧʙϦβϧτ·Ͱ΍Δ • Zenject ͸ϛχϚϜʹ࢖͏

    • UniRx ͸࠷௿ݶ class ؒͷΠϕϯτ௨஌Ͱ࢖͏ • Input ͸ interface Ͱ͍͍ײ͡ʹ 17
  18. ஌ݟͳͲϦετ 2/2 • nested prefab ͸ਆ • CPU ͷ࣮૷͸ Random

    Ͱे෼ • UniRx.Async ͸ήʔϜશମͷεςʔτ؅ཧʹศར • Cloud Build ͸ΘΓͱΦεεϝ • deploy ͸ࣗಈԽ͓ͯ͜͠͏ 18
  19. ઃܭ͸ࡶʹ΍Δ • શମͷߏ੒֬ೝͱ෼୲ͷՄࢹԽͷͨΊʹ͢Δ • namespace ͱ class ͱґଘͷ޲͖͘Β͍ • property

    ͱ͔͸શ෦ॻ͜͏ͱ͠ͳ͍ 19
  20. 20

  21. 21

  22. 1scene ͰλΠτϧʙϦβϧ τ·Ͱ΍Δ • ͦΜͳʹϦονͳλΠτϧ/ϦβϧτΛ࡞͍ͬͯΔՋ͸ͳ͍ • scene ભҠͱ͔ॻ͘͘Β͍ͳΒ UI ͷ

    active ੾Γସ͑Δ͚ͩͰ͍ ͍! • ੩తͰ͍͍΋ͷ͸ͱʹ͔͘ scene ʹ͓͍͍ͯ͘ • ίϯϑϦΫτ͢Δͱ஍ࠈͳͷͰ prefab ʹ͢Δͷ͸ඞਢ!! 22
  23. 23

  24. Zenject ͸ϛχϚϜʹ࢖͏ Zenject ͕ԿͰ͋Δ͔͸Έͳ͞Μ஌ͬͯΔମͰߦ͖·͢ 24

  25. Zenject Binding (ͱ Zen Auto Injecter) ͸ੵۃతʹ࢖͍ͬͯ͘ • scene ͷϧʔτΦϒδΣΫτಉ࢜ͷґଘ͸

    SerializeField Ͱղܾ ͠ͳ͍΄͏͕ྑ͍ • γʔϯʹอଘ͞ΕΔͷͰίϯϑϦΫτϦεΫ͕ߴ͍ • Factory ͸ॻ͘ྔ͕૿͑Δ͚ͩͰࢫΈ͕গͳ͍ • ࣮ߦίετ͸ؾʹͯ͠͸͍͚ͳ͍ 25
  26. GameObjectContext ͸ player Λಈత ʹ࡞Δͱ͖ͳͲʹ༗ޮ͕ͩ… • ී௨ʹ Instantiate ͨ͠΄͏͕ૣ͍ •

    input ͷࠩ͠ସ͑ΛͲ͏΍Δ͔͸೉͍͠ͱ͜Ζ • ཧ૝͸ pure class Ͱ΍Γ͍͕ͨ GameObject Context Installer ʹ Ҿ਺౉͢ͷͱ͔ΊΜͲ͍͘͞ • Monobehaviour ʹͯ͠ GetComponent<IInputEventProvider>(); Ͱे෼Ά͍ 26
  27. UniRx ͸࠷௿ݶ class ؒͷΠ ϕϯτ௨஌Ͱ࢖͏ UniRx ͕ԿͰ͋Δ͔͸Έͳ͞Μ஌ͬͯΔମͰߦ͖·͢ 27

  28. ґଘੑ͸ٯస͠Α͏ • interface Λա৒ʹ੾ͬͯ΋ɺ24࣌ؒ಺ʹ͏Ε͍͜͠ͱ͸ͦΜͳ ʹͳ͍ • ݫີʹґଘੑٯసΛ͢Δඞཁ͸ͳ͍͕… • ந৅ʹґଘͤ͞ͳ͍ͱͯ͠΋ Observer

    ύλʔϯͰґଘͷ޲͖͸ ٯʹ͓ͯ͘͠ • class ͷ੹຿͕෼͚΍͘͢ɺػೳ௥Ճ͕͠΍͍͢ɺίϯϑϦΫ τϦεΫ΋Լ͕Δ 28
  29. كʹΑ͘ݟΔίʔυ 29

  30. public class PlayerCore : MonoBehaviour { [Inject] IInputEventProvider inputEventProvider; bool

    CanJump { get; set; } // ஍໘ʹ͍͍ͭͯΔ͔ͱ͔ void Start() { inputEventProvider.Jump .Where(b => b && CanJump) .Subscribe(_ => Jump()) .AddTo(this); } 30
  31. [SerializeField] PlayerMover mover; void Jump() { mover.Jump(); } } 31

  32. δϟϯϓͨ͠ͱ͖ʹΞχϝʔγϣϯ Λͭͭ͠SE΋໐Β͍ͨ͠! 32

  33. [SerializeField] PlayerMover mover; + [SerializeField] PlayerAnimator animator; + [SerializeField] SeEmitter

    seEmitter; void Jump() { mover.Jump(); + animator.Jump(); + seEmitter.Jump(); } } 33
  34. ΍Γ͍ͨ͜ͱ͕૿͑Δͨͼʹ PlayerCore ʹॲཧ͕૿͍͑ͯ͘ 34

  35. 35

  36. public class PlayerCore : MonoBehaviour { [Inject] IInputEventProvider inputEventProvider; bool

    CanJump { get; set; } // ஍໘ʹ͍͍ͭͯΔ͔ͱ͔ public IObservable<Unit> OnJump => inputEventProvider.Jump .Where(b => b && CanJump) .AsUnitObservable(); } 36
  37. public class PlayerMover : MonoBehaviour { [SerializeField] PlayerCore core; [SerializeField]

    Rigidbody rb; void Start() { core.OnJump .ObserveOn(Scheduler.MainThreadFixedUpdate) .Subscribe(_ => rb.AddForce(0, jumpPower, 0, ForceMode.Impulse)) .AddTo(this); } } 37
  38. public class PlayerAnimator : MonoBehaviour { [SerializeField] PlayerCore core; [SerializeField]

    Animator animator; void Start() { core.OnJump .Subscribe(_ => animator.SetTrigger("Jump")) .AddTo(this); } } 38
  39. 39

  40. Input ͸ interface Ͱ͍ ͍ײ͡ʹ 40

  41. interface IInputEventProvider { IReadOnlyReactiveProperty<float> Move { get; } } 41

  42. public class PlayerCore : MonoBehaviour { void Start() { var

    input = GetComponent<IInputEventProvider>(); } } 42
  43. public class PlayerInput : MonoBehaviour, IInputEventProvider { readonly ReactiveProperty<float> move

    = new ReactiveProperty<float>(); IReadOnlyReactiveProperty<float> IInputEventProvider.Move => move; void Update() { move.Value = Input.GetAxis("Horizontal"); } } 43
  44. public class CpuInput : MonoBehaviour, IInputEventProvider { readonly ReactiveProperty<float> move

    = new ReactiveProperty<float>(); IReadOnlyReactiveProperty<float> IInputEventProvider.Move => move; void Update() { move.Value = Random.insideUnitCircle.x; } } 44
  45. nested prefab ͸ਆ • Ϟσϧͷࠩ͠ସ͕͑ඵͰऴΘΔ • 2PΧϥʔͱ͔ɺίʔυͰϚςϦΞϧม͑ΔΑΓѹ౗తʹָ 45

  46. • ϞσϧʹجૅతͳεΫϦϓτ͚ͩ଍͠ ͨ΋ͷΛ variant • 1PΧϥʔͷϚςϦΞϧઃఆͨ͠΋ͷ Λ variant' • 2PΧϥʔͷϚςϦΞϧઃఆͨ͠΋ͷ

    Λ variant'' • ͜Ε͸2PΑΓ૿͑ͳ͍લఏͩͬͨ ͷͰ 46
  47. CPU ͷ࣮૷͸ Random Ͱे෼ 47

  48. ద౰ʹ Update loop ʹ Random Ͱॻ ͍͓͚ͯ͹ͱΓ͋͑ͣͦΕͬΆ͘ͳΔ • value ͱ͔

    Range ͚ͩͰͳ͘ɺ insideUnitCircle Λ࢖͏ͱ͔ • ৚݅ʹԠͯ֬͡཰Λม͑ͨΓ 48
  49. ʰେסഋʱͷ CPU ͸΋͸΍ϓϨΠ ϠʔͷҐஔ͢Β஌Βͳ͍ 1. ҰఆҎ্୺ʹ͍Δͱδϟϯϓ͢Δ֬཰্͕Δ 2. ໨త஍͸ਅΜதΛબͼ΍͘͢ • insideUnitCircle.x

    Λ࢖͍ͬͯΔ 3. ໨త஍ʹ͍ۙͮͨΒҰఆ֬཰Ͱ࣍ͷ໨త஍ΛܾΊΔ 49
  50. UniRx.Async ͸ήʔϜશମͷ εςʔτ؅ཧʹศར • λΠτϧը໘ͰʰελʔτʱϘλϯ͕ԡ͞ΕͨΒήʔϜ͕͸͡ ·ͬͯɺࢮΜͩΒϦβϧτΛදࣔ͢Δ • ॲཧ͸Ұຊಓ • async/await

    Ͱॻ͘ͱ͍͍ײ͡ 50
  51. async void Start() { await Title(); await StartGame(); await GameOver();

    await Result(); } async UniTask Title() { titleUi.Show(); await titleUi.OnStartClickAsObservable.ToUniTask(); } 51
  52. Cloud Build ͸ΘΓͱΦεε ϝ • ݶΒΕͨ࣌ؒͱϚγϯϦιʔεͷதͰɺϏϧυʹୣΘΕΔͷ͸ ΋͍ͬͨͳ͍ • ͱʹ͔͘Ϗϧυ͸ճ͓͔ͯ͠ͳ͍ͱɺ౔ஃ৔ͰʮΤσΟλͰ͸ ಈ͘ͷʹϏϧυͰಈ͔ͳ͍!!ʯ͕ى͖͕ͪ(Կճ͔΍ͬͯΔ)

    52
  53. ͱΓ͋͑ͣ $9/month ෷͓͚ͬͯ • ࠷ۙ͸ΘΓͱ·ͱ΋ʹͳͬͨ • ͪΌΜͱ࠷৽ͷόʔδϣϯ͕࢖͑Δ͠ • WebGL ͷ

    custom template ͸࢖Θͤͯ΄͍͠ 53
  54. ෷͍ͨ͘ͳ͍ਓ͸ • Ҏલࢲ͕࢖͍ͬͯͨࣗಈϏϧυͷεΫϦϓτΛ͓࢖͍͍ͩ͘͞ • git worktree Ͱ৽͍͠ϫʔΫεϖʔεΛ࡞ͬͯϏϧυͯ͠ gh- pages ϒϥϯνʹ

    push ͢Δ • ϚγϯϦιʔε͸࢖͏͚ͲɺϏϧυதʹ࡞ۀ͸ετοϓ͠ͳ͍ https:/ /github.com/noir-neo/unity-webgl-ghpages/blob/master/ build.sh 54
  55. deploy ͸ࣗಈԽ͓ͯ͜͠͏ • static ͳϦϯΫ͕΄͍͠ • ࠷ऴ੒Ռ෺Λެ։͓ͯ͘͠ͷʹɺ github pages ͸૬ੑ͕͍͍

    • zip ΛσϓϩΠ͢Δ shell • ͱʹ͔͘ऴΘΓࠒ͸όλόλ͢ΔͷͰɺࣗಈԽͰ͖Δ෦෼͸ ͓ͯ͘͠ https:/ /gist.github.com/noir-neo/ 3a2071dc6d8ea8300caed4bc2bb2de26 55
  56. 24࣌ؒͰήʔϜ࡞Δ΍ͭએ఻ • աڈͷ࡞඼ू͸͸ͯͳϒϩάʹ • http:/ /noir-neo.hatenablog.com • ιʔε͸͢΂ͯ github ʹ

    • https:/ /github.com/one-night-game-jam • ຖճ twitch Ͱ഑৴ͯ͠Δ • https:/ /www.twitch.tv/noirneo 56
  57. ·ͱΊ • ୹࣌ؒͰήʔϜΛ׬੒ͤ͞ΔͨΊͷ tips ूΛ঺հ͠·ͨ͠ • جຊతͳઃܭͷߟ͑ํͱɺͦͷ࣮૷ྫɺ͋ͱϏϧυ Έ͍ͨͳ࿩ Ͱͨ͠ •

    ήʔϜδϟϜͱ͔ϓϩτλΠϐϯά͢Δͱ͖ͷώϯτʹͳΕ͹ ޾͍Ͱ͢ 57