diff --git a/.vscode/settings.json b/.vscode/settings.json index 1bdbcbf..9d15f56 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -66,5 +66,5 @@ "explorer.fileNesting.patterns": { "*.sln": "*.csproj" }, - "dotnet.defaultSolution": "TutorialRts.slnx" + "dotnet.defaultSolution": "TutorilaRTS.slnx" } \ No newline at end of file diff --git a/Assets/Scripts/Unit.cs b/Assets/Scripts/Unit.cs index 8d9fc2f..876f252 100644 --- a/Assets/Scripts/Unit.cs +++ b/Assets/Scripts/Unit.cs @@ -1,5 +1,16 @@ +using System.Collections; +using Unity.VisualScripting; using UnityEngine; using UnityEngine.AI; +using UnityEngine.Events; + +public enum UnitState +{ + Idle, + Move, + MoveToResource, + Gather +} public class Unit : MonoBehaviour { @@ -7,6 +18,16 @@ public class Unit : MonoBehaviour public GameObject selectionVisual; private NavMeshAgent navAgent; private SelectionMarker selectionMarker; + [Header("Stats")] + public UnitState state; + public int gatherAmount; + public float gatherRate; + private float lastGatherTime; + private ResourceSource resource; + //events + public class StateChangeEvent : UnitEvent { } + public StateChangeEvent onStateChange; + public Player player; void Awake() { @@ -27,6 +48,24 @@ public class Unit : MonoBehaviour selectionMarker.DestroySelectionMarker(); selectionMarker = null; } + switch(state) + { + case UnitState.Move + { + MoveUpdate(); + break; + } + case UnitState.MoveToResource + { + MoveToResourceUpdate(); + break; + } + case UnitState.Gather + { + GatherUpdate(); + break; + } + } } public void ToggleSelectionVisual(bool selected) { @@ -43,4 +82,33 @@ public class Unit : MonoBehaviour navAgent.SetDestination(pos); selectionMarker = marker; } + //move to a resource and begin to gather it + public void GatherResource(ResourceSource resource, Vector3 pos) + { + + } + void SetState(UnitState toState) + { + state = toState; + //calling the event + if(onStateChange != null) + onStateChange.Invoke(state); + if(toState == UnitState.Idle) + { + navAgent.isStopped = true; + navAgent.ResetPath(); + } + } + void MoveUpdate() + { + + } + void MoveToResourceUpdate() + { + + } + void GatherUpdate() + { + + } } diff --git a/Assets/Scripts/UnitCommander.cs b/Assets/Scripts/UnitCommander.cs index 92abf4f..cb1092b 100644 --- a/Assets/Scripts/UnitCommander.cs +++ b/Assets/Scripts/UnitCommander.cs @@ -74,6 +74,17 @@ public class UnitCommander : MonoBehaviour //called when we command units to gather a resource void UnitsGatherResource(ResourceSource resource, Unit[] units) { - + if(units.Length == 1) + { + units[0].GatherResource(resource, UnitMover.GetUnitDestinationAroundResource(resource.transform.position)); + } + else + { + Vector3[] destinations = UnitMover.GetUnitGroupDestinationsAroundResource(resource.transform.position, units.Length); + for(int x = 0; x + + +