예제 #1
0
    /// <summary>
    /// Plays the clip at tile's location, on the channel group chanGroup. Pitch ranges from -freqRange to +freqRange in semitones.
    /// Volume ranges from -volRange to No change in decibels.
    /// </summary>
    /// <param name="clip">Sound to Play.</param>
    /// <param name="tile">Tile's location to play at. If null, plays at camera's position.</param>
    /// <param name="chanGroup">Chan group to play the sound on.</param>
    /// <param name="freqRange">Frequency range in semitones.</param>
    /// <param name="volRange">Volume range in decibels.</param>
    public void PlaySoundAt(SoundClip clip, Tile tile, string chanGroup = "master", float freqRange = 0f, float volRange = 0f, float cooldownTime = 0.1f)
    {
        if (clip == null || !clip.CanPlay())
        {
            return;
        }

        clip.SetCooldown(cooldownTime);
        ChannelGroup channelGroup;

        if (AudioManager.channelGroups.TryGetValue(chanGroup, out channelGroup) == false)
        {
            channelGroup = AudioManager.channelGroups["master"];
        }

        FMOD.System soundSystem = AudioManager.SoundSystem;
        Channel     channel;

        soundSystem.playSound(clip.Get(), channelGroup, true, out channel);
        if (tile != null)
        {
            VECTOR tilePos = GetVectorFrom(tile);
            channel.set3DAttributes(ref tilePos, ref zero, ref zero);
        }

        if (!freqRange.AreEqual(0f))
        {
            float pitch = Mathf.Pow(1.059f, Random.Range(-freqRange, freqRange));
            channel.setPitch(pitch);
        }

        if (!volRange.AreEqual(0f))
        {
            float curVol;
            channel.getVolume(out curVol);
            float volChange = Random.Range(-volRange, 0f);
            channel.setVolume(curVol * DecibelsToVolume(volChange));
        }

        channel.set3DLevel(SettingsKeyHolder.LocationalSound ? 0.75f : 0f);
        channel.setPaused(false);
    }
예제 #2
0
    /// <summary>
    /// Plays the clip at tile's location, on the channel group chanGroup. Pitch ranges from -freqRange to +freqRange in semitones.
    /// Volume ranges from -volRange to No change in decibels.
    /// </summary>
    /// <param name="clip">Sound to Play.</param>
    /// <param name="tile">Tile's location to play at. If null, plays at camera's position.</param>
    /// <param name="chanGroup">Chan group to play the sound on.</param>
    /// <param name="freqRange">Frequency range in semitones.</param>
    /// <param name="volRange">Volume range in decibels.</param>
    public void PlaySoundAt(Sound clip, Tile tile, string chanGroup = "master", float freqRange = 0f, float volRange = 0f)
    {
        if (!AudioManager.channelGroups.ContainsKey(chanGroup))
        {
            chanGroup = "master";
        }

        ChannelGroup channelGroup = AudioManager.channelGroups[chanGroup];

        FMOD.System soundSystem = AudioManager.SoundSystem;
        Channel     channel;

        soundSystem.playSound(clip, channelGroup, true, out channel);
        if (tile != null)
        {
            VECTOR tilePos = GetVectorFrom(tile);
            channel.set3DAttributes(ref tilePos, ref zero, ref zero);
        }

        if (!freqRange.AreEqual(0f))
        {
            float pitch = Mathf.Pow(1.059f, Random.Range(-freqRange, freqRange));
            channel.setPitch(pitch);
        }

        if (!volRange.AreEqual(0f))
        {
            float curVol;
            channel.getVolume(out curVol);
            float volChange = Random.Range(-volRange, 0f);
            channel.setVolume(curVol * DecibelsToVolume(volChange));
        }

        channel.set3DLevel(0.75f);
        channel.setPaused(false);
    }
예제 #3
0
 private static bool AreNotEqual(float left, float right) => !left.AreEqual(right, Vector1DF.Eps);
예제 #4
0
    private void GetNewJob()
    {
        float needPercent = 0;
        Need  need        = null;

        foreach (Need n in needs)
        {
            if (n.Amount > needPercent)
            {
                need        = n;
                needPercent = n.Amount;
            }
        }

        if (needPercent > 50 && needPercent < 100 && need.RestoreNeedFurn != null)
        {
            if (World.Current.CountFurnitureType(need.RestoreNeedFurn.Type) > 0)
            {
                MyJob = new Job(null, need.RestoreNeedFurn.Type, need.CompleteJobNorm, need.RestoreNeedTime, null, Job.JobPriority.High, false, true, false);
            }
        }

        if (needPercent.AreEqual(100.0f) && need != null && need.CompleteOnFail)
        {
            MyJob = new Job(CurrTile, null, need.CompleteJobCrit, need.RestoreNeedTime * 10, null, Job.JobPriority.High, false, true, true);
        }

        // Get the first job on the queue.
        if (MyJob == null)
        {
            MyJob = World.Current.jobQueue.Dequeue();

            // Check if we got a job from the queue.
            if (MyJob == null)
            {
                Debug.ULogChannel("Character", name + " did not find a job.");
                MyJob = new Job(
                    CurrTile,
                    "Waiting",
                    null,
                    UnityEngine.Random.Range(0.1f, 0.5f),
                    null,
                    Job.JobPriority.Low,
                    false);
                MyJob.JobDescription = "job_waiting_desc";
            }
            else
            {
                if (MyJob.tile == null)
                {
                    Debug.ULogChannel("Character", name + " found a job.");
                }
                else
                {
                    Debug.ULogChannel("Character", name + " found a job at x " + MyJob.tile.X + " y " + MyJob.tile.Y + ".");
                }
            }
        }

        // Get our destination from the job.
        DestTile = MyJob.tile;

        // If the destination tile does not have neighbours that are walkable it's very likely that they can't be walked to
        if (DestTile != null)
        {
            if (DestTile.HasWalkableNeighbours() == false)
            {
                Debug.ULogChannel("Character", "No neighbouring floor tiles! Abandoning job.");
                AbandonJob(false);
                return;
            }
        }

        MyJob.OnJobStopped += OnJobStopped;

        // Immediately check to see if the job tile is reachable.
        // NOTE: We might not be pathing to it right away (due to
        // requiring materials), but we still need to verify that the
        // final location can be reached.
        Profiler.BeginSample("PathGeneration");
        if (MyJob.IsNeed)
        {
            // This will calculate a path from current tile to destination tile.
            pathAStar = new Path_AStar(World.Current, CurrTile, DestTile, need.RestoreNeedFurn.Type, 0, false, true);
        }
        else
        {
            pathAStar = new Path_AStar(World.Current, CurrTile, DestTile);
        }

        Profiler.EndSample();

        if (pathAStar != null && pathAStar.Length() == 0)
        {
            Debug.ULogChannel("Character", "Path_AStar returned no path to target job tile!");
            AbandonJob(false);
            return;
        }

        if (MyJob.adjacent)
        {
            IEnumerable <Tile> reversed = pathAStar.Reverse();
            reversed  = reversed.Skip(1);
            pathAStar = new Path_AStar(new Queue <Tile>(reversed.Reverse()));
            DestTile  = pathAStar.EndTile();
            jobTile   = DestTile;
        }
        else
        {
            jobTile = MyJob.tile;
        }

        MyJob.IsBeingWorked = true;
    }