59 lines
1.5 KiB
C#
59 lines
1.5 KiB
C#
|
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;
|
||
|
}
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
}
|