Esempio n. 1
0
        ///<summary>Will change for the selected radio station</summary>
        public void Radio_SelectStation(RadioData aRadioStation, bool aAutoResume)
        {
            if (!Radio_IsInit(true))
            {
                return;
            }

            if (!m_RadioStations.ContainsKey(aRadioStation))
            {
                Debug.LogError(Debug_Error("The Radio system doesn't have this station: " + aRadioStation));
            }
            else if (aRadioStation == m_RadioStationIds[m_CurrentRadioId])
            {
                Debug.LogWarning(Debug_Warning("These radio station is already in-use: " + aRadioStation));
            }
            else
            {
                m_CurrentRadioStation = m_RadioStations[aRadioStation];
                m_CurrentRadioId      = m_RadioStationIds.IndexOf(aRadioStation);
                if (aAutoResume)
                {
                    Radio_ResumeMusic();
                }
            }
        }
Esempio n. 2
0
 public RadioStation(RadioData aRadioData)
 {
     if (aRadioData != null)
     {
         StationMusics  = aRadioData.GetMusics();
         isPlaying      = false;
         CurrentMusicId = 0;
         timeElapsed    = 0.0f;
         if (aRadioData.WantToShuffle())
         {
             ShuffleRadio();
         }
     }
 }
Esempio n. 3
0
        ///<summary>
        /// The radio system lets you set 10 stations that will play music automaticly. [you can add station by editing the eAudioM_RadioStation in the 'Enums' script]
        /// At start, the system will get all musicData in the folder "MusicDatas" and divide them into each station depend on the data you set.
        /// After, you only need to call if you want to go to next station, previous station or select station and the music will start automaticly, like a real-life radio.
        ///</summary>
        #region RADIO Functions

        ///<summary>Init all the radio station with their music in them</summary>
        private void InitRadioStation()
        {
            //Create the radio player
            GameObject radio = Instantiate(new GameObject(), transform);

            radio.AddComponent <AudioSource>();
            m_RadioPlayer = radio.GetComponent <AudioSource>();

            if (m_RadioPlayer == null)
            {
                Debug.LogError(Debug_InitFailed("Can't init the Radio System, Can't create an audioSource for the radio player"));
                return;
            }

            if (m_RadioStationsInput.Count == 0)
            {
                Debug.LogError(Debug_InitFailed("There's no RadioData set in the manager, can't use the Radio system!"));
                return;
            }

            //Check the radio stations given by the user
            for (int i = 0; i < m_RadioStationsInput.Count; i++)
            {
                RadioData currentRadio = m_RadioStationsInput[i];
                if (currentRadio.HaveMusicInIt())
                {
                    m_RadioStations.Add(currentRadio, new RadioStation(currentRadio));
                    m_RadioStationIds.Add(currentRadio);
                }
                else
                {
                    Debug.LogWarning(Debug_Warning("The radio station: '" + currentRadio.name + "' doesn't have any music in it! Won't be add to the radio system."));
                }
            }

            m_RadioIsInit    = true;
            m_CurrentRadioId = 0;
            Debug.Log(Debug_InitSucces("Radio System as been init"));
            //Initialisation is finish
        }
Esempio n. 4
0
        private void ShowRadioList()
        {
            int   toRemove = -1;
            Color colorValue;

            if (m_RadioStationsInput.arraySize == 0)
            {
                GUILayout.Space(15f);
                ShowAdvancedLabelCenter("Empty");
            }
            for (int i = 0; i < m_RadioStationsInput.arraySize; i++)
            {
                SerializedProperty tempObject = m_RadioStationsInput.GetArrayElementAtIndex(i);

                //Set color
                if (i % 2 == 0)
                {
                    colorValue = CurrentColor;
                }
                else
                {
                    colorValue = CurrentColorDark;
                }
                colorValue.a = 0.5f;

                //Show AudioClip with 'Remove' button
                GUI.backgroundColor = colorValue;
                EditorGUILayout.BeginHorizontal();
                tempObject.objectReferenceValue = EditorGUILayout.ObjectField(tempObject.objectReferenceValue, typeof(RadioData), false, GUILayout.Width(ScreenWidth - 100f), GUILayout.Height(20f));
                if (GUILayout.Button("Remove", m_ButtonStyle, GUILayout.Width(60f), GUILayout.Height(20f)))
                {
                    tempObject.objectReferenceValue = null;
                }
                GUI.backgroundColor = Color.white;
                EditorGUILayout.EndHorizontal();

                //Set back into the list the new audio (if change)
                if (tempObject.objectReferenceValue == null)
                {
                    toRemove = i;
                }
                GUILayout.Space(-2f);
            }

            DrawSeparatorDark(true);

            //Add a sound option
            EditorGUILayout.LabelField("Add a new station ", m_LabelTxtStyleLeft);
            RadioData m_TempData = null;

            m_TempData = (RadioData)EditorGUILayout.ObjectField(m_TempData, typeof(RadioData), false, GUILayout.Width(ScreenWidth - 35f));
            if (m_TempData != null)
            {
                m_RadioStationsInput.InsertArrayElementAtIndex(m_RadioStationsInput.arraySize);
                m_RadioStationsInput.GetArrayElementAtIndex(m_RadioStationsInput.arraySize - 1).objectReferenceValue = m_TempData;
            }

            //Remove sound from list if null
            if (toRemove >= 0)
            {
                m_RadioStationsInput.DeleteArrayElementAtIndex(toRemove);
            }
        }