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
いも
December 15, 2018
Programming
1.5k
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
650
Unityテスト活動のふりかえり
adarapata
1
700
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
180
モブワークっぽいのをやっている話/Trying mobwork
adarapata
2
1.3k
Other Decks in Programming
See All in Programming
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
300
仕様駆動開発による爆速プロダクト開発 / Bakusoku Spec Driven Development
kobakei
0
150
Workers Cache を知る
syumai
0
310
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
280
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
5.2k
Are APIs Still Relevant in the AI Era?
soyuka
0
370
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
130
Heart of Swift Concurrency
koher
0
1.1k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
390
難しいけど、読めた。- OSSの入口に立った話。
sts11142
0
130
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
0
340
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
450
Featured
See All Featured
[RailsConf 2023] Rails as a piece of cake
palkan
59
7k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
270
Building Applications with DynamoDB
mza
96
7.2k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.7k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
470
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
750
Product Roadmaps are Hard
iamctodd
55
13k
Marketing to machines
jonoalderson
1
5.8k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
380
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