Syntriax.Engine/Engine.Core/BehaviourOverride.cs

63 lines
1.6 KiB
C#
Raw Normal View History

2023-11-23 22:07:49 +03:00
using System;
using Microsoft.Xna.Framework;
using Syntriax.Engine.Core.Abstract;
namespace Syntriax.Engine.Core;
public abstract class BehaviourOverride : Behaviour
{
protected IGameObject GameObject => BehaviourController.GameObject;
protected ITransform Transform => BehaviourController.GameObject.Transform;
public BehaviourOverride()
{
OnInitialized += OnInitialize;
OnFinalized += OnFinalize;
2023-11-24 17:20:43 +03:00
OnUnassigned += OnUnassign;
2023-11-23 22:07:49 +03:00
}
2023-11-24 17:20:43 +03:00
protected virtual void OnUnassign() { }
private void OnUnassign(IAssignable assignable) => OnUnassign();
2023-11-23 22:07:49 +03:00
protected virtual void OnInitialize() { }
private void OnInitialize(IInitialize _)
{
BehaviourController.OnPreDraw += PreDraw;
BehaviourController.OnUpdate += Update;
OnInitialize();
}
protected virtual void OnFinalize() { }
private void OnFinalize(IInitialize _)
{
BehaviourController.OnPreDraw -= PreDraw;
BehaviourController.OnUpdate -= Update;
OnFinalize();
}
protected virtual void OnUpdatePreEnabledCheck(GameTime time) { }
protected virtual void OnUpdate(GameTime time) { }
private void Update(IBehaviourController _, GameTime time)
{
OnUpdatePreEnabledCheck(time);
if (!StateEnable.Enabled)
return;
OnUpdate(time);
}
protected virtual void OnPreDrawPreEnabledCheck(GameTime time) { }
protected virtual void OnPreDraw(GameTime time) { }
private void PreDraw(IBehaviourController _, GameTime time)
{
OnPreDrawPreEnabledCheck(time);
if (!StateEnable.Enabled)
return;
OnPreDraw(time);
}
}