using System;
using LanLib.UpdateManager.Jobs.Internal;
using UnityEngine;
namespace LanLib.UpdateManager.Jobs
{
///
/// abstract class with automatic registration in .
///
///
/// Instances will register themselves for job scheduling in the OnEnable message and unregister in the OnDisable message.
///
///
public abstract class AJobBehaviour : MonoBehaviour, ITransformJobUpdatable
where TData : struct, IUpdateTransformJob
{
///
/// Whether job data should be synchronized every frame.
/// By default, returns false.
///
///
/// Override in subclasses implementing and return true
/// to automatically register objects for job data synchronization every frame.
///
public virtual bool SynchronizeJobDataEveryFrame => false;
protected virtual void OnEnable()
{
this.RegisterInManager(SynchronizeJobDataEveryFrame);
}
protected virtual void OnDisable()
{
this.UnregisterInManager();
}
public Transform Transform => transform;
///
/// Returns the job data for the first job run.
///
///
/// Override this in child classes to use data other than in the first scheduled job run.
///
///
public virtual TData InitialJobData => default;
///
/// Shortcut for UpdateTransformJobManager<TData>.Instance.GetData(this).
///
///
public TData JobData => this.GetJobData();
#if UNITY_EDITOR
///
/// Whether job data should be synchronized in the OnValidate message.
/// By default, returns true.
///
///
/// Override in subclasses implementing and return false
/// to avoid automatic job data synchronization during OnValidate.
///
protected virtual bool SynchronizeJobDataOnValidate => true;
///
/// Synchronizes job data on Play mode if returns true.
///
protected virtual void OnValidate()
{
if (Application.isPlaying && SynchronizeJobDataOnValidate)
{
this.SynchronizeJobDataOnce();
}
}
#endif
}
///
/// Alias for .
///
///
/// Deprecated: use instead and implement
/// in job definition to compile jobs with Burst.
///
[Obsolete("Use AJobBehaviour<> and implement IBurstUpdateTransformJob<> in job definition instead.")]
public abstract class AJobBehaviour : AJobBehaviour
where TData : struct, IUpdateTransformJob
where TJob : struct, IInternalUpdateTransformJob
{
}
}