示例#1
0
        static void Bootup() // Creation of a default Poolable & Pool to allow automatization of the pooling process
        {
            // Poolable creation
            var prefabObject = new GameObject("PoolableAudio")
            {
                hideFlags = HideFlags.HideInHierarchy
            };

            Object.DontDestroyOnLoad(prefabObject);

            var audioSource = prefabObject.AddComponent <AudioSource>();

            audioSource.playOnAwake = false;

            prefab = prefabObject.AddComponent <PoolableAudio>();
            ((IInjectable <AudioSource>)prefab).Inject(audioSource);

            // Pool creation
            var poolObject = new GameObject("AudioPool")
            {
                hideFlags = HideFlags.HideInHierarchy
            };

            Object.DontDestroyOnLoad(poolObject);
            pool = poolObject.AddComponent <AudioPool>();

            // Provider creation
            var provider = new AudioProvider(prefab);

            pool.AddProvider(provider);
        }
示例#2
0
 private void Awake()
 {
     if (!instance)
     {
         instance = this;
     }
 }
示例#3
0
 public void Kill()
 {
     dead = true;
     GetComponent <Animator>().SetTrigger("Kill");
     Destroy(gameObject, .5f);
     AudioPool.PlaySound(transform.position, DeathSound);
 }
示例#4
0
        private void OnGUI()
        {
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Play 2D Sound"))
            {
                AudioPool.Play2D(ClipCollection.GetClip(), pitchVariance: PitchVariance);
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();

            if (GUILayout.Button("Play 3D Sound"))
            {
                AudioPool.Play3D(ClipCollection.GetClip(), transform.position, pitchVariance: PitchVariance);
            }

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical("Box");
            GUILayout.Label("Pitch Variance: " + PitchVariance);
            PitchVariance = GUILayout.HorizontalSlider(PitchVariance, 0f, 1f);
            GUILayout.EndVertical();
            GUILayout.EndVertical();
        }
示例#5
0
        public AudioSystem(SystemConfig inConfig) : base(inConfig)
        {
            if (_instance == null)
            {
                _instance = this;
            }
            if (inConfig != null)
            {
                _config = inConfig as AudioConfig;
            }

            var sourcesHolder = new GameObject("AudioSources Holder");

            sourcesHolder.transform.SetParent(GameState.GameHolder);
            sourcesHolder.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity);

            //- fill the audio pool
            for (var i = 0; i < _config.bufferSize; i++)
            {
                var src = sourcesHolder.AddComponent <AudioSource>();
                AudioPool.AddToPool(src);
            }

            //- assign audio map
            _audioMap = new Dictionary <AudioLabel, AudioData>();
            _config.audios.ForEach(audio => _audioMap.Add(audio.label, audio));
        }
示例#6
0
    // Update is called once per frame
    void FixedUpdate()
    {
        lostHeight += SinkSpeed * Time.fixedDeltaTime;
        Speed       = 0f;

        foreach (var part in ShipParts)
        {
            if (part.IsAlive)
            {
                lostHeight -= part.HealthProps.FloatContribution * Time.fixedDeltaTime;
                Speed      += part.HealthProps.SpeedContribution * (part.Cooled ? 1.5f : 1f);
            }
        }
        lostHeight = Mathf.Clamp(lostHeight, 0, 10f);
        if (lostHeight >= 5f)
        {
            lostHeight += .01f;
        }
        if (lostHeight >= 7f)
        {
            Destroy(gameObject);
            AudioPool.PlaySound(transform.position, ExplodeSound);
            FindObjectOfType <StageAdvancer>().ReplayWithDelay(2f);
        }


        HealthBar.SetValueWithoutNotify(1f - lostHeight / 5f);


        ShipRoot.position = new Vector3(0f, Mathf.Sin(Time.timeSinceLevelLoad) * .1f - (lostHeight * lostHeight * .25f));
    }
示例#7
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     // FindObjectOfType<Win>().NeedCoin--;
     AudioPool.PlaySound(transform.position, GetSound);
     MySceneManager.Instance.WinStage();
     // Destroy(gameObject);
 }
示例#8
0
    public AudioSource Play(string key, float pitch)
    {
        AudioClipEntry c      = clips[key];
        float          volume = c.baseVolume + (c.volumeOffset > 0 ? (((Random.value - 0.5F) * 2.0F) * c.volumeOffset) : 0.0F);

        return(AudioPool.PlayAudioClip(c.clips[Random.Range(0, c.clips.Length)], pitch, volume, c.loop));
    }
示例#9
0
    /**
     * Create the prefabs for the pool
     */
    GameObject SpawnForPool(AudioPool audioPool, List <AudioSource> pool)
    {
        GameObject instance = new GameObject(audioPool.audioClip.name);

        //disable this at the moment
        instance.SetActive(false);

        //add the ParticleClip so it can accessed by this ParticleManager
        AudioSource audioSource = instance.AddComponent <AudioSource>();

        audioSource.clip = audioPool.audioClip;

        AudioManagerClip amClip = instance.AddComponent <AudioManagerClip>();

        amClip.audioType = audioPool.audioType;

        pool.Add(audioSource);

        //set the parent to this (ParticleManager's) game object
        //so our hierarchy looks clean
        instance.transform.parent = this.gameObject.transform;

        //we don't want our pool instance destroyed when we change the scene
//		DontDestroyOnLoad(instance);


        return(instance);
    }
示例#10
0
 public void PlayAudio()
 {
     if (audioClip)
     {
         AudioPool.PlaySound(transform.position, audioClip);
     }
 }
 // Use this for initialization
 void Awake()
 {
     if(_instance == null)
     {
         _instance = this;
         pool = new PoolingSystem<AudioPlayer>(audioObjectPrefab, poolSize);
     }
 }
示例#12
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (fatty && fatty.Fat >= 4)
     {
         AudioPool.PlaySound(transform.position, BreakSound);
         Destroy(gameObject);
     }
 }
示例#13
0
 // Use this for initialization
 void Awake()
 {
     if (_instance == null)
     {
         _instance = this;
         pool      = new PoolingSystem <AudioPlayer>(audioObjectPrefab, poolSize);
     }
 }
示例#14
0
 public override void UseTool(Player player, InteractionObject target, GameObject toolObject)
 {
     if (target.objectType == ObjectType.ShippingBin && itemInfo is FoodInfo foodInfo)
     {
         ShipItem(player, foodInfo);
         AudioPool.PlaySound(target.transform.position, target.audioClip, target.audioVolume);
     }
 }
示例#15
0
    public AudioSource Play(string key, int index)
    {
        AudioClipEntry c      = clips[key];
        float          pitch  = c.basePitch + (c.pitchOffset > 0 ? (((Random.value - 0.5F) * 2.0F) * c.pitchOffset) : 0.0F);
        float          volume = c.baseVolume + (c.volumeOffset > 0 ? (((Random.value - 0.5F) * 2.0F) * c.volumeOffset) : 0.0F);

        return(AudioPool.PlayAudioClip(c.clips[index], pitch, volume, c.loop));
    }
示例#16
0
        public void OnChangeSFXVolume(float value)
        {
            float vol = value / 10f;

            Volume.Effects = vol;
            Volume.Steps   = vol;
            AudioPool.PlaySound(Player.Instance.transform.position, TestSound);
        }
示例#17
0
 private void InitPoolOfAudioType(eAudioSourceType audioType, int audioCount)
 {
     if (!this.m_audioPoolDict.ContainsKey(audioType))
     {
         AudioPool audioPool = new AudioPool();
         audioPool.Init(this.m_audioPrefabDict[audioType], this.m_audioRoot, audioCount);
         this.m_audioPoolDict.Add(audioType, audioPool);
     }
 }
示例#18
0
    IEnumerator WinRoutine()
    {
        AudioPool.PlaySound(transform.position, WinJingle);
        FindObjectOfType <MyInput>().enabled = false;
        FindObjectOfType <DJ>().PutASockInIt(.9f);
        yield return(new WaitForSeconds(1.2f));

        NextStage();
    }
示例#19
0
 public void WalkSound()
 {
     if (Character.Grounded)
     {
         var speed = Mathf.Abs(Character.Speed) * .025f;
         speed = speed < .07f ? speed : .07f;
         AudioPool.PlaySound(transform.position, walkSound, volume: Random.value * speed + speed, pitch: .8f + Random.value * .4f);
     }
 }
示例#20
0
    public override void TStart()
    {
        GameObject go = Resources.Load("Audio/TownThemes") as GameObject;

        AudioPool audioTown = go.GetComponent <AudioPool>();

        Game.game.playSound(audioTown.audioPool[Game.game.currentTown], true);

        base.TStart();
    }
示例#21
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Destroy(this);
     }
 }
示例#22
0
 private AudioSource GetSource()
 {
     if (!singleSource)
     {
         return(AudioPool.GetSource());
     }
     if (_sources == null || _sources.Count == 0)
     {
         return(AudioPool.GetSource());
     }
     return(_sources.First().Source);
 }
示例#23
0
    public AudioPool GetAudioPoolByType(eAudioSourceType audioType)
    {
        if (this.m_audioPoolDict.ContainsKey(audioType))
        {
            return(this.m_audioPoolDict[audioType]);
        }
        AudioPool audioPool = new AudioPool();

        audioPool.Init(this.m_audioPrefabDict[audioType], this.m_audioRoot, 1);
        this.m_audioPoolDict.Add(audioType, audioPool);
        return(audioPool);
    }
    // Use this for initialization
    void Start()
    {
        audioPool = GetComponent <AudioPool>();

        fastMusicGameTime             = fastGameTimer;
        WinCondition.ConditionReached = EndGame;
        playMusic(false);

        gameFinished = false;

        StartGame();
    }
示例#25
0
    public override void TStart()
    {
        Game.game.DummyFunction();

        base.TStart();
        attachWeapons();
        Game.game.registerPlayableCharacter(this);
        Game.game.renderQueue.Add(this);
        changeAnimation("idle");

        go       = Resources.Load("Audio/HudAudio") as GameObject;
        audioHud = go.GetComponent <AudioPool>();
    }
示例#26
0
    // Use this for initialization
    void Start()
    {
        var globalObject = GameObject.Find("Global");

        global    = globalObject.GetComponent <Global>();
        audioPool = globalObject.GetComponent <AudioPool>();


        baseMaterial = GetComponent <Renderer>().materials[0];
        noteMaterial = GetComponent <Renderer>().materials[1];

        UpdateNoteDisplay();
    }
示例#27
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (NeedCoin <= 0 && collision.GetComponent <SugaMoni>())
     {
         Heart.SetActive(true);
         collision.GetComponent <SugaMoni>().Disable = true;
         FindObjectOfType <SceneTransitionManager>().NextStage();
         AudioPool.PlaySound(transform.position, WinAudio);
     }
     else
     {
         AudioPool.PlaySound(transform.position, NeedMoreAudio);
     }
 }
示例#28
0
    public override void TStart()
    {
        // Create audio
        BuyString  = Resources.Load("Translations/Common/Buy", typeof(TranslatedText)) as TranslatedText;
        SellString = Resources.Load("Translations/Common/Sell", typeof(TranslatedText)) as TranslatedText;

        go       = Resources.Load("Audio/HudAudio") as GameObject;
        audioHud = go.GetComponent <AudioPool>();

        base.TStart();
        itemsForSelling = new Dictionary <Item, int>();

        inizializeItems();
    }
    private void playMusic(bool isFast)
    {
        audioPool = GetComponent <AudioPool>();

        if (isFast)
        {
            audioPool.PlayMusic(fastMusic, 0.6f);
            fastMusicStarted = true;
        }
        else
        {
            audioPool.PlayMusic(slowMusic, 0.6f);
        }
    }
 private void PlatformingCharacterSounds_OnLand()
 {
     if (Fat == 3)
     {
         AudioPool.PlaySound(transform.position, Land, .75f, 1f);
     }
     if (Fat == 4)
     {
         AudioPool.PlaySound(transform.position, Land, 1f, .85f);
     }
     if (Fat == 5)
     {
         AudioPool.PlaySound(transform.position, Land, 1f, .7f);
     }
 }
示例#31
0
 private void Update()
 {
     if (NeedCoin > 0)
     {
         Coin.SetActive(true);
         Text.text = $"x{NeedCoin}";
     }
     else if (!playedThing)
     {
         Coin.SetActive(false);
         Text.gameObject.SetActive(false);
         AudioPool.PlaySound(Camera.main.transform.position, EnoughMoneyAudio);
         playedThing = true;
     }
 }
示例#32
0
    // Use this for initialization
    void Awake()
    {
        Assert.IsNull(Instance, "More than 1 instance of AudioPool detected. ONLY HAVE 1 IN THE SCENE PLZ");
        Instance = this;

        DefaultSettings = new AudioClipSettings();
        // Set up the object pool of audio sources
        m_AudioSources = new GameObjectPool(1, m_emptyPrefab, this.gameObject);
    }