Inheritance: UnityEngine.ScriptableObject
Beispiel #1
0
        void UpdateSoundBank()
        {
            if (_soundBank == null && _SoundBanks.Count == 0)
            {
                return;
            }

            int          i;
            GATSoundBank soundBank = null;

            for (i = 0; i < _SoundBanks.Count; i++)
            {
                soundBank = _SoundBanks[i];
                if (soundBank == null)
                {
                    continue;
                }

                if (soundBank.SampleRate == GATInfo.OutputSampleRate)
                {
                    _soundBank = soundBank;
                    break;
                }
            }

            if (soundBank == null)
            {
                                #if UNITY_EDITOR || GAT_DEBUG
                Debug.LogError(string.Format("SampleBank {0} could not find a sound bank of appropriate sample rate to load. Ouptut sample rate: {1}khz", this.name, GATInfo.OutputSampleRate.ToString()));
                                #endif
                return;
            }
        }
Beispiel #2
0
        public void EditorUpdateSoundBank(GATSoundBank bank = null)
        {
            if (bank != null)
            {
                _SoundBanks.Add(bank);
            }

            UpdateSoundBank();
        }
Beispiel #3
0
    void OnGUI()
    {
        EditorGUIUtility.fieldWidth = 150f;
        EditorGUIUtility.labelWidth = 80f;
        _soundBank = ( GATSoundBank )EditorGUILayout.ObjectField( "Sound Bank: ", _soundBank, typeof( GATSoundBank ), false, GUILayout.ExpandWidth( false ) );

        if( _soundBank == false )
        {
            EditorGUILayout.HelpBox( __soundBankHelp, MessageType.Info );
            GUI.enabled = false;
        }
        else
        {
            _bankType = ( BankType )EditorGUILayout.EnumPopup( "Bank Type: ", _bankType, GUILayout.ExpandWidth( false ) );
            EditorGUILayout.HelpBox( __bankTypesHelp[ ( int )_bankType ], MessageType.Info );
        }

        GUI.color = Color.green;
        if ( GUILayout.Button( "Create", GUILayout.Width( 70f ) ) )
        {
            GATEditorUtilities.CheckManager();

            GATSampleBank bank = null;

            switch( _bankType )
            {
            case BankType.Simple:
                bank = GATEditorUtilities.NewChildGO< GATSampleBank >( "Sample Bank" );
                break;

            case BankType.Active:
                bank = GATEditorUtilities.NewChildGO< GATActiveSampleBank >( "Sample Bank" );
                break;
            }

            bank.EditorUpdateSoundBank( _soundBank );

            this.Close();
        }
    }
Beispiel #4
0
    void OnGUI()
    {
        int i;
        bool shouldRepaint = false;

        //*************************************************************
        //******************* Zoom slider *****************************
        GUILayout.Space( 10f );
        EditorGUIUtility.labelWidth = 55f;

        int samplesPerPixel = _samplesPerPixel;

        _samplesPerPixel = EditorGUILayout.IntSlider( "Zoom: ", _samplesPerPixel, 2, 1000 );

        if( samplesPerPixel != _samplesPerPixel )
        {
            UpdateZoom();
        }

        //*************************************************************
        //******************* ScrollView  *****************************
        Vector2 prevScroll = _scrollPos;

        _scrollPos = GUI.BeginScrollView( new Rect( 0f, 0f, this.position.width, this.position.height ), _scrollPos, new Rect( 0, 0, _scrollViewWidth ,200f ));

        if( prevScroll != _scrollPos )
            shouldRepaint = true;

        //*************************************************************
        //******************* Mouse Events ****************************
        if( Event.current.isMouse )
        {
            EventType eventType = Event.current.type;

            Vector2 mousePos = Event.current.mousePosition;

            if( eventType == EventType.MouseDown )
            {
                _draggedHandle = null;
                foreach( EnvelopeHandle handle in _handles )
                {
                    if( handle.HitTest( mousePos ) )
                    {
                        _draggedHandle = handle;
                        break;
                    }
                }

                if( _draggedHandle == null && _posHandle.HitTest( mousePos ) )
                {
                    _draggedHandle = _posHandle;
                }
            }
            else if( eventType == EventType.MouseUp )
            {
                _draggedHandle = null;
            }
            else if( eventType == EventType.MouseDrag && _draggedHandle != null )
            {
                if( _draggedHandle.Control == ControlType.Position )
                {
                    int posInSamples = _draggedHandle.EvaluatePosInSamples( mousePos.x );
                    int halfLength   = _envelopeModule.Length / 2;

                    if( posInSamples - halfLength < 0 )
                    {
                        posInSamples = halfLength;
                    }
                    else if( posInSamples + halfLength > EnvelopeHandle.MaxSamples )
                    {
                        posInSamples = EnvelopeHandle.MaxSamples - halfLength;
                    }

                    _handles[ 0 ].PosInSamples = posInSamples - halfLength;
                    _handles[ 1 ].PosInSamples = _handles[ 0 ].PosInSamples + _envelopeModule.FadeIn;

                    _handles[ 3 ].PosInSamples = posInSamples + halfLength;
                    _handles[ 2 ].PosInSamples = _handles[ 3 ].PosInSamples - _envelopeModule.FadeOut;

                    _posHandle.PosInSamples = posInSamples;

                    _envelopeModule.Offset = _handles[0].PosInSamples;
                }
                else
                {
                    _draggedHandle.Drag( mousePos.x );

                    if( _draggedHandle.Control == ControlType.AttackStart )
                    {
                        _envelopeModule.Offset = _draggedHandle.PosInSamples;
                        _envelopeModule.FadeIn = _handles[ 1 ].PosInSamples - _handles[ 0 ].PosInSamples;
                        _envelopeModule.Length = _handles[ 3 ].PosInSamples - _handles[ 0 ].PosInSamples;
                        UpdatePosHandle();
                    }
                    else if( _draggedHandle.Control == ControlType.AttackEnd )
                    {
                        _envelopeModule.FadeIn = _handles[ 1 ].PosInSamples - _handles[ 0 ].PosInSamples;
                    }
                    else if( _draggedHandle.Control == ControlType.ReleaseStart )
                    {
                        _envelopeModule.FadeOut = _handles[ 3 ].PosInSamples - _handles[ 2 ].PosInSamples;
                    }
                    else //ReleaseEnd
                    {
                        _envelopeModule.FadeOut = _handles[ 3 ].PosInSamples - _handles[ 2 ].PosInSamples;
                        _envelopeModule.Length = _handles[ 3 ].PosInSamples - _handles[ 0 ].PosInSamples;
                        UpdatePosHandle();
                    }
                }

                shouldRepaint = true;
            }
        }

        //*************************************************************
        //******************* Drawing *********************************
        for( i = 0; i < 4; i++ )
        {
            _handles[ i ].DrawHandle();
        }

        _posHandle.DrawHandle();

        for( i = 0; i < 4; i++ )
        {
            _linePoints[ i ] = _handles[ i ].Position;
        }

        Handles.color = Color.blue;
        Handles.DrawAAPolyLine( 2f, _linePoints );
        Handles.color = Color.grey;
        Handles.DrawLine( _start, _end );

        GUI.EndScrollView();

        GUILayout.Space( 110f );

        //*************************************************************
        //******************* Info ************************************
        _durationUnit = ( DurationUnit )EditorGUILayout.EnumPopup( _durationUnit, GUILayout.Width( 60f ) );
        GUILayoutOption labelWidth = GUILayout.Width( 90f );

        GUILayout.BeginHorizontal();
        GUILayout.Label( "Length: " + GetLengthStringForSamples( _envelopeModule.Length ), labelWidth );
        GUILayout.Label( "Offset: " + GetLengthStringForSamples( _envelopeModule.Offset ), labelWidth );
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Label( "Fade In: "  + GetLengthStringForSamples( _envelopeModule.FadeIn  ), labelWidth );
        GUILayout.Label( "Fade Out: " + GetLengthStringForSamples( _envelopeModule.FadeOut ), labelWidth );
        GUILayout.EndHorizontal();

        GUILayout.Space( 10f );
        _envelopeModule.Pulse = ( PulseModule )EditorGUILayout.ObjectField( _envelopeModule.Pulse, typeof( PulseModule ), true, GUILayout.Width( 130f ) );

        GUI.enabled = _envelopeModule.Pulse != null;

        _envelopeModule.MapLengthToPulse = GUILayout.Toggle( _envelopeModule.MapLengthToPulse, "Map Length To Pulse", GUILayout.ExpandWidth( false ) );

        GUI.enabled = true;
        if( _envelopeModule.Pulse != null && _envelopeModule.MapLengthToPulse )
        {
            GUILayout.Label( "Length to Pulse ratio: " + _envelopeModule.LengthToPulseRatio.ToString( "0.00" ) );
            _envelopeModule.LengthToPulseRatio = GUILayout.HorizontalSlider( _envelopeModule.LengthToPulseRatio, .1f, 8f, GUILayout.Width( 190f ) );
        }

        //************************************************************************************
        //*********************** ObjectPicker Messages Handling *****************************

        if (Event.current.commandName == "ObjectSelectorUpdated")
        {
            GATSoundBank bank = EditorGUIUtility.GetObjectPickerObject() as GATSoundBank;

            if( bank != null )
            {
                _selectedBankMax = bank.SizeOfLongestSample();
                _selectedBankMin = bank.SizeOfShortestSample();

                shouldRepaint = true;
                _selectedBank = bank;
            }
        }

        //************************************************************************************
        //*********************** SoundBank Clamping *****************************
        GUILayout.BeginArea( new Rect( 200f, 130f, 200f, 150f ) );
        GUILayout.Label( "Max Length: " + GetLengthStringForSamples( EnvelopeHandle.MaxSamples ) );

        EditorGUIUtility.labelWidth = 70f;
        _selectedBank = ( GATSoundBank )EditorGUILayout.ObjectField( "SoundBank:", _selectedBank, typeof( GATSoundBank ), false );

        if( _selectedBank != null )
        {
            if( GUILayout.Button( "Shortest sample:" + GetLengthStringForSamples( _selectedBankMin ), GUILayout.Width( 140f ) ) )
            {
                EnvelopeHandle.MaxSamples = _selectedBankMin;
                UpdateZoom();
            }

            if( GUILayout.Button( "Longest sample:" + GetLengthStringForSamples( _selectedBankMax ), GUILayout.Width( 140f ) ) )
            {
                EnvelopeHandle.MaxSamples = _selectedBankMax;
                UpdateZoom();
            }
        }
        else
        {
            EditorGUILayout.HelpBox( "Select a sound bank to easily map this envelope's max length to the bank's shortest or longest sample.", MessageType.Info );
        }

        //************************************************************************************
        //*********************** Reverse and Normalize **************************************

        _envelopeModule.Reverse = GUILayout.Toggle( _envelopeModule.Reverse, "Reverse" );
        GUILayout.BeginHorizontal();
        _envelopeModule.Normalize = GUILayout.Toggle( _envelopeModule.Normalize, "Normalize", GUILayout.Width( 75f ) );
        if( _envelopeModule.Normalize )
        {
            GUILayout.Label( _envelopeModule.NormalizeValue.ToString("0.00") );
            GUILayout.EndHorizontal();
            _envelopeModule.NormalizeValue = GUILayout.HorizontalSlider( _envelopeModule.NormalizeValue, 0f, 1f );
        }
        else GUILayout.EndHorizontal();

        GUILayout.EndArea();

        if( shouldRepaint )
            Repaint();
    }
Beispiel #5
0
 void OnEnable()
 {
     _soundBank = target as GATSoundBank;
 }
Beispiel #6
0
        public void EditorUpdateSoundBank( GATSoundBank bank = null )
        {
            if( bank != null )
            {
                _SoundBanks.Add ( bank );
            }

            UpdateSoundBank();
        }
Beispiel #7
0
        void UpdateSoundBank()
        {
            if( _soundBank == null && _SoundBanks.Count == 0 )
                return;

            int i;
            GATSoundBank soundBank = null;

            for( i = 0; i < _SoundBanks.Count; i++ )
            {
                soundBank = _SoundBanks[ i ];
                if( soundBank == null )
                    continue;

                if( soundBank.SampleRate == GATInfo.OutputSampleRate )
                {
                    _soundBank = soundBank;
                    break;
                }
            }

            if( soundBank == null )
            {
                #if UNITY_EDITOR || GAT_DEBUG
                Debug.LogError( string.Format( "SampleBank {0} could not find a sound bank of appropriate sample rate to load. Ouptut sample rate: {1}khz", this.name, GATInfo.OutputSampleRate.ToString () ) );
                #endif
                return;
            }
        }
    protected void CheckBanks( GATSoundBank newBank, int index )
    {
        if( newBank == null )
        {
            _sampleBank.EditorUpdateSoundBank();
            return;
        }

        GATSoundBank soundBank;

        for( int i = 0; i < _sampleBank.SoundBanks.Count; i++ )
        {
            if( i == index )
                continue;

            soundBank = _sampleBank.SoundBanks[ i ];

            if( soundBank == newBank )
            {
                EditorUtility.DisplayDialog( "Duplicate SoundBank Error", string.Format( "SoundBank {0} is already referenced .", newBank.name ), "OK" );
                _sampleBank.SoundBanks[ index ] = null;
                break;
            }
            else if( soundBank.SampleRate == newBank.SampleRate )
            {
                EditorUtility.DisplayDialog( "Duplicate Sample Rate Error", string.Format( "{0}khz sample rate is already covered by SoundBank {1}  .", soundBank.SampleRate.ToString() ,soundBank.name ), "OK" );
                _sampleBank.SoundBanks[ index ] = null;
                break;
            }
            else if( soundBank.SampleInfos.Count != newBank.SampleInfos.Count )
            {
                EditorUtility.DisplayDialog( "SoundBank Mismatch Error", string.Format( "SoundBank {0} does not have the same number of sounds as SoundBank {1}. Check your SoundBanks and make sure they correspond.", newBank.name ,soundBank.name ), "OK" );
                _sampleBank.SoundBanks[ index ] = null;
                break;
            }
        }

        _sampleBank.EditorUpdateSoundBank();
    }