/// <summary> /// Adds an agent to the manager. /// </summary> /// <param name="position"> /// The current position of the agent within the navigation mesh. /// </param> /// <param name="agentParams">The agent configuration.</param> /// <returns> /// A reference to the agent object created by the manager, or null on error. /// </returns> public CrowdAgent AddAgent(Vector3 position , CrowdAgentParams agentParams) { if (IsDisposed) { return(null); } IntPtr ptr = IntPtr.Zero; CrowdAgentCoreState initialState = new CrowdAgentCoreState(); int index = CrowdManagerEx.dtcAddAgent(root , ref position , ref agentParams , ref ptr , ref initialState); if (index == -1) { return(null); } mAgents[index] = new CrowdAgent(this, ptr, index); agentStates[index] = initialState; return(mAgents[index]); }
/// <summary> /// Removes an agent from the manager. /// </summary> /// <remarks> /// <para> /// The <see cref="CrowdAgent"/> object will be immediately disposed. Continued use will /// result in undefined behavior. /// </para> /// </remarks> /// <param name="agent">The agent to remove.</param> public void RemoveAgent(CrowdAgent agent) { for (int i = 0; i < mAgents.Length; i++) { if (mAgents[i] == agent) { CrowdManagerEx.dtcRemoveAgent(root, agent.managerIndex); agent.Dispose(); mAgents[i] = null; // Don't need to do anything about the core data array. } } }
/// <summary> /// Removes an agent from the manager. /// </summary> /// <remarks> /// <para> /// The <see cref="CrowdAgent"/> object will be immediately disposed. Continued use will /// result in undefined behavior. /// </para> /// </remarks> /// <param name="agent">The agent to remove.</param> public void RemoveAgent(CrowdAgent agent) { for (int i = 0; i < mAgents.Length; i++) { if (mAgents[i] == agent) { CrowdManagerEx.dtcRemoveAgent(root, agent.managerIndex); agent.Dispose(); mAgents[i] = null; // Don't need to do anything about the core data array. } } }
/// <summary> /// Adds an agent to the manager. /// </summary> /// <param name="position"> /// The current position of the agent within the navigation mesh. /// </param> /// <param name="agentParams">The agent configuration.</param> /// <returns> /// A reference to the agent object created by the manager, or null on error. /// </returns> public CrowdAgent AddAgent(Vector3 position , CrowdAgentParams agentParams) { if (IsDisposed) return null; IntPtr ptr = IntPtr.Zero; CrowdAgentCoreState initialState = new CrowdAgentCoreState(); int index = CrowdManagerEx.dtcAddAgent(root , ref position , ref agentParams , ref ptr , ref initialState); if (index == -1) return null; mAgents[index] = new CrowdAgent(this, ptr, index); agentStates[index] = initialState; return mAgents[index]; }