Exemplo n.º 1
0
        protected void SoundScheduler(float t)
        {
            // ----- Simulate Lag -----
            while (soundSenarioCmdQ.Count > 0 && t > soundSenarioCmdQ.Peek().tRecv)
            {
                currSoundSenarioCmd = soundSenarioCmdQ.Dequeue();
            }
            var elipsed = t - currSoundSenarioCmd.tRecv;

            // ----- Excute Order -----
            if (currSoundSenarioCmd.period == 0 ||
                currSoundSenarioCmd.repeat > 0 && currSoundSenarioCmd.period * currSoundSenarioCmd.repeat <= elipsed)
            {
                cube._StopSound();
            }
            else
            {
                // Index of current operation
                float sum = 0; int index = 0; var sounds = currSoundSenarioCmd.sounds;
                for (int i = 0; i < sounds.Length; ++i)
                {
                    sum += sounds[i].durationMs / 1000f;
                    if (elipsed % currSoundSenarioCmd.period < sum)
                    {
                        index = i;
                        break;
                    }
                }
                cube._PlaySound(sounds[index].note_number, sounds[index].volume);
            }
        }
Exemplo n.º 2
0
        public override void PlaySound(int repeatCount, Cube.SoundOperation[] operations)
        {
            if (operations.Length == 0)
            {
                return;
            }
            operations = operations.Take(59).ToArray();

            SoundSenarioCmd cmd = new SoundSenarioCmd();

            cmd.sounds = operations;
            cmd.repeat = (byte)Mathf.Clamp(repeatCount, 0, 255);
            // calc. period
            cmd.period = 0;
            for (int i = 0; i < cmd.sounds.Length; ++i)
            {
                cmd.period += cmd.sounds[i].durationMs / 1000f;
            }
            cmd.tRecv = Time.time;
            soundSenarioCmdQ.Enqueue(cmd);
        }
 protected virtual void ResetSound()
 {
     soundCmdType    = SoundCmdType.None;
     soundSenarioCmd = default;
 }
Exemplo n.º 4
0
 protected virtual void ResetSound()
 {
     soundSenarioCmdQ.Clear();
     currSoundSenarioCmd = default;
 }