private void UpdateDistance(TravelerData traveler)
        {
            if (OnDistanceChanged != null)
            {
                OnDistanceChanged(m_Data, traveler);
            }

            if (m_Data.numEmissionsToDestroyEmitter > 0 &&
                m_Data.numEmissions >= m_Data.numEmissionsToDestroyEmitter)
            {
                Destroy(gameObject);
            }
        }
Exemple #2
0
        private void UpdatePosition(TravelerData traveler)
        {
            if (traveler != m_Data)
            {
                return;
            }

            transform.position = new Vector3(traveler.position.x, traveler.position.y, transform.position.z);
            if (OnPositionChanged != null)
            {
                OnPositionChanged(traveler);
            }
        }
        private void EmitPackage(TravelerData traveler)
        {
            if (traveler != m_Traveler.Data)
            {
                return;
            }

            GameObject package = (GameObject)Instantiate(m_TimedEmitterPackage.gameObject,
                                                         traveler.position, Quaternion.identity);
            TimedEmitter emitterInPackage = package.GetComponent <TimedEmitter>();
            Site         site             = m_Path[m_PathIndex];

            emitterInPackage.PrefabToSpawn = site.packageContent;

            SetDestination(++m_PathIndex);
        }
        private static void UpdateDestination(TravelerData traveler)
        {
            Vector2 offset = traveler.destination - traveler.position;

            if (offset.magnitude > traveler.deltaDistance)
            {
                return;
            }

            traveler.position       = traveler.destination;
            traveler.hasDestination = false;

            if (OnArrived != null)
            {
                OnArrived(traveler);
            }
        }
        private void Emit(TravelerData traveler, ItemType emissionType)
        {
            foreach (Emission emission in m_Emissions)
            {
                if (emissionType != emission.emissionType)
                {
                    continue;
                }

                if (emission.prefabToSpawn != null)
                {
                    Instantiate(emission.prefabToSpawn,
                                new Vector3(traveler.position.x, traveler.position.y, 0f),
                                Quaternion.identity
                                );
                }
            }
        }
        public void OnDisable(TravelerData traveler)
        {
            if (!m_Travelers.Contains(traveler))
            {
                return;
            }

            if (m_AddTravelers.Contains(traveler))
            {
                m_AddTravelers.Remove(traveler);
            }

            if (m_RemoveTravelers.Contains(traveler))
            {
                return;
            }

            m_RemoveTravelers.Remove(traveler);
        }
        private void Emit(TravelerData traveler, ItemType emissionType)
        {
            float change = GetChange(emissionType);

            if (change == 0f)
            {
                return;
            }

            m_Quantity += change;
            if (m_Quantity >= m_Capacity)
            {
                if (OnFull != null)
                {
                    OnFull(emissionType);
                }
            }

            UpdateView();
        }
Exemple #8
0
        public static float SetDestination(TravelerData traveler, Vector2 destination)
        {
            traveler.hasDestination = true;
            traveler.destination    = destination;
            Vector2 offset   = destination - traveler.position;
            float   distance = offset.magnitude;

            if (distance == 0f)
            {
                return(0f);
            }

            if (traveler.speed <= 0f)
            {
                return(0f);
            }

            traveler.rotation = Vector2Utils.AngleBetweenPoints(traveler.position, destination);
            float duration = distance / traveler.speed;

            return(duration);
        }
        /// <summary>
        /// Max one emission per update.
        /// </summary>
        private void UpdateEmission(DistanceEmitterData emitter, TravelerData traveler)
        {
            if (emitter.emissionType == ItemType.Unknown)
            {
                return;
            }

            emitter.remainingDistance += traveler.deltaDistance;
            if (emitter.rateOverDistance > emitter.remainingDistance)
            {
                return;
            }

            emitter.remainingDistance -= emitter.rateOverDistance;

            emitter.numEmissions++;

            if (OnEmitted != null)
            {
                OnEmitted(traveler, emitter.emissionType);
            }
        }