no message

This commit is contained in:
2026-03-19 22:32:52 +00:00
parent 539ffe3cd0
commit 623ad6f509
5 changed files with 92 additions and 2 deletions

View File

@@ -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<UnitState> { }
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()
{
}
}

View File

@@ -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 <units.Length; x++)
{
units[x].GatherResource(resource, destinations[x]);
}
}
}
}

View File

@@ -1,3 +1,4 @@
using GAP_ParticleSystemController;
using UnityEngine;
using UnityEngine.UIElements;
@@ -51,4 +52,10 @@ public class UnitMover : MonoBehaviour
}
return destinations;
}
public static Vector3 GetUnitDestinationAroundResource(Vector3 resourcePos)
{
float angle = Random.Range(0, 360);
Vector3 dir = new Vector3(Mathf.Sin(angle * Mathf.Deg2Rad), 0, Mathf.Cos(angle * Mathf.Deg2Rad));
return resourcePos;
}
}