示例#1
0
 public void OnEnable()
 {
     if (waypointAgent == null)
     {
         waypointAgent = GetComponentInParent <WaypointAgent>();
     }
 }
示例#2
0
    private void OnTriggerEnter(Collider other)
    {
        if (waypointAgent == null)
        {
            Debug.LogError("No waypoint agent is assigned to this object " + name);
            return;
        }

        //Don't freeze in place when not waiting for a trafficlight.
        if (waypointAgent.WaitingForTrafficLight == null)
        {
            return;
        }


        if (other.CompareTag("MovingEntity"))
        {
            WaypointAgent otherAgent = other.GetComponentInParent <WaypointAgent>();

            if (otherAgent == null)
            {
                return;
            }

            if (waypointAgent.TrafficLaneId == otherAgent.TrafficLaneId)
            {
                waypointAgent.WaypointSystemActivated = false;
            }
        }
    }
示例#3
0
        private void Awake()
        {
            waypointAgent = GetComponent <WaypointAgent>();

            //подписка на события достижения точки и обнаружения игрока
            waypointAgent.OnPositionReached.AddListener(OnPositionReached);
            enemyEyes.OnPlayerVisible.AddListener(OnPlayerVisible);
        }
    // Remove an entity from the list
    public void RemoveEntity(WaypointAgent entity)
    {
        if (objectToMove.Contains(entity))
        {
            objectToMove.Remove(entity);
        }

        shouldClean = true;
        objectToMove.TrimExcess();
    }
    //--------------------Private Functions--------------------

    // Spawns the entity within the system....doesn't spawn it with the world. It needs to already exist
    private GameObject SpawnEntity(GameObject objectToSpawn)
    {
        objectToSpawn.transform.parent = transform;
        WaypointAgent agent = objectToSpawn.GetComponent <WaypointAgent>();

        Vector3 targetPosition = new Vector3(((Random.insideUnitSphere.x * 2) * nodeProximityDistance),
                                             0 + (objectToSpawn.GetComponent <Collider>().bounds.extents.magnitude) / 2,
                                             ((Random.insideUnitSphere.z * 2) * nodeProximityDistance));

        agent.currentNodeTarget     = targetPosition + waypointNodes[agent.CurrentIndex].transform.position;
        agent.WaypointSystem        = this;
        agent.WaypointRotation      = rotationMode;
        agent.NodeProximityDistance = nodeProximityDistance;
        agent.SlerpSpeed            = slerpRotationSpeed;

        return(objectToSpawn);
    }
    private void UpdateSystem()
    {
        for (int i = 0; i < objectToMove.Count; ++i)
        {
            if (objectToMove[i] == null)
            {
                objectToMove.TrimExcess();
                continue;
            }

            if (!objectToMove[i].gameObject.activeInHierarchy)
            {
                continue;
            }

            WaypointAgent aiObj = objectToMove[i];

            //Exiting if the target node is
            //outside of the waypointNodes list.
            if (aiObj.CurrentIndex >= waypointNodes.Count)
            {
                if (!looping)
                {
                    RemoveEntity(aiObj);
                    Destroy(aiObj.gameObject);
                    objectToMove.TrimExcess();
                }
                else
                {
                    aiObj.CurrentIndex = 0;
                }

                continue;
            }
        }

        // Trim the list of unnecessary entries
        if (shouldClean && !inRoutine)
        {
            StartCoroutine(CleanList());
        }

        // Reset the update timer
        timeSinceLastUpdate = 0.0f;
    }
示例#7
0
    void Awake()
    {
        agent      = GetComponent <WaypointAgent>();
        animator   = GetComponentInChildren <Animator>();
        photonView = GetComponent <PhotonView>();

        enemyHUD = GetComponentInChildren <EnemyHUD>();

        agent.MoveSpeed = Speed;

        if (DamageType == DamageType.Shared)
        {
            healthStat = new SharedHealthStat(MaxHP);
        }
        else
        {
            healthStat = new UniqueHealthStat(MaxHP, 2);
        }
    }
示例#8
0
    private void OnTriggerExit(Collider other)
    {
        if (waypointAgent == null)
        {
            Debug.LogError("No waypoint agent is assigned to this object " + name);
            return;
        }

        if (other.CompareTag("MovingEntity"))
        {
            WaypointAgent otherAgent = other.GetComponentInParent <WaypointAgent>();

            if (otherAgent == null)
            {
                return;
            }

            if (waypointAgent.TrafficLaneId == otherAgent.TrafficLaneId)
            {
                waypointAgent.WaypointSystemActivated = true;
            }
        }
    }
 public bool ObjectIsOnNode(WaypointAgent obj)
 {
     //Checking if the distance from the object to the target node is less than the proximity distance.
     return(Vector3.Distance(obj.transform.position, obj.currentNodeTarget) < nodeProximityDistance);
 }
示例#10
0
 public void AddWaypointAgent(WaypointAgent newAgent)
 {
     waypointAgents.Add(newAgent);
 }
示例#11
0
    public void InitEntityAtLane(int laneId, GameObject objectToSpawn)
    {
        TrafficLaneData laneData = FindLaneDataById(laneId);

        if (laneData == null)
        {
            Debug.LogError("Lane id " + laneId + " not found!");
            return;
        }

        WaypointManager waypointManager = laneData.GetRandomWaypointManager();

        if (waypointManager == null)
        {
            Debug.LogError("No waypointmanager assigned for lane " + laneId);
            return;
        }


        if (waypointManager.waypointNodes.Count < 1)
        {
            Debug.LogError("No waypoint nodes set!");
            return;
        }


        WaypointAgent waypointAgent = objectToSpawn.GetComponent <WaypointAgent>();

        if (waypointAgent == null)
        {
            Debug.LogError("Entity " + objectToSpawn + " is missing WaypointAgent component!");
            return;
        }

        //Set spawn location and rotation
        Transform spawnLocation = waypointManager.waypointNodes[0].transform;

        objectToSpawn.transform.rotation = spawnLocation.rotation;
        objectToSpawn.transform.position = spawnLocation.position;

        //Assign waypoint systems.
        waypointAgent.WaypointSystem = waypointManager;

        //Reset waypointsystem
        waypointAgent.ResetWaypointTargetToFirst();

        //Update the lane data, add this waypointagent to the lane data list.
        laneData.AddWaypointAgent(waypointAgent);
        laneData.NumberOfEntitiesInLane++;

        //Assign traffic lane id to the waypointagent
        waypointAgent.TrafficLaneId = laneData.id;


        //Add any trafficlights assigned from the lane to the waypoint trafficlight queue.
        //This is the order of trafficlights the waypoint agent will drive through
        for (int i = 0; i < laneData.trafficLights.Count; i++)
        {
            waypointAgent.TrafficlightQueue.Enqueue(laneData.trafficLights[i]);
        }
        waypointAgent.AssignNextTrafficlight();



        //When finished configuring, activate the waypoint system.
        waypointAgent.WaypointSystemActivated = true;


        //Send update to controller with newest state data.
        ClientInstance.SendStateData();
    }
示例#12
0
 void OnEnable()
 {
     this.self = target as WaypointAgent;
     Undo.undoRedoPerformed += this.OnUndoRedo;
 }