Beispiel #1
0
    /// <summary>
    /// Register a custom agent and it's hidden agent to prevent the custom agent
    /// from spawning more hidden agents then needed.
    /// </summary>
    /// <param name="customAgent">The custom agent</param>
    /// <param name="hiddenAgent">The hidden agent</param>
    public static void RegisterAgent(CustomNavMeshAgent customAgent, HiddenNavMeshAgent hiddenAgent)
    {
        Instance.customToHiddenAgents[customAgent.gameObject] = hiddenAgent.gameObject;
        Instance.hiddenToCustomAgents[hiddenAgent.gameObject] = customAgent.gameObject;

        hiddenAgent.OnRegister();
    }
Beispiel #2
0
 /// <summary>
 /// Unregister the correspondence betweem a custom agent and it's hidden agent.
 /// </summary>
 /// <param name="customAgent">The custom agent</param>
 /// <param name="hiddenAgent">The hidden agent</param>
 public static void UnregisterAgent(CustomNavMeshAgent customAgent, HiddenNavMeshAgent hiddenAgent)
 {
     if (Instance != null)
     {
         Instance.hiddenToCustomAgents.Remove(hiddenAgent.gameObject);
         Instance.customToHiddenAgents.Remove(customAgent.gameObject);
     }
 }
Beispiel #3
0
 /// <summary>
 /// Tries to retrieve the custom agent from an hidden agent. Returns false if the custom agent is null.
 /// </summary>
 /// <param name="hiddenAgent">The hidden agent</param>
 /// <param name="customAgent">The custom agent</param>
 /// <returns></returns>
 public static bool TryGetCustomAgent(HiddenNavMeshAgent hiddenAgent, out CustomNavMeshAgent customAgent)
 {
     if (Instance == null)
     {
         customAgent = null;
     }
     else
     {
         Instance.hiddenToCustomAgents.TryGetValue(hiddenAgent.gameObject, out GameObject customObject);
         customAgent = (customObject != null) ? customObject.GetComponent <CustomNavMeshAgent>() : null;
     }
     return(customAgent != null);
 }
Beispiel #4
0
 /// <summary>
 /// Tries to retrieve the hidden agent from a custom agent. Returns false if the hidden agent is null.
 /// </summary>
 /// <param name="customAgent">The custom agent</param>
 /// <param name="hiddenAgent">The hidden agent</param>
 /// <returns></returns>
 public static bool TryGetHiddenAgent(CustomNavMeshAgent customAgent, out HiddenNavMeshAgent hiddenAgent)
 {
     if (Instance == null)
     {
         hiddenAgent = null;
     }
     else
     {
         Instance.customToHiddenAgents.TryGetValue(customAgent.gameObject, out GameObject hiddenObject);
         hiddenAgent = (hiddenObject != null) ? hiddenObject.GetComponent <HiddenNavMeshAgent>() : null;
     }
     return(hiddenAgent != null);
 }