You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			74 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C#
		
	
			
		
		
	
	
			74 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C#
		
	
| using Entitas;
 | |
| using UnityEngine;
 | |
| using Game;
 | |
| 
 | |
| public class AISystem : IExecuteSystem, IInitializeSystem
 | |
| {
 | |
|     private IGroup<GameEntity> _entities;
 | |
| 
 | |
|     public void Initialize()
 | |
|     {
 | |
|         _entities = Util.GetGroup(GameMatcher.AI);
 | |
|     }
 | |
| 
 | |
|     public void Execute()
 | |
|     {
 | |
|         foreach (var entity in _entities)
 | |
|         {
 | |
|             UpdateAI(entity);
 | |
|             UpdateAIHungry(entity);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private static void UpdateAIHungry(GameEntity entity)
 | |
|     {
 | |
|         var ai = entity.aI;
 | |
|         var hp = entity.hp;
 | |
|         if (!hp.IsAlive)
 | |
|         {
 | |
|             return;
 | |
|         }
 | |
| 
 | |
|         if (ai.IsHungryFull.Value)
 | |
|         {
 | |
|             return;
 | |
|         }
 | |
| 
 | |
|         if (ai.AttackPermit.Value)
 | |
|         {
 | |
|             return;
 | |
|         }
 | |
| 
 | |
|         var newHungry = ai.Hungry.Value + ai.HungryIncrease * ai.HungryIncreaseRate * Time.deltaTime;
 | |
|         ai.Hungry.Value = Mathf.Min(ai.HungryMax.Value, newHungry);
 | |
|         if (ai.Hungry.Value >= ai.HungryMax.Value)
 | |
|         {
 | |
|             ai.IsHungryFull.Value = true;
 | |
|             ai.Hungry.Value = 0;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private static void UpdateAI(GameEntity entity)
 | |
|     {
 | |
|         var ai = entity.aI;
 | |
|         var skill = entity.skill;
 | |
|         var hp = entity.hp;
 | |
|         if (!hp.IsAlive)
 | |
|         {
 | |
|             return;
 | |
|         }
 | |
| 
 | |
|         ai.ThinkCdNow -= Time.deltaTime;
 | |
|         if (ai.ThinkCdNow > 0)
 | |
|         {
 | |
|             return;
 | |
|         }
 | |
| 
 | |
|         ai.ThinkCdNow = ai.ThinkCdMax;
 | |
|         if (skill.IsRunning)
 | |
|         {
 | |
|             return;
 | |
|         }
 | |
|         ai.BehaviorTree.Tick();
 | |
|     }
 | |
| } |