NavMeshModifierVolume.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Collections.Generic;
  2. namespace UnityEngine.AI
  3. {
  4. [ExecuteInEditMode]
  5. [AddComponentMenu("Navigation/NavMeshModifierVolume", 31)]
  6. [HelpURL("https://github.com/Unity-Technologies/NavMeshComponents#documentation-draft")]
  7. public class NavMeshModifierVolume : MonoBehaviour
  8. {
  9. [SerializeField]
  10. Vector3 m_Size = new Vector3(4.0f, 3.0f, 4.0f);
  11. public Vector3 size { get { return m_Size; } set { m_Size = value; } }
  12. [SerializeField]
  13. Vector3 m_Center = new Vector3(0, 1.0f, 0);
  14. public Vector3 center { get { return m_Center; } set { m_Center = value; } }
  15. [SerializeField]
  16. int m_Area;
  17. public int area { get { return m_Area; } set { m_Area = value; } }
  18. // List of agent types the modifier is applied for.
  19. // Special values: empty == None, m_AffectedAgents[0] =-1 == All.
  20. [SerializeField]
  21. List<int> m_AffectedAgents = new List<int>(new int[] { -1 }); // Default value is All
  22. static readonly List<NavMeshModifierVolume> s_NavMeshModifiers = new List<NavMeshModifierVolume>();
  23. public static List<NavMeshModifierVolume> activeModifiers
  24. {
  25. get { return s_NavMeshModifiers; }
  26. }
  27. void OnEnable()
  28. {
  29. if (!s_NavMeshModifiers.Contains(this))
  30. s_NavMeshModifiers.Add(this);
  31. }
  32. void OnDisable()
  33. {
  34. s_NavMeshModifiers.Remove(this);
  35. }
  36. public bool AffectsAgentType(int agentTypeID)
  37. {
  38. if (m_AffectedAgents.Count == 0)
  39. return false;
  40. if (m_AffectedAgents[0] == -1)
  41. return true;
  42. return m_AffectedAgents.IndexOf(agentTypeID) != -1;
  43. }
  44. }
  45. }