private void Awake() { Type type = Type.GetType(PickTargetChangedStrategy.ToString()); //target type TargetChangedStrategy = (BehaviourStrategy)Activator.CreateInstance(type); // an instance of target type this.enabled = false; }
void setEnemyBehaviours(GameObject spawnedEnemy, Enemy enemy) { BehaviourStrategy behaviour = spawnedEnemy.GetComponent <BehaviourStrategy>(); behaviour.setHealth(enemy.health); behaviour.setDamage(enemy.damage); behaviour.setSpeed(enemy.speed); behaviour.setPlayerObject(this.playerObj.transform); }
private void Awake() { Health = new SensitiveIntValue(CompareMode.LessThan, healthInitValue, 0); Health.Triggered.AddListener(OnHealthZero); Type type = Type.GetType(DeathStrategy.ToString()); //target type healthZeroStrategy = (BehaviourStrategy)Activator.CreateInstance(type); // an instance of target type }
// Start is called before the first frame update void Start() { // Creating the default strategy behaviours walkNearHome = new WalkNearHomeBehaviour(GetComponent <NavMeshAgent>(), home); List <AgentBehaviour> behaviours = new List <AgentBehaviour> { walkNearHome }; BehaviourStrategy defaultStrategy = new BehaviourStrategy(behaviours, (state) => { return(true); }); ControlCenter = new ControlCenter(gameObject, defaultStrategy); }
void OnTriggerEnter(Collider collider) { if (collider.tag == "Enemy") { GameObject collided = collider.gameObject; BehaviourStrategy enemy = collided.GetComponent <BehaviourStrategy>(); ChangeLightSettings(5.03f, 10.46f); TakeDamage((int)enemy.getDamage()); collider.gameObject.SetActive(false); Instantiate(explosionObject, collider.gameObject.transform.position, Quaternion.identity); GameLogger.GetInstance().PlayerGotHit(new PlayerHitInfo(0, collided.name, enemy.getDamage())); } }
// Start is called before the first frame update void Start() { // Creating the default strategy behaviours flyAround = new FlyAroundBehaviour(GetComponent <NavMeshAgent>(), tree, tree2, tree3, tree4); migrate = new MigrateBehaviour(GetComponent <NavMeshAgent>(), palm); List <AgentBehaviour> behaviours = new List <AgentBehaviour> { flyAround, migrate }; BehaviourStrategy defaultStrategy = new BehaviourStrategy(behaviours, (state) => { return(true); }); ControlCenter = new ControlCenter(gameObject, defaultStrategy); }
private void InitializeControlCenter(GameObject self, BehaviourStrategy defaultStrategy) { StrategyManager = new StrategyManager(defaultStrategy) { EnableBehaviourSwitcing = false, EnableMultipleStrategies = false }; ArbitrationManager = new ArbitrationManager { EnableArbitrationRules = false, }; CommunicationManager = new CommunicationManager(self) { EnableBroadcasting = false }; }
/* This method will be called before Update, FixedUpdate and LateUpdate * This makes sure that the first method which gets called each frame (which can vary) * forces the controlcenter to calculate which behaviour(s) to execute exactly one time * each frame */ public void PreExecuteCalculations() { if (lastArbitratedFrame != Time.frameCount) { strategyToUse = StrategyManager.GetStrategy(); // Get the strategy to use toExecute = ArbitrationManager.Arbitrate(strategyToUse.GetBehaviours()); // Get the behaviour(s) to execute if (CommunicationManager.EnableBroadcasting) { AgentBehaviour broadcastedBehaviourToDo = CommunicationManager.GetBehaviourToDo(toExecute); if (broadcastedBehaviourToDo != null) { toExecute.Clear(); toExecute.Add(broadcastedBehaviourToDo); } } SuppressBehaviours(); lastArbitratedFrame = Time.frameCount; } }
void Start() { // Timers lifeTime = new Stopwatch(); takeHealthTimer = new Stopwatch(); lifeTime.Start(); takeHealthTimer.Start(); // Setting up the startup state state = new AgentState { hydrationLevel = 35, foodSupply = 50, happy = false, isAtDisco = false }; // Creating the default strategy behaviours walkAround = new WalkAroundBehaviour(GetComponent <NavMeshAgent>()); eatFood = new EatNearbyFoodBehaviour(GetComponent <NavMeshAgent>(), transform, state); findWater = new GetWaterBehaviour(GetComponent <NavMeshAgent>(), transform, state); awayFromMonster = new RunAwayFromMonster(GetComponent <NavMeshAgent>(), transform); List <AgentBehaviour> behaviours = new List <AgentBehaviour> { walkAround, eatFood, findWater, awayFromMonster }; homeAndRest = new GetHomeAndRestBehaviour(GetComponent <NavMeshAgent>(), restingPlace, state); // Added later to the default strategy defaultStrategy = new BehaviourStrategy(behaviours, (state) => { return(true); }); ControlCenter = new ControlCenter(gameObject, defaultStrategy); ControlCenter.SetStateObject(state); // Making additional strategies IStrategyManager strategyManager = ControlCenter.StrategyManager; strategyManager.EnableMultipleStrategies = true; AgentBehaviour goToDisco = new GoToDiscoBehaviour(GetComponent <NavMeshAgent>(), disco); AgentBehaviour dance = new DanceBehaviour(ControlCenter.CommunicationManager, GetComponent <NavMeshAgent>(), gameObject, state); AgentBehaviour goHomeAndSleep = new GetHomeAndSleepBehaviour(GetComponent <NavMeshAgent>(), restingPlace, state); List <AgentBehaviour> nightTimeStrategy = new List <AgentBehaviour> { goToDisco, dance, goHomeAndSleep }; BehaviourStrategy strategy = new BehaviourStrategy(nightTimeStrategy, (state) => { if (GameManager.isNight) { return(true); } else { return(false); } }); strategyManager.AddAdditionalStrategy(strategy); // Setting up the communication manager ICommunicationManager communicationManager = ControlCenter.CommunicationManager; communicationManager.EnableBroadcasting = true; BroadcastSettings settings = new BroadcastSettings { AgentTag = "Agent", BroadcastRadius = 20 }; settings.SetSuppressibleBehaviours(new List <AgentBehaviour> { dance, goToDisco }); communicationManager.SetBroadcastSettings(settings); // Add arbitration rules ControlCenter.ArbitrationManager.EnableArbitrationRules = true; ControlCenter.ArbitrationManager.AddArbitrationRule((inputBehaviors) => { if (inputBehaviors.Contains(findWater) && inputBehaviors.Contains(awayFromMonster)) { List <AgentBehaviour> toExecute = new List <AgentBehaviour> { findWater }; return(new ArbitrationRule(toExecute, true)); } return(default);
public ControlCenter(GameObject self, BehaviourStrategy defaultStrategy) { InitializeControlCenter(self, defaultStrategy); }