NavMeshModifier.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Collections.Generic;
  2. namespace UnityEngine.AI
  3. {
  4. [ExecuteInEditMode]
  5. [AddComponentMenu("Navigation/NavMeshModifier", 32)]
  6. [HelpURL("https://github.com/Unity-Technologies/NavMeshComponents#documentation-draft")]
  7. public class NavMeshModifier : MonoBehaviour
  8. {
  9. [SerializeField]
  10. bool m_OverrideArea;
  11. public bool overrideArea { get { return m_OverrideArea; } set { m_OverrideArea = value; } }
  12. [SerializeField]
  13. int m_Area;
  14. public int area { get { return m_Area; } set { m_Area = value; } }
  15. [SerializeField]
  16. bool m_IgnoreFromBuild;
  17. public bool ignoreFromBuild { get { return m_IgnoreFromBuild; } set { m_IgnoreFromBuild = 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<NavMeshModifier> s_NavMeshModifiers = new List<NavMeshModifier>();
  23. public static List<NavMeshModifier> 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. }