Local AI Testing & Interactive Tech Tab
Refactored game loop to allow full local testing Added AI controller abstractions Added ability to save database to local copy for offline testing Tech Tab is now interactive, has properties panel
This commit is contained in:
parent
43d5ebdd35
commit
af88788e4f
50 changed files with 5799 additions and 712 deletions
43
Assets/Scripts/ServerShared/Agents/AgentController.cs
Normal file
43
Assets/Scripts/ServerShared/Agents/AgentController.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using static Unity.Mathematics.math;
|
||||
using Random = Unity.Mathematics.Random;
|
||||
|
||||
public class AgentController
|
||||
{
|
||||
public Entity Entity { get; }
|
||||
public EntityAgent EntityAgent { get; }
|
||||
public GameContext Context { get; }
|
||||
public ZoneData Zone { get; set; }
|
||||
|
||||
private Locomotion _locomotion;
|
||||
private Random _random = new Random((uint) (DateTime.Now.Ticks%uint.MaxValue));
|
||||
|
||||
public AgentController(GameContext context, ZoneData zone, Entity entity)
|
||||
{
|
||||
Entity = entity;
|
||||
Zone = zone;
|
||||
Context = context;
|
||||
EntityAgent = new EntityAgent(context, zone, entity);
|
||||
_locomotion = new Locomotion(entity);
|
||||
EntityAgent.CurrentBehavior = _locomotion;
|
||||
RandomTarget();
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
{
|
||||
EntityAgent.Update(delta);
|
||||
var distance = length(_locomotion.Objective.Position - Entity.Position);
|
||||
Context.Log($"Agent Distance: {distance}");
|
||||
if(distance < 20)
|
||||
RandomTarget();
|
||||
}
|
||||
|
||||
private void RandomTarget()
|
||||
{
|
||||
var entities = Context.ZoneEntities(Zone).ToArray();
|
||||
_locomotion.Objective = entities[_random.NextInt(entities.Length)];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue