Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Zenject Optionalアレコレ
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
いも
December 15, 2018
Programming
1.6k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Zenject Optionalアレコレ
「【年末だよ】Unity お・と・なのLT大会 2018」で発表した資料です
いも
December 15, 2018
More Decks by いも
See All by いも
UnityプログラミングバイブルR6号宣伝&Unity Logging小話
adarapata
0
670
Unityテスト活動のふりかえり
adarapata
1
720
Gather.townはいいぞ その後
adarapata
1
1.7k
Unityでの開発事例
adarapata
3
23k
どこのご家庭にもあるシーンマネージャーの話
adarapata
2
8.9k
Gather.townはいいぞ
adarapata
2
2.5k
宴はいいぞ
adarapata
0
2.3k
わかった気になるモブプログラミング
adarapata
1
190
モブワークっぽいのをやっている話/Trying mobwork
adarapata
2
1.3k
Other Decks in Programming
See All in Programming
AI時代のFlutter品質設計 — アプリ品質を守るQuality Layers
omatty198
0
370
SFCで実現する病院・医療システムの動的組み立て式UI
koukimiura
1
170
社内AIエージェント「Askワンバン」における コストチューニングの取り組み
t0yohei
0
170
自作Discord音声botをLambda MicroVMsに移行した話 / Migrating My Discord Voice Bot to Lambda MicroVMs
akihisaikeda
1
300
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
1.2k
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
4
3.8k
flutter_test のその先へ — Flutter アプリの LLM 機能に「評価」という品質保証を
kosukesaigusa
0
200
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
230
クラウドエージェントは、 何がそんなに便利なのか / what makes cloud agents so useful
rkaga
5
820
あなたの await、OS まで届いてる? strace で覗く JavaScript の非同期
hasutosasaki
1
2.3k
Event is what happens
moro
2
4.1k
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
1.7k
Featured
See All Featured
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
3
1.2k
Intergalactic Javascript Robots from Outer Space
tanoku
273
28k
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
750
The Cult of Friendly URLs
andyhume
79
7.1k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
630
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
980
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1.1k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.5k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Transcript
Zenject Optionalアレコレ いも(@adarapata) 2018/12/15 【年末だよ】Unity お・と・なのLT大会 2018
自己紹介 いも(28) @adarapata XFLAG クライアントエンジニア スマブラSPはガオガエン adarapata.com 2018/12/15 【年末だよ】Unity お・と・なのLT大会
2018
今日の話 2018/12/15 【年末だよ】Unity お・と・なのLT大会 2018
Zenject OptionalExtras ZenjectはDIとは直接関係ないけど便利な機能をいく つか提供している。 公式ドキュメントはあるけど、あまり日本語記事はな いので使われてるかどうかはわからない。需要はない かもしれない。 でも話そう。 2018/12/15 【年末だよ】Unity
お・と・なのLT大会 2018
Optionalな方々 TestFramework Signals MemoryPoolMonitor Re ection Baking 2018/12/15 【年末だよ】Unity お・と・なのLT大会
2018
TestFramework みんな大好きテスト機能の提供。現在は3種類のテス トに区分されている。 UnitTest IntegrationTest SceneTest Unity標準のテストクラスではDiContainerが用意さ れていないのでDIしているコードのテストが書きづ らい。なのでZenjectのテストクラスを使う。 2018/12/15
【年末だよ】Unity お・と・なのLT大会 2018
UnitTestとIntegrationTest https://speakerdeck.com/adarapata/zenjecttotesuto 以前に書いたのでこちらもどうぞ。 2018/12/15 【年末だよ】Unity お・と・なのLT大会 2018
SceneTest 最近追加されてたテスト。シーンをサッと呼べる機能 が追加されている public class FooSceneTest : SceneTestFixture { [UnityTest]
public IEnumerator TestScene() { yield return LoadScene("FooScene"); // FooシーンにFooクラスがバインドされてるか? Assert.That(SceneContainer.HasBinding<Foo>()); } } 複数のシーンも一気に読み込める 2018/12/15 【年末だよ】Unity お・と・なのLT大会 2018
こんなときに便利そう Zenject使いつつテスト書きたいとき というか書くならContainerを扱うのでほぼ必須 基本的にはUnitTestとIntegrationTest書いておけば なんとかなりそう SceneTestは、そもそもシーン単位でどういう風に 書いてくとベストなのかは模索中 UIにイベント流す機能もないので自前でがんば る 2018/12/15
【年末だよ】Unity お・と・なのLT大会 2018
Signals いわゆるPub/Subメッセージ機構 SignalBusを使ってメッセージを発行・購読できる UnityだとPub/SubはUniRx.MessageBrokerがよく 使われている印象 同一Container内だけでやり取りできるのが Zenject Signalの特徴 Unityアドカレで詳細を書いたのでそちらもご査収 ください。
http://adarapata.hatenablog.com/entry/2018/12/ 13/041721 2018/12/15 【年末だよ】Unity お・と・なのLT大会 2018
購読側 public class UserJoinedSignal { public string Username; } public
class Greeter { public void SayHello(UserJoinedSignal userJoinedInfo) { Debug.Log($"Hello{userJoinedInfo.Username}!"); } } 送りたいイベントをclass or structにして、購読側は 受け皿のメソッドを作る 2018/12/15 【年末だよ】Unity お・と・なのLT大会 2018
発行側 public class GameInitializer : IInitializable { readonly SignalBus _signalBus;
public GameInitializer(SignalBus signalBus) { _signalBus = signalBus; } public void Initialize() { _signalBus.Fire( new UserJoinedSignal() { Username = "Bob" }); } } Containerから SignalBus を受け取り、 Fire で送信する 2018/12/15 【年末だよ】Unity お・と・なのLT大会 2018
Installer public class GameInstaller : MonoInstaller<GameInstaller> { public override void
InstallBindings() { SignalBusInstaller.Install(Container); // Signalを定義 Container.DeclareSignal<UserJoinedSignal>(); Container.Bind<Greeter>().AsSingle(); // Signalが来た時にGreeter.SayHelloに投げる Container.BindSignal<UserJoinedSignal>() .ToMethod<Greeter>(x => x.SayHello) .FromResolve(); Container.BindInterfacesTo<GameInitializer>() .AsSingle(); } } SignalをBindする 2018/12/15 【年末だよ】Unity お・と・なのLT大会 2018
こんなときに便利そう 不特定多数からのイベントを受け取らなくてはな らないとき Pub/Subで疎結合にしたいけどグローバルにどこか らでもメッセージが来るのは不安というときに なんでもかんでもSignalにするとあちらこちらに飛 び回ってデバッグしにくいのでほどほどに(個人の 感想です) 2018/12/15 【年末だよ】Unity
お・と・なのLT大会 2018
MemoryPoolMonitor Zenject MemoryPoolの状況を可視化できる そもそもZenject MemoryPoolとは 2018/12/15 【年末だよ】Unity お・と・なのLT大会 2018
Zenject MemoryPool Unityでのオブジェクトプールを実現する機能 Containerでインスタンスを管理してくれる PureClass、MonoBehavior両方対応 MonoBehaviorの場合Active/非Activeで対応す るっぽい MemoryPoolは標準機能で、MonitorがOptional 2018/12/15 【年末だよ】Unity
お・と・なのLT大会 2018
public class Foo { public class Pool : MemoryPool<Foo> {
} } public class Bar { readonly Foo.Pool _fooPool; readonly List<Foo> _foos = new List<Foo>(); public Bar(Foo.Pool fooPool) { _fooPool = fooPool; } public void AddFoo() => _foos.Add(_fooPool.Spawn()); public void RemoveFoo() { var foo = _foos[0]; _fooPool.Despawn(foo); _foos.Remove(foo); } } 2018/12/15 【年末だよ】Unity お・と・なのLT大会 2018
public class TestInstaller : MonoInstaller<TestInstaller> { public override void InstallBindings()
{ Container.Bind<Bar>().AsSingle(); Container.BindMemoryPool<Foo, Foo.Pool>(); } } Factoryと同じ感じで書ける 2018/12/15 【年末だよ】Unity お・と・なのLT大会 2018
MonoBehaviorの場合は MonoMemoryPool でOK public class FooBehavior : MonoBehavior { public
class Pool : MonoMemoryPool<Foo> { } } Zenject Factoryと組み合わせることもできる public class Foo : IPoolable<IMemoryPool> { private IMemoryPool _pool; public void OnSpawned(IMemoryPool p1) => _pool = p1; public void OnDespawned() => _pool = null; public class Factory : PlaceholderFactory<Foo> { } } // Foo.Factory.Create()の裏側でPoolされる Container.BindFactory<Foo, Foo.Factory>() .FromPoolableMemoryPool<Foo>(x => x.WithInitialSize(10)); 2018/12/15 【年末だよ】Unity お・と・なのLT大会 2018
Zenject Pool Monitorで現在Poolしている数を 確認できる NumTotal: 現在Poolしている合計数 NumActive: 現在使われている数 Num Inactive:
現在使われていない数 2018/12/15 【年末だよ】Unity お・と・なのLT大会 2018
こんなときに便利そう Zenjectに乗っかりつつも、メモリコストを抑えた いとき オブジェクトプールを自分で書くのが面倒な時に Zenject Factoryの恩恵に与れるのがミソ Monitorがあるので把握しやすい でもガリガリチューニングしたいときはそもそも Zenject使わない可能性 2018/12/15
【年末だよ】Unity お・と・なのLT大会 2018
Re ection Baking Installerの実行時間を短縮する機能 Inject時のリフレクションがボトルネックになりが ちなので、対象のメソッドやクラスの情報を予め Bakeしておく staticに情報が保持されるので速いっぽい。 裏側では cecil
というライブラリが動いてる https://github.com/jbevain/cecil 既存のアセンブリに任意のILを差し込める凄いやつ 2018/12/15 【年末だよ】Unity お・と・なのLT大会 2018
[Create] -> [Zenject] -> [Re ection Baking Settings] 設定ファイルが爆誕する 2018/12/15
【年末だよ】Unity お・と・なのLT大会 2018
Include Assemblies にBake対象のアセンブリを指定 名前空間のパターンマッチングでもいいらしい(未 検証) エディタ上で確認したいときは Is Enabled In Editor
2018/12/15 【年末だよ】Unity お・と・なのLT大会 2018
早くなるの? ZEN_INTERNAL_PROFILING で確認してみる ↑を入れるとSceneContext.Awakeの実行ログが吐か れて便利 公式のSample SpaceFighter で確認してみる 2018/12/15 【年末だよ】Unity
お・と・なのLT大会 2018
Before After 2018/12/15 【年末だよ】Unity お・と・なのLT大会 2018
サンプルプロジェクト規模だとわから なかった 公式だと起動時間が最大45%短縮したらしい 俺たちのZenjectを信じろ 2018/12/15 【年末だよ】Unity お・と・なのLT大会 2018
こんなときに便利そう Installer部分がボトルネックになっているとき 検証は簡単なのでとりあえずやってみるのは良さ そう ファイルサイズが少し増えるはずなので注意 2018/12/15 【年末だよ】Unity お・と・なのLT大会 2018
まとめ Optional Extrasは色々面白いのがある ZEN_INTERNAL_PROFILING で数値見ていこう 日本語記事は少ないのでみんなで書こう 流行って! 2018/12/15 【年末だよ】Unity お・と・なのLT大会
2018
おわり 2018/12/15 【年末だよ】Unity お・と・なのLT大会 2018