SHADE_Y3/Assets/Scripts/Gameplay/AIBehaviour/AIRework/HomeOwnerAI.cs

106 lines
3.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Reflection.PortableExecutable;
using System.Text;
using System.Threading.Tasks;
using SHADE;
using SHADE_Scripting.Gameplay.AIBehaviour.AIRework.States;
namespace SHADE_Scripting.Gameplay.AIBehaviour.AIRework
{
public class HomeOwnerAI:Script
{
public float idleDuration = 1.0f;
public float timeoutDuration = 2.0f;
public GameObject patrolPointParent;
public float patrolSpeed = 2.0f;
public float chaseSpeed = 3.0f;
public float alertCooldown = 0.0f;
public GameObject player;
[NonSerialized]
public IEnumerable<Transform> patrolPointPool;
protected override void awake()
{
StateMachine machine = GetScript<StateMachine>();
if(machine)
{
Dictionary<Type, BaseState> dictionary = new Dictionary<Type, BaseState>();
dictionary.Add(typeof(IdleState), new IdleState(machine));
dictionary.Add(typeof(PatrolState), new PatrolState(machine));
dictionary.Add(typeof(TimeoutState), new TimeoutState(machine));
dictionary.Add(typeof(ChaseState), new ChaseState(machine));
dictionary.Add(typeof(AlertState), new AlertState(machine));
machine.InitStateMachine(dictionary);
}
patrolPointPool = patrolPointParent.GetComponentsInChildren<Transform>();
}
protected override void update()
{
if(alertCooldown > 0.0f)
{
alertCooldown -= Time.DeltaTimeF;
}
else
{
alertCooldown = 0.0f;
}
RigidBody rigid = GetComponent<RigidBody>();
if(rigid)
{
rigid.AngularVelocity = Vector3.Zero;
}
}
public bool ShouldTransitAlert()
{
AILineOfSight los = GetScript<AILineOfSight>();
if (los)
{
if (los.withinSight && alertCooldown <= 0.0f)
{
return true;
}
}
return false;
}
public void RotateToPlayer()
{
//Transform playerTransform = player.GetComponent<Transform>();
////Rotate to face player.
//Transform aiTransform = GetComponent<Transform>();
//if(playerTransform && aiTransform)
//{
// Vector3 direction = playerTransform.GlobalPosition - aiTransform.GlobalPosition;
// Quaternion currentRotation = aiTransform.LocalRotation;
// Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(direction.x, direction.z), 0.0f);
// aiTransform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, 5.0f * (float)Time.FixedDeltaTime);
//}
}
}
}