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
660
Unityテスト活動のふりかえり
adarapata
1
710
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
[2026-10-09]一枚の布で作らなくてもいい。 信頼性は「パッチワーク」で紡がれる~既存の運用と新しい可能性をつなぎ合わせてきたCREの話~
tosite
0
110
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
5
4.1k
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
6.7k
S3 TablesのIcebergデータに、AIエージェントからアクセスしてみた / 20261016developersio2026joetsu-accessing-iceberg-in-s3tables-via-agent
kasacchiful
PRO
0
170
Kotlinize Is Not Just Converting to Kotlin
chigichan24
1
170
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
280
最近”作らせてる” ローカルAIアプリの話
akit37
0
480
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
0
550
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
220
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
150
気持ちぃ〜角丸 Squircle
ryu1013
0
320
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
270
Featured
See All Featured
Heart Work Chapter 1 - Part 1
lfama
PRO
10
37k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
380
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
480
Darren the Foodie - Storyboard
khoart
PRO
4
4k
Embracing the Ebb and Flow
colly
88
5.2k
HDC tutorial
michielstock
2
960
Between Models and Reality
mayunak
4
500
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
310
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
410
Building Adaptive Systems
keathley
44
3.3k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
590
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