private void OnEnable()
    {
        agent        = target as CustomNavMeshAgent;
        navMeshAgent = agent.GetComponent <NavMeshAgent>();
        if (navMeshAgent != null)
        {
            // prevent the user from changing the agent through the NavMeshAgent's inspector
            navMeshAgent.hideFlags = HideFlags.HideInInspector;
        }

        m_AgentTypeID             = serializedObject.FindProperty("m_AgentTypeID");
        m_Radius                  = serializedObject.FindProperty("m_Radius");
        m_Height                  = serializedObject.FindProperty("m_Height");
        m_WalkableMask            = serializedObject.FindProperty("m_WalkableMask");
        m_Speed                   = serializedObject.FindProperty("m_Speed");
        m_Acceleration            = serializedObject.FindProperty("m_Acceleration");
        m_AngularSpeed            = serializedObject.FindProperty("m_AngularSpeed");
        m_StoppingDistance        = serializedObject.FindProperty("m_StoppingDistance");
        m_AutoTraverseOffMeshLink = serializedObject.FindProperty("m_AutoTraverseOffMeshLink");
        m_AutoBraking             = serializedObject.FindProperty("m_AutoBraking");
        m_AutoRepath              = serializedObject.FindProperty("m_AutoRepath");
        m_BaseOffset              = serializedObject.FindProperty("m_BaseOffset");
        m_ObstacleAvoidanceType   = serializedObject.FindProperty("m_ObstacleAvoidanceType");
        m_AvoidancePriority       = serializedObject.FindProperty("m_AvoidancePriority");

        m_TimeToBlock                 = serializedObject.FindProperty("m_TimeToBlock");
        m_UnblockSpeedThreshold       = serializedObject.FindProperty("m_UnblockSpeedThreshold");
        m_BlockRefreshInterval        = serializedObject.FindProperty("m_BlockRefreshInterval");
        m_MinDistanceBoostToStopBlock = serializedObject.FindProperty("m_MinDistanceBoostToStopBlock");
        m_CarvingMoveThreshold        = serializedObject.FindProperty("m_MoveThreshold");
        m_TimeToStationary            = serializedObject.FindProperty("m_TimeToStationary");
        m_CarveOnlyStationary         = serializedObject.FindProperty("m_CarveOnlyStationary");
    }
Beispiel #2
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 #3
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 #4
0
 // Awake is called when the script instance is being loaded
 protected override void Awake()
 {
     base.Awake();
     if (!agent)
     {
         agent = GetComponent <CustomNavMeshAgent>();
     }
 }
Beispiel #5
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 #6
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);
 }
Beispiel #7
0
    /// <summary>
    /// Link this agent to a custom agent and update everything. To be called from CustomNavMeshAgent
    /// after this component is added. Note: in the agent and in the obstacle classes, this
    /// initialization is done in OnCustomEnable; however, in this case the CustomAgent
    /// property is still null during OnCustomEnable.
    /// </summary>
    public void LinkWithCustomAgent(CustomNavMeshAgent customAgent)
    {
        customAgentGameObject = (customAgent != null) ? customAgent.gameObject : null;
        this.customAgent      = customAgent;

        UpdateAgent();
        UpdateMesh();
        UpdateVisibility();

        UpdateParent();
        UpdatePosition();
        UpdateRotation();
        UpdateScale();

        TrySubscribe();
    }
Beispiel #8
0
 /// <summary>
 /// Transfers the parameters of a CustomNavMeshAgent to a NavMeshAgent.
 /// </summary>
 /// <param name="sourceAgent">The CustomNavMeshAgent to copy</param>
 /// <param name="destAgent">The destination NavMeshAgent</param>
 public static void TransferAgentValues(CustomNavMeshAgent sourceAgent, NavMeshAgent destAgent)
 {
     destAgent.agentTypeID             = sourceAgent.AgentTypeID;
     destAgent.radius                  = sourceAgent.Radius;
     destAgent.height                  = sourceAgent.Height;
     destAgent.areaMask                = sourceAgent.AreaMask;
     destAgent.speed                   = sourceAgent.Speed;
     destAgent.acceleration            = sourceAgent.Acceleration;
     destAgent.angularSpeed            = sourceAgent.AngularSpeed;
     destAgent.stoppingDistance        = sourceAgent.StoppingDistance;
     destAgent.autoTraverseOffMeshLink = sourceAgent.AutoTraverseOffMeshLink;
     destAgent.autoBraking             = sourceAgent.AutoBraking;
     destAgent.autoRepath              = sourceAgent.AutoRepath;
     destAgent.baseOffset              = sourceAgent.BaseOffset;
     destAgent.obstacleAvoidanceType   = sourceAgent.ObstacleAvoidanceType;
     destAgent.avoidancePriority       = sourceAgent.AvoidancePriority;
 }
 // Use this for initialization
 private void Start()
 {
     if (!PhotonNetwork.isMasterClient)
     {
         return;
     }
     agent = GetComponent <CustomNavMeshAgent>();
     if (!agent)
     {
         return;
     }
     agent.Speed = speed;
     agent.OnDestinationReached += IncreasePassingCount;
     boundLeft  = TDS_Camera.Instance.CurrentBounds.XMin - 1;
     boundRight = TDS_Camera.Instance.CurrentBounds.XMax + 1;
     Run();
 }
    void UpdateAgent()
    {
        if (CustomAgent != null && Agent != null)
        {
#if UNITY_EDITOR
            Undo.RecordObject(Agent, "");
#endif
            // Update my NavMeshAgent
            CustomNavMeshAgent.TransferAgentValues(CustomAgent, Agent);
            Agent.baseOffset = CustomAgent.Height / 2.0f; // keep mesh centered

#if UNITY_EDITOR
            Undo.RecordObject(Obstacle, "");
#endif
            // Update my NavMeshObstacle
            Obstacle.carvingMoveThreshold    = CustomAgent.CarvingMoveThreshold;
            Obstacle.carvingTimeToStationary = CustomAgent.CarvingTimeToStationary;
            Obstacle.carveOnlyStationary     = CustomAgent.CarveOnlyStationary;
        }
    }
Beispiel #11
0
    private void OnSceneGUI()
    {
                #if UNITY_EDITOR
        selectedAgent = target as CustomNavMeshAgent;

        if (null == selectedAgent)
        {
            return;
        }

        for (int i = 0; i < selectedAgent.destCornerPointList.Count; i++)
        {
            Handles.color = Color.red;
            Handles.DrawSolidDisc(
                selectedAgent.destCornerPointList [i],
                Vector3.up,
                0.05f
                );
        }
                #endif
    }
Beispiel #12
0
 /// <summary>
 /// Checks if this hidden agent is linked with the specified custom agent.
 /// </summary>
 /// <param name="customAgent">The custom agent.</param>
 /// <returns>True if the specified agent is indeed the linked one; otherwise, false.</returns>
 public bool IsLinkedWith(CustomNavMeshAgent customAgent)
 {
     return(CustomAgent == customAgent);
 }
 private void Start()
 {
     target = GameObject.Find("Target").transform;
     agent  = GetComponent <CustomNavMeshAgent>();
 }