Untitled

 avatar
unknown
csharp
4 years ago
2.3 kB
19
Indexable
    public enum TimelineType //Types of things that timeline can control
    {
        Enemy, Projectile, All, None
    }
    
    public enum TimelineEntryType //Enums representing executable timeline elements
    {
        Teleport, Linear, Sin, Arc, Destroy, Pause, Animation, SpawnPrefab, Attack, Empty
    }

    #region TimelineEntries
    
    [Serializable]
    public class TimelineEntry
    {
        public virtual TimelineEntryType TimelineType { get; private set; }
        public virtual TimelineType[] ValidTypes => new[] {Movement.TimelineType.None};

        /* Called when the timeline entry is reached in the sequence.
         * return function lets the timeline manager know when the action is finished */
        public virtual void Execute(GameObject receiver, out Func<bool> finishCheck) { finishCheck = () => false; }
    }
    
    public class TeleportEntry : TimelineEntry
    {
        public override TimelineEntryType TimelineType => TimelineEntryType.Teleport;
        public override TimelineType[] ValidTypes => new[] {Movement.TimelineType.All};

        public Vector2 TeleportVector;

        public override void Execute(GameObject receiver, out Func<bool> finishCheck)
        {
            receiver.transform.Translate(TeleportVector);
            finishCheck = () => true;
        }
    }
    
    public class PauseEntry : TimelineEntry
    {
        public override TimelineEntryType TimelineType => TimelineEntryType.Pause;
        public override TimelineType[] ValidTypes => new[] {Movement.TimelineType.All};

        public float PauseTimeSeconds;

        public override void Execute(GameObject receiver, out Func<bool> finishCheck)
        {
            var finishTime = Time.time + PauseTimeSeconds;
            finishCheck = () => Time.time > finishTime;
        }
    }
    
    #endregion
    
    [CreateAssetMenu(menuName = "Behavior Timeline")] //Add entry to Unity's Create Asset menu
    public class BehaviorTimelineData : ScriptableObject
    {
        /*  Holds an array of timeline "instructions" that will execute sequentially.
         *  Data will be stored here, execution will be done in a MonoBehaviour */
        
        [SerializeField] private List<TimelineEntry> timelineEntries = new();
    }
Editor is loading...