You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.8 KiB

using ET.PeopleBehave;
using UnityEngine;
using UnityEngine.AI;
namespace ET
{
[FriendClass(typeof(Gather))]
[FriendClass(typeof(ResourceViewComponent))]
[FriendClass(typeof(ResourcePoint))]
[FriendClass(typeof(Construct))]
[FriendClass(typeof(PeopleViewComponent))]
[FriendClass(typeof(People))]
public static class PeopleViewHelper
{
public static string GetHeadIconUrlByGender(int gender)
{
var iconName = gender == 0? "Head_M" : "Head_F";
var url = $"ui://{FUIPackage.Common}/{iconName}";
return url;
}
public static void CheckWork(this People self)
{
PeopleBehaveComponent.Instance?.HandlePeopleBehave(self);
}
public static void UpdateAnimatorByBehave(People people)
{
var pAnimator = people.GetComponent<PeopleAnimatorComponent>();
if (pAnimator == null)
{
return;
}
int behave = people.GetBehaveType();
switch (behave)
{
case ConstBehaveType.BEHAVE_IDLE:
pAnimator.StopAll();
pAnimator.PlayAnimation(PeopleAnimEnum.Idle);
break;
case ConstBehaveType.BEHAVE_PREPARE_GATHER:
case ConstBehaveType.BEHAVE_PREPARE_CONSTRUCT:
pAnimator.StopAll();
pAnimator.PlayAnimation(PeopleAnimEnum.Run);
break;
case ConstBehaveType.BEHAVE_GATHER:
pAnimator.StopAll();
pAnimator.PlayAnimation(PeopleAnimEnum.Gather);
break;
case ConstBehaveType.BEHAVE_CONSTRUCT:
pAnimator.StopAll();
pAnimator.PlayAnimation(PeopleAnimEnum.Construct);
break;
default:
Debug.LogWarning("Unhandled behave type:" + behave);
break;
}
}
public static Vector3 GetRandomMovePos(PeopleViewComponent peopleViewComponent, float radius)
{
var navAgent = peopleViewComponent.Agent;
var path = new NavMeshPath();
Vector3 newDest = peopleViewComponent.PeopleRoot.transform.position;
int count = 0;
do
{
Vector3 randomDir = Random.insideUnitCircle * radius;
newDest = randomDir + peopleViewComponent.PeopleRoot.transform.position;
navAgent.CalculatePath(newDest, path);
count++;
if (count > 10)
{
break;
}
}
while (path.status != NavMeshPathStatus.PathComplete);
return newDest;
}
}
}