Пример #1
0
        private AudioClip getRandomSongFromDirectory(string dir)
        {
            var files = Directory.GetFiles(dir, "*.ogg", SearchOption.AllDirectories);

            if (files.Length == 0)
            {
                Debug.LogWarning($"Music directory '{dir}' did not contain any OGG files, cannot play music.");
                CurrentArtist = "No artist";
                CurrentSong   = "No song";
                return(null);
            }

            // handle case where directory only contains 1 file - we'd want to just play it again instead of
            // excluding it and causing no song to play next
            var filesToChooseFrom = files.Length == 1 ? files : files.Where(f => !f.Equals(_currentSongFilename));

            var randomFile = RandUtil.RandomListElement(filesToChooseFrom);

            _currentSongFilename = randomFile;

            setMetadataFromFilePath(randomFile);
            Debug.Log($"Now playing: {CurrentSong} by {CurrentArtist}");

            return(ResourceManager.Load <ToriiAudioClip>(randomFile, "scene"));
        }
Пример #2
0
        private void spawnPlayerInDream(LevelEntities entities)
        {
            var allSpawns = entities.OfType <SpawnPoint>();

            if (!allSpawns.Any())
            {
                Debug.LogError("No spawn points in dream! Unable to spawn player.");
                return;
            }

            // handle a designated SpawnPoint being used
            if (!string.IsNullOrEmpty(_forcedSpawnID))
            {
                try
                {
                    SpawnPoint spawn = allSpawns.First(e => e.EntityID == _forcedSpawnID);
                    spawn.Spawn();
                    return;
                }
                catch (InvalidOperationException e)
                {
                    Debug.LogError($"Unable to find SpawnPoint with ID '{_forcedSpawnID}'");
                    throw;
                }
            }

            // spawn in a first day-designated spawn if it's the first day
            if (GameSave.CurrentJournalSave.DayNumber == 1)
            {
                var firstDaySpawns = allSpawns.Where(s => s.DayOneSpawn).ToList();
                if (firstDaySpawns.Any())
                {
                    RandUtil.RandomListElement(firstDaySpawns).Spawn();
                    return;
                }
            }

            // make sure we choose a spawn point that isn't a tunnel entrance
            var spawnPoints = allSpawns.Where(s => !s.TunnelEntrance).ToList();

            if (spawnPoints.Any())
            {
                RandUtil.RandomListElement(spawnPoints).Spawn();
                return;
            }

            // otherwise we'll have to spawn on a tunnel entrance... this shouldn't happen so warn the player
            Debug.LogWarning(
                "Unable to find a spawn point that isn't a tunnel entrance -- using a tunnel entrance instead.");
            RandUtil.RandomListElement(allSpawns).Spawn();
        }
Пример #3
0
        public void Transition(Color fadeCol,
                               string dreamPath    = null,
                               bool playSound      = true,
                               string spawnPointID = null)
        {
            if (string.IsNullOrEmpty(dreamPath))
            {
                // choose a random dream that isn't the current dream
                dreamPath = RandUtil.RandomListElement(
                    JournalLoader.Current.LinkableDreams.Where(d => !d.Equals(_currentDreamPath)));
                Debug.Log($"Dream path: {dreamPath}, Current dream path: {_currentDreamPath}");
            }

            _currentDreamPath = dreamPath;
            Dream dream =
                _serializer.Deserialize <Dream>(PathUtil.Combine(Application.streamingAssetsPath, dreamPath));

            Transition(fadeCol, dream, playSound, spawnPointID);
        }
        private void createRandomSound(Soundscape soundscape)
        {
            var randomSound = RandUtil.RandomListElement(soundscape.Sounds);
            var source      = createSourceObject();

            source.clip                  = randomSound.Sound;
            source.spatialBlend          = 1;
            source.loop                  = false;
            source.outputAudioMixerGroup = _mixerGroup;
            source.rolloffMode           = AudioRolloffMode.Linear;

            var angle    = RandUtil.Float(randomSound.MinAngle, randomSound.MaxAngle);
            var distance = RandUtil.Float(randomSound.MinDistance, randomSound.MaxDistance);

            Transform baseTransform = Centre == null ? transform : Centre.transform;

            Vector3 soundPos = baseTransform.position +
                               (Quaternion.AngleAxis(angle, Vector3.up) * baseTransform.forward * distance);

            source.transform.position = soundPos;
            StartCoroutine(playSoundThenDestroy(source));
        }
Пример #5
0
 /// <summary>
 /// Get a random dream from the pool of first day dreams.
 /// </summary>
 /// <returns>The random dream.</returns>
 public string GetFirstDream()
 {
     return(RandUtil.RandomListElement(FirstDream));
 }
Пример #6
0
 /// <summary>
 /// Get a random linkable dream from the pool of linkable dreams.
 /// </summary>
 /// <returns>The random dream.</returns>
 public string GetLinkableDream()
 {
     return(RandUtil.RandomListElement(LinkableDreams));
 }