Esempio n. 1
0
    private void EmitSound(PlaySoundEvent SoundEvent)
    {
        audioPlayersAvailable = false;
        foreach (AudioSource audioSource in audioPlayerList)
        {
            audioPlayersAvailable = false;
            if (audioSource.isPlaying != true)
            {
                audioSource.gameObject.transform.position = SoundEvent.position;
                audioSource.pitch  = Random.Range(SoundEvent.pitchMin, SoundEvent.pitchMax);
                audioSource.volume = SoundEvent.volume;
                audioSource.PlayOneShot(SoundEvent.sound);
                audioPlayersAvailable = true;
                return;
            }
        }

        if (audioPlayersAvailable == false)
        {
            obj = Instantiate(audioPlayer, SoundEvent.position, Quaternion.identity);
            obj.GetComponent <AudioSource>().pitch  = Random.Range(SoundEvent.pitchMin, SoundEvent.pitchMax);
            obj.GetComponent <AudioSource>().volume = SoundEvent.volume;
            obj.GetComponent <AudioSource>().PlayOneShot(SoundEvent.sound);
            Destroy(obj, SoundEvent.sound.length);
        }
    }
Esempio n. 2
0
        public static DetourEvent PlaySoundCallback(string soundCue)
        {
            var @event = new PlaySoundEvent(soundCue);

            FireEvent(@event);
            return(@event);
        }
Esempio n. 3
0
    public void Cycle()
    {
        if (!aiming && input.Enabled)
        {
            GlobalState.EventService.Dispatch(new InputToggleEvent(false));
            CycleLocalQueue();
            level.levelState.bubbleQueue.Rotate(nextBubbles.Length);
            SwapBubblesEvent.Dispatch();

            PlaySoundEvent.Dispatch((nextBubbles.Length > 1) ? SoundType.SwapBubbles : SoundType.FailSwapBubbles);
        }
    }
Esempio n. 4
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        numOfNotes++;
        PlaySoundEvent.Invoke(itemPickSound);
        BuzzleRecordEvent.Invoke(itemPickSound);

        gameObject.SetActive(false);

        // Debug.Log(collision.gameObject.name);

        //  Destroy(gameObject);
    }
Esempio n. 5
0
        public override void createUI(ISkillEvent value, EditorUI p)
        {
            base.createUI(value, p);

            this.ev = value as PlaySoundEvent;

            heroRadio = new EditorRadio("仅主角");
            heroRadio.addEventListener(EventX.CHANGE, radioHandle);
            heroRadio.selected = ev.isOnlyHero;

            onceRadio = new EditorRadio("once");
            onceRadio.addEventListener(EventX.CHANGE, onceRadioHandle);
            onceRadio.selected = ev.isOnce;

            formItem1 = new EditorFormItem("声音1:");
            formItem1.addEventListener(EventX.CHANGE, soundHandle1);
            formItem1.searckKey = DataSource.SOUND;
            formItem1.value     = ev.m_sound1;


            formItem2 = new EditorFormItem("声音2:");
            formItem2.addEventListener(EventX.CHANGE, soundHandle1);
            formItem2.searckKey = DataSource.SOUND;
            formItem2.value     = ev.m_sound2;


            formItem3 = new EditorFormItem("声音3:");
            formItem3.addEventListener(EventX.CHANGE, soundHandle1);
            formItem3.searckKey = DataSource.SOUND;
            formItem3.value     = ev.m_sound3;


            formItem4 = new EditorFormItem("声音4:");
            formItem4.addEventListener(EventX.CHANGE, soundHandle1);
            formItem4.searckKey = DataSource.SOUND;
            formItem4.value     = ev.m_sound4;

            p.addChild(heroRadio);
            p.addChild(formItem1);
            p.addChild(formItem2);
            p.addChild(formItem3);
            p.addChild(formItem4);
            p.addChild(onceRadio);

            p.windowRepaint();
        }
Esempio n. 6
0
    private void OnPlaySound(PlaySoundEvent e)
    {
        AudioClip selectedClip;

        switch (e.SoundToPlay)
        {
        case SoundLibrarySelection.Meow:
            selectedClip = clips[0];
            break;

        default:
            selectedClip = clips[0];
            break;
        }

        source.PlayOneShot(selectedClip);
    }
    private void OnAnimationFireBubble()
    {
        shooterBubble.transform.parent = null;
        var rigidBody = shooterBubble.GetComponent <Rigidbody2D>();

        rigidBody.velocity     = direction;
        rigidBody.gravityScale = 0.0f;
        rigidBody.isKinematic  = false;

        GlobalState.EventService.Dispatch(new BubbleFiredEvent(shooterBubble));

        if (launchSoundOverride != null)
        {
            PlaySoundEvent.Dispatch(launchSoundOverride);
        }
        else
        {
            PlaySoundEvent.Dispatch(SoundType.LaunchBubble);
        }
    }
Esempio n. 8
0
        void Start()
        {
            // go from List to dictionary for quick retrieval
            for (int i = 0; i < listSoundList.Count; ++i)
            {
                SoundNode soundNode = listSoundList[i];
                soundNode.soundObject.audioSource        = gameObject.AddComponent <AudioSource>();
                soundNode.soundObject.audioSource.volume = soundNode.soundObject.volume;
                soundNode.soundObject.audioSource.loop   = soundNode.soundObject.type == SoundObject.soundType.music ? true : false;
                soundDictionary.Add(soundNode.id, soundNode);
            }

            // instantiate the event
            if (playSoundEvent == null)
            {
                playSoundEvent = new PlaySoundEvent();
            }

            // trigger func
            playSoundEvent.AddListener(PlaySound);
        }
Esempio n. 9
0
        private void OnAnimateStarsOnMapNodeEvent(AnimateStarsOnMapNodeEvent gameEvent)
        {
            GlobalState.EventService.RemoveEventHandler <AnimateStarsOnMapNodeEvent>(OnAnimateStarsOnMapNodeEvent);

            for (long starIndex = gameEvent.oldStars; starIndex < filledStars; ++starIndex)
            {
                // We need to make a copy of starIndex so our lambda doesn't reference it directly
                var index        = starIndex;
                var newStarIndex = (index - gameEvent.oldStars);
                var delay        = (0.4f * (newStarIndex + 1));

                starPositions[index].enabled = false;

                Util.FrameUtil.AfterDelay(delay, () =>
                {
                    PlaySoundEvent.Dispatch(starSounds[newStarIndex]);
                    StartCoroutine(AnimationEffect.Play(starPositions[index].gameObject,
                                                        AnimationType.StarOnMapNode));
                });
            }
        }
Esempio n. 10
0
 public static SoundEffectInstance Play(SfxEntry entry, Point tilePos, int variant, PlaySoundEvent onPlay)
 {
     return Play(entry, tilePos.ToVector2() * 16f, variant, onPlay);
 }
Esempio n. 11
0
        public void PlaySoundCallback(PlaySoundEvent @event)
        {
            var sound = @event.SoundCue;

            Console.WriteLine("Sound Played: " + sound);
        }
Esempio n. 12
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     PlaySoundEvent.Invoke(itemPickSound);
     Destroy(gameObject);
 }
Esempio n. 13
0
 void PlaySound(PlaySoundEvent e)
 {
     MasterAudio.PlaySoundAndForget(e.Sound, _sounds [e.Sound]);
 }
Esempio n. 14
0
 public void ExternalPlaySound()
 {
     PlaySoundEvent.Invoke(itemPickSound);
 }
Esempio n. 15
0
 public void PlaySoundHelper(PlaySoundEvent pse)
 {
     PlaySound(pse.cvarName, pse.eventVolume, pse.pan, pse.pitch, pse.SoundType);
 }
Esempio n. 16
0
    void OnPlaySoundEvent(PlaySoundEvent evt)
    {
        var audioClip = Shiki.Loader.LoadSound(evt.soundName);

        this.audioSource.PlayOneShot(audioClip);
    }
Esempio n. 17
0
        static Tuple <int, float, float, float> CalcParams(SfxEntry e, Vector2 pos, int v, PlaySoundEvent onPlay)
        {
            var volSetting = e.IsAmbient ? (Main.gameInactive ? 0f : Main.ambientVolume) : Main.soundVolume;

            if (volSetting <= 0f)
            {
                return(null);
            }

            bool shouldPlay = true;
            float
                vol = 1f, pitch = 0f, pan = 0f;

            if (pos.X <= 0f || pos.Y <= 0f || Single.IsNaN(pos.X) || Single.IsNaN(pos.Y))
            {
                shouldPlay = true;
            }
            else
            {
#pragma warning disable RECS0091 // Use 'var' keyword when possible
                                 // to the code analyser: learn to C#
                Rectangle
#pragma warning restore RECS0091
                screen = new Rectangle((int)(Main.screenPosition.X - Main.screenWidth * 2), (int)(Main.screenPosition.Y - Main.screenHeight * 2), Main.screenWidth * 5, Main.screenHeight * 5),
                sound  = new Rectangle((int)pos.X, (int)pos.Y, 1, 1);

                shouldPlay |= sound.Intersects(screen);

                if (shouldPlay)
                {
                    var screenCentre = new Vector2(Main.screenPosition.X + Main.screenWidth * 0.5f, Main.screenPosition.Y + Main.screenHeight * 0.5f);

                    pan = (pos.X - screenCentre.X) / (Main.screenWidth * 0.5f);
                    vol = 1f - Vector2.Distance(pos, screenCentre) / (Main.screenWidth * 1.5f);
                }
            }
            pan = MathHelper.Clamp(pan, -1f, 1f);
            vol = Math.Min(vol * volSetting, 1f);

            if (vol <= 0f)
            {
                return(null);
            }

            if (onPlay != null && !onPlay(e, pos, ref v, ref vol, ref pitch, ref pan))
            {
                return(null);
            }

            vol   = MathHelper.Clamp(vol, 0f, 1f);
            pitch = MathHelper.Clamp(pitch, -1f, 1f);
            pan   = MathHelper.Clamp(pan, -1f, 1f);

            return(Tuple.Create(v, vol, pitch, pan));
        }
Esempio n. 18
0
 void PlaySound(PlaySoundEvent e)
 {
     PlaySound(e.clip, e.volume, e.force);
 }
Esempio n. 19
0
 private void ProcessPlaySoundEvent(PlaySoundEvent playSoundEvent)
 {
     soundProcessor.Play(playSoundEvent.Filename, playSoundEvent.Volume);
 }
Esempio n. 20
0
 void onPlaySound(PlaySoundEvent e)
 {
     playSound(e.clip);
 }
Esempio n. 21
0
        public static SoundEffectInstance Play(SfxEntry entry, Vector2 position, int variant, PlaySoundEvent onPlay)
        {
            if (Main.dedServ || WorldGen.gen || Main.netMode == 2)
                return null;

            var kvp = new KeyValuePair<SfxEntry, int>(entry, entry.Variants == 1 ? 0 : variant);

            var t = CalcParams(entry, position, variant, onPlay);

            if (t == null || t.Item2 <= 0f)
                return null;

            SoundEffectInstance inst;
            var b = entry.PlayBehaviour(variant);
            switch (b)
            {
                case SfxPlayBehaviour.MultipleInstances:
                    inst = entry.GetInstance(variant);

                    if (inst == null)
                        return null;

                    instancePool.Add(inst); // don't GC
                    break;
                case SfxPlayBehaviour.PlayIfStopped:
                case SfxPlayBehaviour.PlayIfStoppedUpdateParams:
                    if (instanceMap.ContainsKey(kvp))
                    {
                        var inst_ = instanceMap[kvp];

                        if (inst_.State == SoundState.Stopped)
                            inst = inst_;
                        else
                        {
                            if (b == SfxPlayBehaviour.PlayIfStoppedUpdateParams)
                                ApplyParams(inst_, t);

                            return null;
                        }
                    }
                    else
                    {
                        inst = entry.GetInstance(variant);

                        if (inst == null)
                            return null;

                        instanceMap.Add(kvp, inst);
                    }
                    break;
                case SfxPlayBehaviour.Singleton:
                    if (instanceMap.ContainsKey(kvp))
                    {
                        var inst_ = instanceMap[kvp];

                        inst_.Stop();

                        instanceMap.Remove(kvp);
                    }

                    inst = entry.GetInstance(variant);

                    if (inst == null)
                        return null;

                    instanceMap.Add(kvp, inst);
                    break;
                // required, compiler will complain about 'inst' not being assigned to otherwise
                // and this is more foolproof than setting 'inst' to null.
                default:
                    return null;
            }

            ApplyParams(inst, t);

            inst.Play(); // !

            CleanupLingeringInstances();

            return inst;
        }
Esempio n. 22
0
        static Tuple<int, float, float, float> CalcParams(SfxEntry e, Vector2 pos, int v, PlaySoundEvent onPlay)
        {
            var volSetting = e.IsAmbient ? (Main.gameInactive ? 0f : Main.ambientVolume) : Main.soundVolume;

            if (volSetting <= 0f)
                return null;

            bool shouldPlay = true;
            float
                vol = 1f, pitch = 0f, pan = 0f;

            if (pos.X <= 0f || pos.Y <= 0f || Single.IsNaN(pos.X) || Single.IsNaN(pos.Y))
                shouldPlay = true;
            else
            {
            #pragma warning disable RECS0091 // Use 'var' keyword when possible
                                 // to the code analyser: learn to C#
                Rectangle
            #pragma warning restore RECS0091
                    screen = new Rectangle((int)(Main.screenPosition.X - Main.screenWidth * 2), (int)(Main.screenPosition.Y - Main.screenHeight * 2), Main.screenWidth * 5, Main.screenHeight * 5),
                    sound  = new Rectangle((int)pos.X, (int)pos.Y, 1, 1);

                shouldPlay |= sound.Intersects(screen);

                if (shouldPlay)
                {
                    var screenCentre = new Vector2(Main.screenPosition.X + Main.screenWidth * 0.5f, Main.screenPosition.Y + Main.screenHeight * 0.5f);

                    pan = (pos.X - screenCentre.X) / (Main.screenWidth * 0.5f);
                    vol = 1f - Vector2.Distance(pos, screenCentre) / (Main.screenWidth * 1.5f);
                }
            }
            pan = MathHelper.Clamp(pan, -1f, 1f);
            vol = Math.Min(vol * volSetting, 1f);

            if (vol <= 0f)
                return null;

            if (onPlay != null && !onPlay(e, pos, ref v, ref vol, ref pitch, ref pan))
                return null;

            vol   = MathHelper.Clamp(vol  ,  0f, 1f);
            pitch = MathHelper.Clamp(pitch, -1f, 1f);
            pan   = MathHelper.Clamp(pan  , -1f, 1f);

            return Tuple.Create(v, vol, pitch, pan);
        }
Esempio n. 23
0
 public static SoundEffectInstance Play(SfxEntry entry, Point tilePos, int variant, PlaySoundEvent onPlay)
 {
     return(Play(entry, tilePos.ToVector2() * 16f, variant, onPlay));
 }
Esempio n. 24
0
        public static SoundEffectInstance Play(SfxEntry entry, Vector2 position, int variant, PlaySoundEvent onPlay)
        {
            if (Main.dedServ || WorldGen.gen || Main.netMode == 2)
            {
                return(null);
            }

            var kvp = new KeyValuePair <SfxEntry, int>(entry, entry.Variants == 1 ? 0 : variant);

            var t = CalcParams(entry, position, variant, onPlay);

            if (t == null || t.Item2 <= 0f)
            {
                return(null);
            }

            SoundEffectInstance inst;
            var b = entry.PlayBehaviour(variant);

            switch (b)
            {
            case SfxPlayBehaviour.MultipleInstances:
                inst = entry.GetInstance(variant);

                if (inst == null)
                {
                    return(null);
                }

                instancePool.Add(inst);     // don't GC
                break;

            case SfxPlayBehaviour.PlayIfStopped:
            case SfxPlayBehaviour.PlayIfStoppedUpdateParams:
                if (instanceMap.ContainsKey(kvp))
                {
                    var inst_ = instanceMap[kvp];

                    if (inst_.State == SoundState.Stopped)
                    {
                        inst = inst_;
                    }
                    else
                    {
                        if (b == SfxPlayBehaviour.PlayIfStoppedUpdateParams)
                        {
                            ApplyParams(inst_, t);
                        }

                        return(null);
                    }
                }
                else
                {
                    inst = entry.GetInstance(variant);

                    if (inst == null)
                    {
                        return(null);
                    }

                    instanceMap.Add(kvp, inst);
                }
                break;

            case SfxPlayBehaviour.Singleton:
                if (instanceMap.ContainsKey(kvp))
                {
                    var inst_ = instanceMap[kvp];

                    inst_.Stop();

                    instanceMap.Remove(kvp);
                }

                inst = entry.GetInstance(variant);

                if (inst == null)
                {
                    return(null);
                }

                instanceMap.Add(kvp, inst);
                break;

            // required, compiler will complain about 'inst' not being assigned to otherwise
            // and this is more foolproof than setting 'inst' to null.
            default:
                return(null);
            }

            ApplyParams(inst, t);

            inst.Play(); // !

            CleanupLingeringInstances();

            return(inst);
        }
Esempio n. 25
0
        /// <summary>
        /// Creates the on complete function from an oncomplete string.
        /// </summary>
        /// <returns>The on complete function in the form of an Action.</returns>
        /// <param name="oc">OnComplete function in string form.</param>
        public static Action <InteractionEvent> CreateOnCompleteFunction(string oc)
        {
            // Just return a no-op if the user didn't provide an OnComplete string
            if (string.IsNullOrEmpty(oc))
            {
                return((InteractionEvent evt) => { });
            }
            ParsingResult pR = ParseString(oc);

            Action <InteractionEvent> ac = (InteractionEvent evt) => {
                IGameEvent outEvt;
                switch (pR.interactionKind)
                {
                case InteractionKind.Become:
                    if (pR.obj1 == "TargetItem")
                    {
                        outEvt = new ReplaceObjectEvent(evt.targetObject, pR.obj2);
                    }
                    else
                    {
                        outEvt = new ReplaceObjectEvent(pR.obj1, pR.obj2);
                    }
                    break;

                case InteractionKind.Show:
                    Debug.Log("Show InteractionKind");
                    Debug.Log(string.Format("{0}, {1}", pR.obj1, pR.obj2));
                    outEvt = new ShowObjectEvent(pR.obj1);
                    break;

                case InteractionKind.Hide:
                    outEvt = new HideObjectEvent(pR.obj1);
                    break;

                case InteractionKind.Delete:
                    Debug.Log("Delete InteractionKind");
                    Debug.Log(string.Format("{0} {1}", pR.obj1, pR.obj2));
                    outEvt = new DeleteObjectEvent(pR.obj1);
                    break;

                case InteractionKind.Play:
                    switch (pR.uiEventKind)
                    {
                    case UIActionKind.Dialog:
                        outEvt = new ShowTextEvent(pR.obj1);
                        break;

                    case UIActionKind.Sound:
                        outEvt = new PlaySoundEvent(pR.obj1);
                        break;

                    default:
                        throw new ArgumentException("Play must be followed by Dialog or Sound");
                    }
                    break;

                case InteractionKind.Get:
                    outEvt = new PlayerRecieveObjectEvent(pR.obj1);
                    break;

                default:
                    throw new ArgumentException(string.Format("Invalid interaction kind in OnComplete: {0} (OnComplete string: {1})", pR.interactionKind, oc));
                }
                EventManager.FireEvent(outEvt);
            };

            return(ac);
        }