Advertisement
Guest User

Plan Template

a guest
Apr 28th, 2025
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Collections;
  5. using Unity.Entities.UniversalDelegates;
  6. using UnityEngine;
  7.  
  8. public abstract class PseudoPlannerBasePlan
  9. {
  10.     #region plan handling
  11.     public PseudoPlanner planner;
  12.     protected List<BotBaseState> States;
  13.     public List<List<Func<bool>>> AdvanceConditions;
  14.     public int index;
  15.    
  16.     public abstract void MonitorBreak();
  17.     public abstract void Exit();
  18.    
  19.     public virtual void Enter()
  20.     {
  21.         index = 0;
  22.         planner.botMotor.SwitchState(States[0]);
  23.         planner.ResetDelays();
  24.     }
  25.     public virtual void Run()
  26.     {
  27.        
  28.     }
  29.    
  30.     public virtual void MonitorAdvance()
  31.     {
  32.         if (AllTrue(AdvanceConditions[index]))
  33.             GoNextStep();
  34.     }
  35.    
  36.     protected void GoNextStep()
  37.     {
  38.         index += 1;
  39.         planner.botMotor.SwitchState(States[index]);
  40.     }
  41.  
  42.     protected bool AllTrue(List<Func<bool>> Conditions)
  43.     {
  44.         if (Conditions.Any())
  45.             return Conditions.All(x => x());
  46.         else return false;
  47.     }
  48.    
  49.     protected bool ConditionsSuccesful(int i)
  50.     {
  51.         return index == i && AllTrue(AdvanceConditions[i]);
  52.     }
  53.      
  54.     #endregion
  55.    
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement