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

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

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

ねおりん

April 04, 2019
Tweet

More Decks by ねおりん

Other Decks in Programming

Transcript

  1. 9

  2. 10

  3. 11

  4. 12

  5. 13

  6. 14

  7. ஌ݟͳͲϦετ 1/2 • ઃܭ͸ࡶʹ΍Δ • 1scene ͰλΠτϧʙϦβϧτ·Ͱ΍Δ • Zenject ͸ϛχϚϜʹ࢖͏

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

    Ͱे෼ • UniRx.Async ͸ήʔϜશମͷεςʔτ؅ཧʹศར • Cloud Build ͸ΘΓͱΦεεϝ • deploy ͸ࣗಈԽ͓ͯ͜͠͏ 18
  9. 20

  10. 21

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

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

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

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

    input ͷࠩ͠ସ͑ΛͲ͏΍Δ͔͸೉͍͠ͱ͜Ζ • ཧ૝͸ pure class Ͱ΍Γ͍͕ͨ GameObject Context Installer ʹ Ҿ਺౉͢ͷͱ͔ΊΜͲ͍͘͞ • Monobehaviour ʹͯ͠ GetComponent<IInputEventProvider>(); Ͱे෼Ά͍ 26
  15. ґଘੑ͸ٯస͠Α͏ • interface Λա৒ʹ੾ͬͯ΋ɺ24࣌ؒ಺ʹ͏Ε͍͜͠ͱ͸ͦΜͳ ʹͳ͍ • ݫີʹґଘੑٯసΛ͢Δඞཁ͸ͳ͍͕… • ந৅ʹґଘͤ͞ͳ͍ͱͯ͠΋ Observer

    ύλʔϯͰґଘͷ޲͖͸ ٯʹ͓ͯ͘͠ • class ͷ੹຿͕෼͚΍͘͢ɺػೳ௥Ճ͕͠΍͍͢ɺίϯϑϦΫ τϦεΫ΋Լ͕Δ 28
  16. public class PlayerCore : MonoBehaviour { [Inject] IInputEventProvider inputEventProvider; bool

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

    seEmitter; void Jump() { mover.Jump(); + animator.Jump(); + seEmitter.Jump(); } } 33
  18. 35

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

    CanJump { get; set; } // ஍໘ʹ͍͍ͭͯΔ͔ͱ͔ public IObservable<Unit> OnJump => inputEventProvider.Jump .Where(b => b && CanJump) .AsUnitObservable(); } 36
  20. 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
  21. public class PlayerAnimator : MonoBehaviour { [SerializeField] PlayerCore core; [SerializeField]

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

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

    input = GetComponent<IInputEventProvider>(); } } 42
  24. 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
  25. 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
  26. ద౰ʹ Update loop ʹ Random Ͱॻ ͍͓͚ͯ͹ͱΓ͋͑ͣͦΕͬΆ͘ͳΔ • value ͱ͔

    Range ͚ͩͰͳ͘ɺ insideUnitCircle Λ࢖͏ͱ͔ • ৚݅ʹԠͯ֬͡཰Λม͑ͨΓ 48
  27. async void Start() { await Title(); await StartGame(); await GameOver();

    await Result(); } async UniTask Title() { titleUi.Show(); await titleUi.OnStartClickAsObservable.ToUniTask(); } 51
  28. ෷͍ͨ͘ͳ͍ਓ͸ • Ҏલࢲ͕࢖͍ͬͯͨࣗಈϏϧυͷεΫϦϓτΛ͓࢖͍͍ͩ͘͞ • git worktree Ͱ৽͍͠ϫʔΫεϖʔεΛ࡞ͬͯϏϧυͯ͠ gh- pages ϒϥϯνʹ

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

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

    • https:/ /github.com/one-night-game-jam • ຖճ twitch Ͱ഑৴ͯ͠Δ • https:/ /www.twitch.tv/noirneo 56