mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-26 22:10:17 +00:00
cache list of ped AIs
This commit is contained in:
parent
c48d59d7a1
commit
f4a2e25d21
2 changed files with 21 additions and 6 deletions
|
@ -78,7 +78,7 @@ namespace SanAndreasUnity.Behaviours
|
|||
StartCoroutine(SpawnPedWithAI(targetZone));
|
||||
}
|
||||
}
|
||||
NumberOfPeds = GameObject.FindObjectsOfType<Ped_AI>().Count();
|
||||
NumberOfPeds = Ped_AI.AllPedAIs.Count;
|
||||
lastUpdateTime = Time.time;
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ namespace SanAndreasUnity.Behaviours
|
|||
yield return null;
|
||||
}
|
||||
|
||||
if (GameObject.FindObjectsOfType<Ped_AI>().Where(p => Math.Abs(Vector3.Distance(p.transform.position, targetZone)) < MaxNPCDistance).Count() > MaxNumberOfNPCAtSpawnPoint)
|
||||
if (Ped_AI.AllPedAIs.Count(p => Math.Abs(Vector3.Distance(p.transform.position, targetZone)) < MaxNPCDistance) > MaxNumberOfNPCAtSpawnPoint)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using Assets.Scripts.Importing.Paths;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Assets.Scripts.Importing.Paths;
|
||||
using UnityEngine;
|
||||
using SanAndreasUnity.Utilities;
|
||||
using SanAndreasUnity.Net;
|
||||
|
@ -13,6 +15,9 @@ namespace SanAndreasUnity.Behaviours
|
|||
}
|
||||
public class Ped_AI : MonoBehaviour
|
||||
{
|
||||
private static readonly List<Ped_AI> s_allPedAIs = new List<Ped_AI>();
|
||||
public static IReadOnlyList<Ped_AI> AllPedAIs => s_allPedAIs;
|
||||
|
||||
[SerializeField] private Vector3 currentNodePos;
|
||||
[SerializeField] private Vector3 targetNodePos;
|
||||
[SerializeField] private Vector2 targetNodeOffset; // Adding random offset to prevent peds to have the exact destination
|
||||
|
@ -36,13 +41,23 @@ namespace SanAndreasUnity.Behaviours
|
|||
|
||||
public Ped MyPed { get; private set; }
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
this.MyPed = this.GetComponentOrLogError<Ped>();
|
||||
this.MyPed = this.GetComponentOrThrow<Ped>();
|
||||
Ped.onDamaged += Ped_onDamaged;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
s_allPedAIs.Add(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
s_allPedAIs.Remove(this);
|
||||
}
|
||||
|
||||
private void Ped_onDamaged(Ped hitPed, DamageInfo dmgInfo, Ped.DamageResult dmgResult)
|
||||
{
|
||||
if(hitPed.Equals(this.MyPed))
|
||||
|
|
Loading…
Reference in a new issue