Esempio n. 1
0
        bool InheritDependencies()
        {
            //if (spectrumSource) return true;

            Transform parent = transform.parent;

            if (spectrumSource == null)
            {
                spectrumSource = GetComponent <SpectrumSource>();
            }

            if (eq == null)
            {
                eq = GetComponent <EQ>();
            }

            while (spectrumSource == null || eq == null)
            {
                if (parent != null)
                {
                    if (spectrumSource == null)
                    {
                        spectrumSource = parent.GetComponent <SpectrumSource>();
                    }

                    if (eq == null)
                    {
                        eq = parent.GetComponent <EQ>();
                    }

                    parent = parent.parent;
                }
                else
                {
                    break;
                }
            }

            return(spectrumSource);
        }
Esempio n. 2
0
        public override void OnInspectorGUI()
        {
            // Update the serializedProperty - always do this in the beginning of OnInspectorGUI.
            serializedObject.Update();

            SpectrumSource source = (SpectrumSource)target;

            EditorGUILayout.Space();

            EditorGUILayout.Foldout(true, "Audio", GlobalStyles.heading);

            EditorGUILayout.PropertyField(audioSourceProp, new GUIContent("AudioSource"));
            EditorGUILayout.IntPopup(channelProp, audioChannelStrings, audioChannels, new GUIContent("Channel", "The audio channel to pull spectrum data from. If the channel doesn't exist, then it'll fall back to the highest supported channel during play mode."));
            EditorGUILayout.PropertyField(peaksProfileProp, new GUIContent("Peaks Profile", "Audio Spectrum Profile. Create one from the Assets menu."));

            if (!source.peaksProfile)
            {
                EditorGUILayout.HelpBox("A Peaks Profile must be attached for the spectrum to work.", MessageType.Warning);
            }

            if (Application.isPlaying && source.peaksProfile != null && source.peaksProfile.isDirty)
            {
                if (source.recordProfile)
                {
                    if (GUILayout.Button("Stop Recording"))
                    {
                        source.recordProfile = false;
                    }
                }
                else
                {
                    if (GUILayout.Button("Record Peaks"))
                    {
                        source.RecordPeaks();
                    }
                }
            }

            GUI.enabled = !source.recordProfile;

            EditorGUILayout.Space();

            EditorGUILayout.Foldout(true, "Presentation", GlobalStyles.heading);
            EditorGUILayout.IntPopup(bandOptionProperty, bandOptionStrings, bandOptions, new GUIContent("Bands", "The number of times to divide the standard audio frequency."));
            EditorGUILayout.PropertyField(normalizeProp, new GUIContent("Normalize", "Scales level to be between 0 and 1 either by the highest peak value, or individually per level peak. Raw just passes the original spectrum data through."));

            // Apply changes to the serializedProperty - always do this at the end of OnInspectorGUI.
            serializedObject.ApplyModifiedProperties();

            if (source.audioSource && source.audioSource.clip)
            {
                source.audioChannel = Mathf.Clamp(source.audioChannel, 0, (source.audioSource.clip.channels - 1));
            }

            if (GUI.changed)
            {
                foreach (SpectrumSource src in targets)
                {
                    src.Refresh();
                }
            }
        }