示例#1
0
        private void Update()
        {
            if (!m_isPlaying)
            {
                return;
            }

            m_timer += Time.deltaTime;

            if (!m_audioSource.isPlaying && (m_timer >= 0.0f))
            {
                if (OnSongStartedPlaying != null)
                {
                    OnSongStartedPlaying();
                }

                m_audioSource.Play();
            }

            if (m_timer >= m_audioSource.clip.length)
            {
                m_isPlaying = false;

                if (OnSongFinishedPlaying != null)
                {
                    OnSongFinishedPlaying();
                }

                m_audioSource.Stop();
                m_audioSource.clip = null;

                return;
            }

            while (m_noteIndex < m_notes.Count)
            {
                if ((m_notes[m_noteIndex].timeInSong - timeOffset) <= m_timer)
                {
                    if (m_guitarHeroGameController.forceScalingMode)
                    {
                        m_noteSpawner.SpawnForceScalingNote(m_notes[m_noteIndex], m_timer);
                    }
                    else
                    {
                        m_noteSpawner.SpawnNote(m_notes[m_noteIndex], m_timer);
                    }
                    m_noteIndex++;
                }
                else
                {
                    break;
                }
            }
        }
        private void UDPMessageReceivedHandler(NetInMessage message)
        {
            message.ResetIndex();

            MessageType.Command command = (MessageType.Command)message.ReadInt32();
            if (command == MessageType.Command.Data)
            {
                for (int i = 0; i < 5; i++)
                {
                    int   fingerIndex = message.ReadInt32();
                    float plotValue   = message.ReadFloat();

                    FingerForceGraphs[fingerIndex].value = Mathf.FloorToInt(plotValue);
                    forceScalingNoteActivators[fingerIndex].GetComponent <ForceScalingNoteActivatorController>().SetForcePercentage(plotValue);
                }
            }
            else if (command == MessageType.Command.Control)
            {
                MessageType.ControlType controlType = (MessageType.ControlType)message.ReadInt32();
                if (controlType == MessageType.ControlType.PlaySong)
                {
                    int songIndex = message.ReadInt32();

                    audioSource.clip = songList.songs[songIndex].audioClip;
                    audioSource.loop = false;
                    audioSource.Play();
                }
                else if (controlType == MessageType.ControlType.StopSong)
                {
                    audioSource.Stop();

                    noteSpawner.DeleteAllNotes();
                }
                else if (controlType == MessageType.ControlType.SpawnNote)
                {
                    int     spawnIndex         = message.ReadInt32();
                    float   duration           = message.ReadFloat();
                    Vector3 locationInNoteLane = message.ReadVector3();

                    noteSpawner.SpawnHoldNote(spawnIndex, locationInNoteLane, duration);
                }
                else if (controlType == MessageType.ControlType.SpawnForceScalingNote)
                {
                    int     spawnIndex         = message.ReadInt32();
                    float   duration           = message.ReadFloat();
                    Vector3 locationInNoteLane = message.ReadVector3();
                    float   noteScaleX         = message.ReadFloat();

                    noteSpawner.SpawnForceScalingNote(spawnIndex, locationInNoteLane, noteScaleX, duration);
                }
                else if (controlType == MessageType.ControlType.InitVisualizations)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        int   fingerIndex = message.ReadInt32();
                        float minTargetValuePercentage = message.ReadFloat();
                        float maxTargetValuePercentage = message.ReadFloat();

                        FingerForceGraphs[fingerIndex].minTargetValue = Mathf.FloorToInt(minTargetValuePercentage);
                        FingerForceGraphs[fingerIndex].maxTargetValue = Mathf.FloorToInt(maxTargetValuePercentage);

                        forceScalingNoteActivators[fingerIndex].GetComponent <ForceScalingNoteActivatorController>().SetForceRangePercentage(minTargetValuePercentage, maxTargetValuePercentage);
                    }
                }
                else if (controlType == MessageType.ControlType.PressKey)
                {
                    KeyCode key = (KeyCode)message.ReadInt32();
                    CustomInput.PressKey(key);
                }
                else if (controlType == MessageType.ControlType.ReleaseKey)
                {
                    KeyCode key = (KeyCode)message.ReadInt32();
                    CustomInput.ReleaseKey(key);
                }
                else if (controlType == MessageType.ControlType.ChangeForceScalingMode)
                {
                    int isForceScalingMode = message.ReadInt32();

                    SetForceScalingModeValue(isForceScalingMode == 1);
                }
            }
        }