Ejemplo n.º 1
0
        ///--------------------------------------------------------------------
        /// Sound Event methods
        ///--------------------------------------------------------------------

        public SoundEvent(LiveEntity src, Vector3 pos, float rad, SoundIntensity val = SoundIntensity.NORMAL)
        {
            _source    = src;
            _origin    = pos;
            _radius    = rad;
            _intensity = val;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a sound event and calls EmitSoundEvent on the specified ISoundEmitter; applies SND_DIST_MOD to the AudioSource.maxDistance
        /// </summary>
        public void CreateSoundEvent(LiveEntity ent, AudioSource src, SoundIntensity type = SoundIntensity.NORMAL)
        {
            if (ent == null)
            {
                return;
            }

            if (src == null)
            {
                return;
            }

            ent.EmitSoundEvent(new SoundEvent(ent, src.transform.position, src.maxDistance * SND_DIST_MOD, type));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Do something with received sound events
        /// </summary>
        protected override void ProcessSoundEvents()
        {
            if (SoundEventList != null && SoundEventList.Count > 0)
            {
                for (int i = 0; i < SoundEventList.Count; i++)
                {
                    Vector3 origin = SoundEventList[i].Origin;
                    float   rad    = SoundEventList[i].Radius;

                    // Check if it's in range; if not, continue
                    if (!Util.CheckDistSqr(origin, this.transform.position, rad))
                    {
                        continue;
                    }

                    // Check if we're already interested in something closer to us
                    if (TargetPos != Vector3.zero)
                    {
                        if (Util.CheckDistSqr(origin, this.transform.position) > Util.CheckDistSqr(TargetPos, this.transform.position))
                        {
                            continue;
                        }
                    }

                    LiveEntity     ent       = SoundEventList[i].Source;
                    GameObject     src       = SoundEventList[i].Source?.gameObject;
                    SoundIntensity intensity = SoundEventList[i].Intensity;

                    // Predators investigate sounds if they don't currently have a target and the source did not come from an object
                    if (TargetObj == null && Params.Predator)
                    {
                        if (src == null)
                        {
                            if (intensity >= SoundIntensity.NOTEWORTHY || (MovePos == Vector3.zero && TargetPos == Vector3.zero))
                            {
                                SetTargetPos(origin);
                            }

                            continue;
                        }
                    }

                    // If the heard entity is another Npc
                    if (ent is Npc npc)
                    {
                        // Prey ignore other prey
                        if (!Params.Predator && !npc.Params.Predator)
                        {
                            continue;
                        }
                    }

                    if (ent != null)
                    {
                        TrackEntity(ent);

                        if (intensity >= SoundIntensity.NOTEWORTHY)
                        {
                            Behavior.SetIgnoreSightCheck(true);
                            SetTargetObj(src, ent);
                        }
                    }
                }

                SoundEventList.Clear();
            }
        }