diff --git a/Assets/Scripts/NPC/NPCBrainSystem/DecisionTypes.meta b/Assets/Scripts/NPC/NPCBrainSystem/DecisionTypes.meta new file mode 100644 index 00000000..c7fcb72e --- /dev/null +++ b/Assets/Scripts/NPC/NPCBrainSystem/DecisionTypes.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 56939ec6b1c7ba4418f60df6bf032cd8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/NPC/NPCBrainSystem/DecisionTypes/NPCDecision.cs b/Assets/Scripts/NPC/NPCBrainSystem/DecisionTypes/NPCDecision.cs new file mode 100644 index 00000000..9ed38438 --- /dev/null +++ b/Assets/Scripts/NPC/NPCBrainSystem/DecisionTypes/NPCDecision.cs @@ -0,0 +1,17 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public abstract class NPCDecision : ScriptableObject +{ + protected Coroutine executeRoutine; + + public abstract IEnumerator ExecuteCoroutine(NPCBrain npc); + public void Execute(NPCBrain npc) + { + executeRoutine = npc.StartCoroutine(ExecuteCoroutine(npc)); + } + public abstract void Interrupt(NPCBrain npc); + + public bool IsRunning() => executeRoutine != null; +} \ No newline at end of file diff --git a/Assets/Scripts/NPC/NPCBrainSystem/NPCDecision.cs.meta b/Assets/Scripts/NPC/NPCBrainSystem/DecisionTypes/NPCDecision.cs.meta similarity index 100% rename from Assets/Scripts/NPC/NPCBrainSystem/NPCDecision.cs.meta rename to Assets/Scripts/NPC/NPCBrainSystem/DecisionTypes/NPCDecision.cs.meta diff --git a/Assets/Scripts/NPC/NPCBrainSystem/DecisionTypes/NPCPatrolDecision.cs b/Assets/Scripts/NPC/NPCBrainSystem/DecisionTypes/NPCPatrolDecision.cs new file mode 100644 index 00000000..aad4c0f6 --- /dev/null +++ b/Assets/Scripts/NPC/NPCBrainSystem/DecisionTypes/NPCPatrolDecision.cs @@ -0,0 +1,69 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.AI; +using UnityEngine.Events; + +[CreateAssetMenu(fileName = "PatrolDecision", menuName = "RiftMayhem/AI/Decisions/Patrol")] +public class NPCPatrolDecision : NPCDecision +{ + [Header("Settings:")] + [SerializeField] private float distanceToChangePatrolDestination; + [SerializeField] private float patrolAgentSpeed; + + NavMeshAgent agent; + Vector3 patrolDestination = new Vector3(); + + public UnityEvent OnPatrolReachedDestination = new UnityEvent(); + + + public override IEnumerator ExecuteCoroutine(NPCBrain npc) + { + SetupAgent(npc); + + StartPatrollingToNewPosition(); + + yield return new WaitUntil(() => IsPathComplete()); + + OnPatrolReachedDestination.Invoke(); + } + + public override void Interrupt(NPCBrain npc) + { + if (executeRoutine != null) + npc.StopCoroutine(executeRoutine); + } + + + + //Helpers + protected void StartPatrollingToNewPosition() + { + agent.speed = patrolAgentSpeed; + + patrolDestination.x = Random.Range(-5, 5); + patrolDestination.y = 0f; + patrolDestination.z = Random.Range(-5, 5); + + agent.SetDestination(agent.transform.position + patrolDestination); + agent.isStopped = false; + } + + protected bool IsPathComplete() + { + if (Vector3.Distance(agent.destination, agent.transform.position) <= agent.stoppingDistance) + { + if (!agent.hasPath || agent.velocity.sqrMagnitude == 0f) + { + return true; + } + } + return false; + } + + protected void SetupAgent(NPCBrain npc) + { + agent = npc.Agent; + } + +} diff --git a/Assets/Scripts/NPC/NPCBrainSystem/DecisionTypes/NPCPatrolDecision.cs.meta b/Assets/Scripts/NPC/NPCBrainSystem/DecisionTypes/NPCPatrolDecision.cs.meta new file mode 100644 index 00000000..76e8b527 --- /dev/null +++ b/Assets/Scripts/NPC/NPCBrainSystem/DecisionTypes/NPCPatrolDecision.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cc8abedb55d773e46aab9bba344516df +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/NPC/NPCBrainSystem/NPCBrain.cs b/Assets/Scripts/NPC/NPCBrainSystem/NPCBrain.cs index c4758e53..b738fb0e 100644 --- a/Assets/Scripts/NPC/NPCBrainSystem/NPCBrain.cs +++ b/Assets/Scripts/NPC/NPCBrainSystem/NPCBrain.cs @@ -1,10 +1,25 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.AI; public class NPCBrain : MonoBehaviour { + [Header("Decision Profile")] + [SerializeField] private NPCDecisionProfile decisionProfile; + NavMeshAgent agent; + public NavMeshAgent Agent => agent; + + private void Start() + { + StartCoroutine(Decide()); + } + + IEnumerator Decide() + { + yield return null; + } } diff --git a/Assets/Scripts/NPC/NPCBrainSystem/NPCDecision.cs b/Assets/Scripts/NPC/NPCBrainSystem/NPCDecision.cs deleted file mode 100644 index ba9d8334..00000000 --- a/Assets/Scripts/NPC/NPCBrainSystem/NPCDecision.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public abstract class NPCDecision : ScriptableObject -{ - public abstract void Execute(NPCController npc); -} \ No newline at end of file diff --git a/Assets/Starfield Skybox/Skybox.mat b/Assets/Starfield Skybox/Skybox.mat index f126a32d..f8db3567 100644 --- a/Assets/Starfield Skybox/Skybox.mat +++ b/Assets/Starfield Skybox/Skybox.mat @@ -94,7 +94,7 @@ Material: - _Mode: 0 - _OcclusionStrength: 1 - _Parallax: 0.02 - - _Rotation: 11.08514 + - _Rotation: 12.507187 - _SmoothnessTextureChannel: 0 - _SpecularHighlights: 1 - _SrcBlend: 1