Ejemplo n.º 1
0
    // Play a random ambient sound every so many seconds
    IEnumerator PlayAmbience(AmbientSound sounds)
    {
        AudioSource audioSource = sounds.zone.gameObject.GetComponent <AudioSource>();

        // Keep playing while the audio manager exists
        while (true && sounds.zone != null)
        {
            // Play a random sound around the listener
            SoundEffect randomSound = sounds.GetRandomSound();
            audioSource.clip = randomSound.sound;

            // If the sound is able to be heard
            if (sounds.zone.source.volume > 0)
            {
                // Play the effect
                audioSource.Play();

                // Wait the average time before playing the next sound
                yield return(new WaitForSeconds(
                                 sounds.averageSecondsPerNoise * UnityEngine.Random.Range(
                                     Mathf.Max(0, sounds.averageSecondsPerNoise - sounds.randomSecondDeviation),
                                     sounds.averageSecondsPerNoise + sounds.randomSecondDeviation)
                                 + randomSound.sound.length));
            }
            yield return(new WaitForEndOfFrame());
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Plays a uniqe AmbientSound. Replaces the old one if needed.
    /// </summary>
    /// <param name="ambientName"></param>
    public void PlayAmbientSound(string ambientName)
    {
        // Gets the AmbientSound to play
        AmbientSound _ambientToPlay = GetAmbient(ambientName);

        // returns if null
        if (_ambientToPlay == null)
        {
            return;
        }
        // return if the new AmbienSound is the same as current AmbientSound
        if (_ambientToPlay == CurrentAmbient)
        {
            Debug.Log("AudioToolkit :: You're trying to play the same AmbientSound");
            return;
        }

        // Stops all the currently playing AmbientSounds
        if (CurrentAmbient != null)
        {
            foreach (Sound _sound in CurrentAmbient.Sounds)
            {
                _sound.Stop();
            }
        }

        // Play the AmbientSound child sounds
        foreach (Sound _sound in _ambientToPlay.Sounds)
        {
            _sound.Play(Vector3.zero);
        }

        // Set the CurrentAmbient to the AmbientSound that we've just played
        CurrentAmbient = _ambientToPlay;
    }
Ejemplo n.º 3
0
        private void ActorsHierarchyTest()
        {
            Debug.Log(LogLevel.Display, "Starting " + MethodBase.GetCurrentMethod().Name + "...");

            const string actorName = "TestPlayerController";

            PlayerController playerController = new PlayerController(actorName);
            Actor            actor            = World.GetActor <Actor>(actorName);

            if (playerController == null || actor == null)
            {
                Debug.Log(LogLevel.Error, "Actor valid references check failed!");

                return;
            }

            AmbientSound ambientSound = World.GetActor <AmbientSound>(actorName);
            Brush        brush        = World.GetActor <Brush>(actorName);

            if (ambientSound != null || brush != null)
            {
                Debug.Log(LogLevel.Error, "Actor invalid references check failed!");

                return;
            }

            Debug.Log(LogLevel.Display, "Test passed successfully");
        }
Ejemplo n.º 4
0
        private async Task InitComponents()
        {
            _mediaEngine = new MediaEngine();
            _mediaEngine.MediaStateChanged += MediaEngineOnMediaStateChanged;
            var result = await _mediaEngine.InitializeAsync();

            if (result == MediaEngineInitializationResult.Fail)
            {
                Debugger.Break();
                return;
            }
            else
            {
                //_mediaEngine.Play("http://uwstream1.somafm.com:80");
                //_mediaEngine.Play("http://ice.somafm.com/groovesalad");
                //return;
            }

            _ambientSound  = new AmbientSound(_mediaEngine);
            _internetRadio = new InternetRadio(_mediaEngine);

            _timeService      = new MockTimeService();
            _timeService.Tick = ClockTick;

            _input            = new Input();
            _input.KeyAlarm  += OnKeyAlarm;
            _input.KeySnooze += OnKeySnooze;
            _input.KeyRadio  += OnKeyRadio;
        }
    IEnumerator ScheduleEffect(AmbientSound sound)
    {
        yield return(new WaitForSeconds(sound.GetNextTime()));

        source.PlayOneShot(sound.clip, sound.volume);

        StartCoroutine(ScheduleEffect(sound));
    }
Ejemplo n.º 6
0
 void OnDestroy()
 {
     for (int i = 0, iLen = ambientSounds.Count; i < iLen; ++i)
     {
         AmbientSound ambientSound = ambientSounds[i];
         ambientSound.Dispose();
     }
 }
Ejemplo n.º 7
0
    public void SetVolume()
    {
        globalVolume      = mainSlider.value * dynamicVolume;
        ambientPercentage = AmbientSound.AmbientPercentage();

        audioSource.volume = globalVolume * (1 - ambientPercentage);
        LaserChords.volume = globalVolume * (1 - ambientPercentage) * laserLevel;
        RealChords.volume  = globalVolume * (1 - ambientPercentage) * realLevel;
        bass.volume        = globalVolume * (1 - ambientPercentage);
    }
Ejemplo n.º 8
0
        public override object CreateObject(object parent = null)
        {
            var obj = new AmbientSound();

            base.CreateObject(obj);
            obj.criterionId = CriterionId;
            obj.silenceMin  = SilenceMin;
            obj.silenceMax  = SilenceMax;
            obj.type_id     = Type_id;
            return(obj);
        }
Ejemplo n.º 9
0
    public void PlayOnServerAmbient(string name)
    {
        AmbientSound a = Array.Find(ambientSounds, sound => sound.name == name);

        if (a == null)
        {
            if (a.onServer)
            {
                return;
            }
        }
        a.source.Play();
    }
Ejemplo n.º 10
0
 IEnumerator Coroutine_Response()
 {
     if (mResponseIndex == mCurrentQuestion.CorrectAnswerIndex)
     {
         mFsm.SetCurrentState((int)GameState.StateID.SHOW_RESULTS);
         yield return(StartCoroutine(AmbientSound.Coroutine_PlayShot(mAudioSource, mAudioClipResponse, 0.50f)));
     }
     else
     {
         mFsm.SetCurrentState((int)GameState.StateID.SHOW_RESULTS);
         yield return(StartCoroutine(AmbientSound.Coroutine_PlayShot(mAudioSource, mAudioClipNoResponse, 0.75f)));
     }
 }
Ejemplo n.º 11
0
    //---------Ambient----------------
    public void PlayLocalAmbient(string name)
    {
        AmbientSound a = Array.Find(ambientSounds, sound => sound.name == name);

        if (a.isLocal)
        {
            if (a == null)
            {
                return;
            }
        }
        a.source.Play();
    }
Ejemplo n.º 12
0
        public static AmbientSound ambient_sound(int unique_id, Sample sample, float volume = 0.5f, float pan = 0f, float pitch = 1f)
        {
            AmbientSound s;

            var key = unique_id ^ (sample.index << 16);

            if (ambient_sounds.ContainsKey(key))    s = ambient_sounds[key];
            else                                    {s = new AmbientSound(sample); ambient_sounds.Add(key, s);};

            s.nudge(volume, pan, pitch);

            return s;
        }
Ejemplo n.º 13
0
    void Awake()
    {
        //Debug.Log ("Music Player Awake" + GetInstanceID());
        if (instance != null) {
            Destroy (gameObject);
            print ("destroy dupe ambient");

        }else {
            instance = this;
            GameObject.DontDestroyOnLoad(gameObject);

        }
    }
Ejemplo n.º 14
0
    static bool IncludeAmbientSound(AmbientSound ambient)
    {
        if (MasterAudio.SoundGroupHardCodedNames.Contains(ambient.AmbientSoundGroup))
        {
            return(false);
        }

        if (FilterSoundGroup(ambient.AmbientSoundGroup))
        {
            return(false);
        }

        return(true);
    }
Ejemplo n.º 15
0
        public void AddToGrid(Block blk)
        {
            StartCoroutine(AmbientSound.Coroutine_PlayShot(mAudioSource, mAddToGridAudioClip));

            // Manual reverse iteration is possible using the GetChild() and childCount variables
            // Using normal forward traversal we cannot remove the parent.
            for (int i = blk.transform.childCount - 1; i >= 0; --i)
            {
                Transform child = blk.transform.GetChild(i);
                child.SetParent(null, true);

                int x = Mathf.RoundToInt(child.transform.position.x);
                int y = Mathf.RoundToInt(child.transform.position.y);
                mGrid[x, y] = child;
            }
        }
Ejemplo n.º 16
0
        // Update is called once per frame
        void Update()
        {
            // if (PauseManager.GetIsPaused()) { return; }

            float spice = 1.0f;//Mathf.Min(1, GameplayState.instance.currentSpiciness);

            float fadeInNormalized = Mathf.Clamp(fadeInTimer / fadeInDuration, 0.0f, 1.0f);

            fadeInTimer += Time.deltaTime;

            for (int i = 0, iLen = ambientSounds.Count; i < iLen; ++i)
            {
                AmbientSound ambientSound = ambientSounds[i];

                ambientSound.Update(spice, fadeInNormalized);
            }
        }
Ejemplo n.º 17
0
        public override void Bind(Entity entity, Main main, bool creating = false)
        {
            Transform transform = entity.GetOrCreate <Transform>("Transform");

            AmbientSound ambientSound = entity.GetOrCreate <AmbientSound>("AmbientSound");

            this.SetMain(entity, main);

            VoxelAttachable.MakeAttachable(entity, main).EditorProperties();
            VoxelAttachable.BindTarget(entity, ambientSound.Position);

            entity.Add("PlayCue", ambientSound.PlayCue);
            entity.Add("StopCue", ambientSound.StopCue);

            entity.Add("Play", ambientSound.Enable);
            entity.Add("Stop", ambientSound.Disable);
            entity.Add("Playing", ambientSound.Enabled);
        }
Ejemplo n.º 18
0
    public IEnumerator Coroutine_StartCountDown(float totalTime)
    {
        mBackground.gameObject.SetActive(true);
        mTextTimer.gameObject.SetActive(true);
        int t = (int)totalTime;

        while (t != 0)
        {
            mTextTimer.text = t.ToString();
            StartCoroutine(AmbientSound.Coroutine_PlayShot(mAudioSource, mAudioClip));
            yield return(new WaitForSeconds(1.0f));

            t -= 1;
        }
        mTextTimer.gameObject.SetActive(false);
        mBackground.gameObject.SetActive(false);
        OnFinishCountDown?.Invoke();
    }
Ejemplo n.º 19
0
    // Use this for initialization
    void Awake()
    {
        Instance = this;

        ambientPercentage = AmbientSound.AmbientPercentage();
        audioSource       = GetComponent <AudioSource>();
        mainSlider.onValueChanged.AddListener(delegate { ValueChangeCheck(); });
        //secondarySource = GetComponentInChildren<AudioSource>();
        if (Toolbox.Instance.PlayerInLaser())
        {
            laserLevel = 1;
            realLevel  = 0;
        }
        else
        {
            laserLevel = 0;
            realLevel  = 1;
        }

        StartCoroutine(FadeInGlobalVolume());
    }
Ejemplo n.º 20
0
        IEnumerator Coroutine_RemoveLines()
        {
            int id = CheckIfNeedToClearLines();

            while (id != -1)
            {
                yield return(StartCoroutine(RemoveLine(id)));

                id = CheckIfNeedToClearLines();
                //yield return new WaitForSeconds(1.0f);
                yield return(StartCoroutine(AmbientSound.Coroutine_PlayShot(mAudioSource, mClearLineAudioClip)));
            }

            if (mLinesRemoved >= GetLinesToClearLevel(mLevel))
            {
                mFsm.SetCurrentState((int)GameState.StateID.NEW_LEVEL);
            }
            else
            {
                mFsm.SetCurrentState((int)GameState.StateID.PLAYING);
            }
        }
Ejemplo n.º 21
0
        public override void Bind(Entity entity, Main main, bool creating = false)
        {
            Transform     transform = entity.GetOrCreate <Transform>("Transform");
            PlayerTrigger trigger   = entity.GetOrCreate <PlayerTrigger>("PlayerTrigger");

            this.SetMain(entity, main);

            VoxelAttachable.MakeAttachable(entity, main).EditorProperties();

            MapExit mapExit = entity.GetOrCreate <MapExit>("MapExit");

            AmbientSound sound = entity.GetOrCreate <AmbientSound>();

            sound.Add(new Binding <Vector3>(sound.Position, transform.Position));
            sound.PlayCue.Value = AK.EVENTS.PLAY_DOOR_AMBIENCE;
            sound.StopCue.Value = AK.EVENTS.STOP_DOOR_AMBIENCE;
            sound.Add(new Binding <bool>(sound.Enabled, trigger.Enabled));

            trigger.Add(new TwoWayBinding <Vector3>(transform.Position, trigger.Position));
            trigger.Add(new CommandBinding(trigger.PlayerEntered, (Action)mapExit.Go));

            trigger.EditorProperties();

            entity.Add("Enable", trigger.Enable);
            entity.Add("Disable", trigger.Disable);
            entity.Add("OnEnter", trigger.PlayerEntered);

            entity.Add("Enabled", trigger.Enabled);
            entity.Add("NextMap", mapExit.NextMap, new PropertyEntry.EditorData
            {
                Options = FileFilter.Get(main, main.MapDirectory, null, MapLoader.MapExtension, delegate()
                {
                    return(new[] { Main.MenuMap });
                }),
            });
            entity.Add("StartSpawnPoint", mapExit.StartSpawnPoint);
        }
Ejemplo n.º 22
0
 void OnEnterLost()
 {
     StartCoroutine(AmbientSound.Coroutine_PlayShot(mAudioSource, mLostAudioClip));
     StartCoroutine(Coroutine_OnLost());
     //Debug.Log("Game ended");
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Check if a certain ambient sound is enabled
 /// </summary>
 public bool IsAmbientSoundEnabled(AmbientSound soundType)
 {
     return(MtaClient.IsAmbientSoundEnabled(soundType.ToString().ToLower()));
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Enables ambient sounds
 /// </summary>
 public bool SetAmbientSoundEnabled(AmbientSound soundType, bool enable = true)
 {
     return(MtaClient.SetAmbientSoundEnabled(soundType.ToString().ToLower(), enable));
 }
Ejemplo n.º 25
0
        public static void Run(Entity script)
        {
            Updater         updater = script.Create <Updater>();
            Command         enable  = command(script, "Enable");
            Command         disable = command(script, "Disable");
            Property <bool> enabled = property <bool>(script, "Enabled");

            updater.Add(new Binding <bool>(updater.Enabled, enabled));

            script.Add(new CommandBinding(enable, () => !enabled, delegate()
            {
                enabled.Value = true;
            }));

            script.Add(new CommandBinding(disable, () => enabled, delegate()
            {
                enabled.Value = false;
            }));

            AmbientSound sound = script.Create <AmbientSound>();

            sound.PlayCue.Value = AK.EVENTS.PLAY_MONOLITH_LOOP;
            sound.StopCue.Value = AK.EVENTS.STOP_ALL_OBJECT;
            sound.Add(new Binding <bool>(sound.Enabled, enabled));

            script.Add(new Binding <float, bool>(WorldFactory.Instance.Get <World>().CameraShakeAmount, x => x ? 0.02f : 0.0f, enabled));

            script.Add(new ChangeBinding <bool>(enabled, delegate(bool old, bool value)
            {
                if (!old && value)
                {
                    enable.Execute();
                }
                else if (old && !value)
                {
                    disable.Execute();
                }
            }));

            RiftFactory riftFactory = Factory.Get <RiftFactory>();
            const float minInterval = 3.0f;
            const float maxInterval = 8.0f;
            float       interval    = minInterval + (float)random.NextDouble() * (maxInterval - minInterval);

            updater.Action = delegate(float dt)
            {
                Entity player = PlayerFactory.Instance;
                if (player != null)
                {
                    interval -= dt;
                    if (interval < 0.0f)
                    {
                        Vector3 pos = player.Get <Transform>().Position;
                        Vector3 dir = Vector3.Normalize(new Vector3((float)random.NextDouble() * 2.0f - 1.0f, (float)random.NextDouble() * 2.0f - 1.0f, (float)random.NextDouble() * 2.0f - 1.0f));
                        Voxel.GlobalRaycastResult hit = default(Voxel.GlobalRaycastResult);
                        int  radius  = random.Next(4, 10);
                        int  tries   = 30;
                        bool success = false;
                        while (tries > 0)
                        {
                            hit = Voxel.GlobalRaycast(pos, dir, 50.0f);

                            if (hit.Voxel != null &&
                                hit.Distance > radius &&
                                Rift.Query(hit.Position) == null &&
                                Zone.CanSpawnRift(hit.Position) &&
                                MapExit.Query(hit.Position, 5 + radius) == null)
                            {
                                success = true;
                                break;
                            }

                            tries--;
                        }

                        if (success)
                        {
                            Entity rift = riftFactory.CreateAndBind(main);
                            rift.Get <Transform>().Position.Value = hit.Position;
                            VoxelAttachable attachment = rift.Get <VoxelAttachable>();
                            attachment.AttachedVoxel.Value = hit.Voxel.Entity;
                            attachment.Coord.Value         = hit.Coordinate.Value;
                            Rift riftComponent = rift.Get <Rift>();
                            riftComponent.Radius.Value = radius;
                            main.Add(rift);
                            riftComponent.Enabled.Value = true;
                            interval = minInterval + (float)random.NextDouble() * (maxInterval - minInterval);
                        }
                    }
                }
            };
            script.Add(updater);
        }
Ejemplo n.º 26
0
 // -- lifecycle --
 protected void Start()
 {
     mDoor         = GetComponent <Door>();
     mHover        = GetComponentInChildren <Interact.OnHover>();
     mAmbientSound = GetComponent <AmbientSound>();
 }
Ejemplo n.º 27
0
        /// <summary>
        /// Function that handles tasks that trigger when a key is pressed.
        /// </summary>
        /// <param name="e">Data passed by the event handler that calls the function.</param>
        /// <returns></returns>
        public bool KeyPressed(MOIS.KeyEvent e)
        {
            switch (e.key)
            {
            case MOIS.KeyCode.KC_LEFT:
            case MOIS.KeyCode.KC_A:
                position--;
                if (position < -1)
                {
                    position = -1;
                }
                break;

            case MOIS.KeyCode.KC_RIGHT:
            case MOIS.KeyCode.KC_D:
                position++;
                if (position > 1)
                {
                    position = 1;
                }
                break;

            case MOIS.KeyCode.KC_SPACE:
                switch (position)
                {
                case -1:
                    running = false;
                    break;

                case 0:
                    if (soundEntity != null)
                    {
                        if (soundEntity.IsPlaying())
                        {
                            soundEntity.Stop();
                        }
                        else
                        {
                            soundEntity.Play();
                        }
                        break;
                    }

                    soundEntity = smgr.CreateSoundEntity("Assets/Sounds/DrumMono.ogg", mgr.GetSceneNode("Drum"), "Drum", false, false);
                    soundEntity.SetReferenceDistance(.5f);
                    soundEntity.SetMaxDistance(5);
                    soundEntity.Play();
                    break;

                case 1:
                    if (ambientSound != null)
                    {
                        if (ambientSound.IsPlaying())
                        {
                            ambientSound.Stop();
                        }
                        else
                        {
                            ambientSound.Play();
                        }
                        break;
                    }
                    ambientSound = smgr.CreateAmbientSound("Assets/Sounds/Tune.ogg", "Tune", false, false);
                    ambientSound.Play();
                    break;
                }
                break;

            case MOIS.KeyCode.KC_ESCAPE:
                running = false;
                break;
            }

            return(true);
        }
Ejemplo n.º 28
0
 void OnEnterNewLevel()
 {
     StartCoroutine(AmbientSound.Coroutine_PlayShot(mAudioSource, mLevelUpAudioClip));
     StartCoroutine(Coroutine_LevelUp());
 }
Ejemplo n.º 29
0
 // -- lifecycle --
 protected void Awake()
 {
     mRenderer     = GetComponent <Renderer>();
     mAmbientSound = GetComponent <AmbientSound>();
 }
Ejemplo n.º 30
0
    void FlipPlayerAndThings(GameObject player, GameObject held, IList <GameObject> things)
    {
        GetComponent <MFPP.Player>().collisionLayers = null;
        bool selectedObjects = false;

        if (things.Count > 0)
        {
            selectedObjects = true;
        }

        flipburst.Boom();

        space = !space;

        //change the layer that the player is on, for changing its collision detection
        if (space)
        {
            player.layer = 16; //set player to real world
            // Camera.main.GetComponent<CameraTransition>().Flip(true);
            GetComponent <SkyboxTransition>().Flip(true);
            transitionCollider.FlipTransitions(true);

            mutationSpawner.SpawnMutations();

            AmbientSound.CrossfadeAllToReal();
        }
        else
        {
            player.layer = 15;    //set player to laser world
            GetComponent <SkyboxTransition>().Flip(false);
            transitionCollider.FlipTransitions(false);

            AmbientSound.CrossfadeAllToLaser();
        }

        if (held)
        {
            Flip(held);
        }
        FlipList(things);
        Toolbox.Instance.FlipSharedMaterials(space);
        currentRing = Instantiate(ring);
        currentRing.transform.position = transform.position;


        if (soundTrack)
        {
            //play secondary sound when there is a held object or are selected objects
            if (held || (selectedObjects))
            {
                soundTrack.PlaySecondary();
            }

            else
            {
                soundTrack.PlayPrimary();
            }

            soundTrack.FadeBetween(space);
        }
    }
Ejemplo n.º 31
0
 private void Update()
 {
     ambientPercentage = 1 - AmbientSound.AmbientPercentage();
     audio.volume      = volume * ambientPercentage;
 }
Ejemplo n.º 32
0
 IEnumerator Coroutine_NoResponse()
 {
     mFsm.SetCurrentState((int)GameState.StateID.SHOW_RESULTS);
     yield return(StartCoroutine(AmbientSound.Coroutine_PlayShot(mAudioSource, mAudioClipNoResponse)));
 }