/
crypt
/
NumbersPlay
Обзор
Документация
Войти
/
crypt
/
NumbersPlay
Код
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Assets/Plugins/Zenject/Source/Util/ZenjectStateMachineBehaviourAutoInjecter.cs
40 строк
1 KB
Crypt
start
16 ноя 2025, 14:28
16 ноя 2025, 14:28
1482007
Код
Авторство
О чём код?
using ModestTree; using UnityEngine; namespace Zenject { public class ZenjectStateMachineBehaviourAutoInjecter : MonoBehaviour { DiContainer _container; Animator _animator; [Inject] public void Construct(DiContainer container) { _container = container; _animator = GetComponent<Animator>(); Assert.IsNotNull(_animator); } // The unity docs (https://unity3d.com/learn/tutorials/modules/beginner/5-pre-order-beta/state-machine-behaviours) // mention that StateMachineBehaviour's should only be retrieved in the Start method // which is why we do it here public void Start() { // Animator can be null when users create GameObjects directly so in that case // Just don't bother attempting to inject the behaviour classes if (_animator != null) { var behaviours = _animator.GetBehaviours<StateMachineBehaviour>(); if (behaviours != null) { foreach (var behaviour in behaviours) { _container.Inject(behaviour); } } } } } }