Update Project

This commit is contained in:
2026-03-20 13:04:43 +02:00
parent 9b587e6cba
commit beae2dea89
2295 changed files with 251259 additions and 33 deletions
@@ -0,0 +1,73 @@
namespace Zenject
{
public interface IDecoratableMonoKernel
{
bool ShouldInitializeOnStart();
void Initialize();
void Update();
void FixedUpdate();
void LateUpdate();
void Dispose();
void LateDispose();
}
public class DecoratableMonoKernel : IDecoratableMonoKernel
{
[InjectLocal]
public TickableManager TickableManager { get; protected set; } = null;
[InjectLocal]
public InitializableManager InitializableManager { get; protected set; } = null;
[InjectLocal]
public DisposableManager DisposablesManager { get; protected set; } = null;
public virtual bool ShouldInitializeOnStart() => true;
public virtual void Initialize()
{
InitializableManager.Initialize();
}
public void Update()
{
TickableManager.Update();
}
public void FixedUpdate()
{
TickableManager.FixedUpdate();
}
public void LateUpdate()
{
TickableManager.LateUpdate();
}
public void Dispose()
{
DisposablesManager.Dispose();
}
public void LateDispose()
{
DisposablesManager.LateDispose();
}
}
public abstract class BaseMonoKernelDecorator : IDecoratableMonoKernel
{
[Inject]
protected IDecoratableMonoKernel DecoratedMonoKernel;
public virtual bool ShouldInitializeOnStart() => DecoratedMonoKernel.ShouldInitializeOnStart();
public virtual void Initialize() => DecoratedMonoKernel.Initialize();
public virtual void Update() => DecoratedMonoKernel.Update();
public virtual void FixedUpdate() => DecoratedMonoKernel.FixedUpdate();
public virtual void LateUpdate() => DecoratedMonoKernel.LateUpdate();
public virtual void Dispose() => DecoratedMonoKernel.Dispose();
public virtual void LateDispose() => DecoratedMonoKernel.LateDispose();
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f054684b4d0f44a1904823270ae3f137
timeCreated: 1587868417
@@ -0,0 +1,10 @@
#if !NOT_UNITY3D
namespace Zenject
{
public class DefaultGameObjectKernel : MonoKernel
{
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 1c47912ae4e51a84d92f1acf689997c8
timeCreated: 1461708048
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: -9996
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,48 @@
using System;
using System.Diagnostics;
namespace Zenject
{
[DebuggerStepThrough]
public class Kernel : IInitializable, IDisposable, ITickable, ILateTickable, IFixedTickable, ILateDisposable
{
[InjectLocal]
TickableManager _tickableManager = null;
[InjectLocal]
InitializableManager _initializableManager = null;
[InjectLocal]
DisposableManager _disposablesManager = null;
public virtual void Initialize()
{
_initializableManager.Initialize();
}
public virtual void Dispose()
{
_disposablesManager.Dispose();
}
public virtual void LateDispose()
{
_disposablesManager.LateDispose();
}
public virtual void Tick()
{
_tickableManager.Update();
}
public virtual void LateTick()
{
_tickableManager.LateUpdate();
}
public virtual void FixedTick()
{
_tickableManager.FixedUpdate();
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8a25347f1a9a6b544b4ef8b643824a6f
timeCreated: 1461708051
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,130 @@
#if !NOT_UNITY3D
#pragma warning disable 649
using ModestTree;
using UnityEngine;
using UnityEngine.Analytics;
namespace Zenject
{
public abstract class MonoKernel : MonoBehaviour
{
[InjectLocal]
TickableManager _tickableManager = null;
[InjectLocal]
InitializableManager _initializableManager = null;
[InjectLocal]
DisposableManager _disposablesManager = null;
[InjectOptional]
private IDecoratableMonoKernel decoratableMonoKernel;
bool _hasInitialized;
bool _isDestroyed;
protected bool IsDestroyed
{
get { return _isDestroyed; }
}
public virtual void Start()
{
if (decoratableMonoKernel?.ShouldInitializeOnStart()??true)
{
Initialize();
}
}
public void Initialize()
{
// We don't put this in start in case Start is overridden
if (!_hasInitialized)
{
_hasInitialized = true;
if (decoratableMonoKernel != null)
{
decoratableMonoKernel.Initialize();
}
else
{
_initializableManager.Initialize();
}
}
}
public virtual void Update()
{
// Don't spam the log every frame if initialization fails and leaves it as null
if (_tickableManager != null)
{
if (decoratableMonoKernel != null)
{
decoratableMonoKernel.Update();
}
else
{
_tickableManager.Update();
}
}
}
public virtual void FixedUpdate()
{
// Don't spam the log every frame if initialization fails and leaves it as null
if (_tickableManager != null)
{
if (decoratableMonoKernel != null)
{
decoratableMonoKernel.FixedUpdate();
}
else
{
_tickableManager.FixedUpdate();
}
}
}
public virtual void LateUpdate()
{
// Don't spam the log every frame if initialization fails and leaves it as null
if (_tickableManager != null)
{
if (decoratableMonoKernel != null)
{
decoratableMonoKernel.LateUpdate();
}
else
{
_tickableManager.LateUpdate();
}
}
}
public virtual void OnDestroy()
{
// _disposablesManager can be null if we get destroyed before the Start event
if (_disposablesManager != null)
{
Assert.That(!_isDestroyed);
_isDestroyed = true;
if (decoratableMonoKernel != null)
{
decoratableMonoKernel.Dispose();
decoratableMonoKernel.LateDispose();
}
else
{
_disposablesManager.Dispose();
_disposablesManager.LateDispose();
}
}
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0ed09ac17d1c3ca44b8064ce22ebba27
timeCreated: 1461708048
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,87 @@
#if !NOT_UNITY3D
using System.Collections.Generic;
using System.Linq;
using ModestTree;
using UnityEngine.SceneManagement;
namespace Zenject
{
public class ProjectKernel : MonoKernel
{
[Inject]
ZenjectSettings _settings = null;
[Inject]
SceneContextRegistry _contextRegistry = null;
// One issue with relying on MonoKernel.OnDestroy to call IDisposable.Dispose
// is that the order that OnDestroy is called in is difficult to predict
// One good thing is that it does follow the heirarchy order (so root game objects
// will have thier OnDestroy called before child objects)
// However, the order that OnDestroy is called for the root game objects themselves
// is largely random
// Within an individual scene, this can be helped somewhat by placing all game objects
// underneath the SceneContext and then also checking the 'ParentNewObjectsUnderRoot'
// property to ensure any new game objects will also be parented underneath SceneContext
// By doing this, we can be guaranteed to have any bound IDisposable's have their
// Dispose called before any game object is destroyed in the scene
// However, when using multiple scenes (each with their own SceneContext) the order
// that these SceneContext game objects are destroyed is random
// So to address that, we explicitly call GameObject.DestroyImmediate for all
// SceneContext's in the reverse order that the scenes were loaded in below
// (this works because OnApplicationQuit is always called before OnDestroy)
// Note that this only works when stopping the app and not when changing scenes
// When changing scenes, if you have multiple scenes loaded at once, you will have to
// manually unload the scenes in the reverse order they were loaded before going to
// the new scene, if you require a predictable destruction order. Or you can always use
// ZenjectSceneLoader which will do this for you
public void OnApplicationQuit()
{
if (_settings.EnsureDeterministicDestructionOrderOnApplicationQuit)
{
DestroyEverythingInOrder();
}
}
public void DestroyEverythingInOrder()
{
ForceUnloadAllScenes(true);
// Destroy project context after all scenes
Assert.That(!IsDestroyed);
DestroyImmediate(gameObject);
Assert.That(IsDestroyed);
}
public void ForceUnloadAllScenes(bool immediate = false)
{
// OnApplicationQuit should always be called before OnDestroy
// (Unless it is destroyed manually)
Assert.That(!IsDestroyed);
var sceneOrder = new List<Scene>();
for (int i = 0; i < SceneManager.sceneCount; i++)
{
sceneOrder.Add(SceneManager.GetSceneAt(i));
}
// Destroy the scene contexts from bottom to top
// Since this is the reverse order that they were loaded in
foreach (var sceneContext in _contextRegistry.SceneContexts.OrderByDescending(x => sceneOrder.IndexOf(x.gameObject.scene)).ToList())
{
if (immediate)
{
DestroyImmediate(sceneContext.gameObject);
}
else
{
Destroy(sceneContext.gameObject);
}
}
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 374b2cd725ea28a46a6377959bb73c9c
timeCreated: 1461708049
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: -9998
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,21 @@
#if !NOT_UNITY3D
using ModestTree;
namespace Zenject
{
public class SceneKernel : MonoKernel
{
// Only needed to set "script execution order" in unity project settings
#if ZEN_INTERNAL_PROFILING
public override void Start()
{
base.Start();
Log.Info("SceneContext.Awake detailed profiling: {0}", ProfileTimers.FormatResults());
}
#endif
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: aff38aaefd39d0d41a92c2707718d15c
timeCreated: 1461708052
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: -9997
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: