Exemple #1
0
    // -----------------------------------------------------------------------------
    // Name	:	Activate
    // Desc	:	Overrides the base class functionality that would ordinarilty remove
    //			a collectable item from the scene. In the case of PDAs, we essentially
    //			download the data (remove disk) leaving the PDA in the scene but no
    //			longer functional
    // ------------------------------------------------------------------------------
    public override void Activate(CharacterManager characterManager)
    {
        // This is an empty PDA so nothing to take
        if (!_audioItem)
        {
            return;
        }

        // We need a valid character manager and inventory manager
        if (_inventory != null)
        {
            // Add this item to the inventory
            if (_inventory.AddItem(this, true))
            {
                // Set Empty Text
                _interactiveText = "Audio Log: Empty";

                // Remove Data
                _inventoryItem = _audioItem = null;

                // Disable screen Texture
                if (_screenRenderer)
                {
                    _screenRenderer.material.SetTexture("_EmissionMap", null);
                    _screenRenderer.material.SetColor("_EmissionColor", Color.black);
                }
            }
        }
    }
    // --------------------------------------------------------------------------------------------
    // Name :   AddRecordingItem
    // Desc :   Adds an AudioRecording to the Inventory and begins playing is AutoPlay is enabled
    // --------------------------------------------------------------------------------------------
    protected bool AddRecordingItem(InventoryItemAudio inventoryAudio, CollectableAudio collectableAudio, bool playAudio)
    {
        if (inventoryAudio)
        {
            // Play the pickup sound
            inventoryAudio.Pickup(collectableAudio.transform.position, playAudio);

            // Add audio recording to the list
            _recordings.Add(inventoryAudio);

            // Play on Pick if configured to do so
            if (_autoPlayOnPickup)
            {
                // Tell Inventory to play this audio recording immediately
                // This should be the one at end of the recordings list
                PlayAudioRecording(_recordings.Count - 1);
            }

            if (_notificationQueue)
            {
                _notificationQueue.Enqueue("Audio Recording Added");
            }


            // Data successfully retrieved
            return(true);
        }

        return(false);
    }
    // --------------------------------------------------------------------------------------------
    // Name :   PlayAudio
    // Desc :   Called (usually by Inventory System) to start playing an Inventory Audio Item.
    //          This raises the BeginAudio event and then starts up the Update coroutine.
    // --------------------------------------------------------------------------------------------
    public void PlayAudio(InventoryItemAudio audioItem)
    {
        // Stop the coroutine if was running previously
        if (_coroutine != null)
        {
            StopCoroutine(_coroutine);
            _coroutine = null;
        }

        // Stop playing any sound that the audio source is already playing
        if (_audioSource && _audioSource.isPlaying)
        {
            // Stop audio playing
            _audioSource.Stop();

            // Clear transcript text
            if (_transcriptText)
            {
                _transcriptText.value = null;
            }
        }

        // Failure - so fire stop event immediately
        if (!audioItem || !_audioSource || !audioItem.audioCollection)
        {
            StopAudio();
            return;
        }

        // Inventory Items always have USE clips in third bank
        AudioClip clip = audioItem.audioCollection[2];

        if (!clip)
        {
            StopAudio();
            return;
        }

        // Configure Audio Source
        _audioSource.clip         = clip;
        _audioSource.volume       = audioItem.audioCollection.volume;
        _audioSource.spatialBlend = audioItem.audioCollection.spatialBlend;
        _audioSource.priority     = audioItem.audioCollection.priority;
        _audioSource.Play();

        // Fire Begin Event
        OnBeginAudio.Invoke(audioItem);

        // Start  Update Coroutine
        _coroutine = UpdateAudio(audioItem);
        StartCoroutine(_coroutine);
    }
Exemple #4
0
    // --------------------------------------------------------------------
    // Name	:	SetData
    // Desc	:	Called by the InventoryUI to configure the entry with
    //          with its text data
    // --------------------------------------------------------------------
    public void SetData(InventoryItemAudio itemAudio, int index)
    {
        // Store Audio Item
        _inventoryItemAudio = itemAudio;

        // Store the index of this item in the list
        _index = index;

        // Is this the sound that is currently playing
        bool isActive = IsActive();

        // Set the actual Text
        if (_inventoryItemAudio)
        {
            if (_name)
            {
                _name.text = _inventoryItemAudio.person;
            }
            if (_subject)
            {
                _subject.text = _inventoryItemAudio.subject;
            }
        }
        else
        {
            if (_name)
            {
                _name.text = null;
            }
            if (_subject)
            {
                _subject.text = null;
            }
        }

        // Set Text Colors
        if (_name)
        {
            _name.color = isActive ? _activeColor : _normalColor;
        }
        if (_subject)
        {
            _subject.color = isActive ? _activeColor : _normalColor;
        }
    }
Exemple #5
0
    // ---------------------------------------------------------------------------------------------
    // Name :   Start
    // Desc :   Caches a reference to the associated InventoryAudioItem and sets the texture
    //          of that audio item.
    // ---------------------------------------------------------------------------------------------
    protected override void Start()
    {
        // Call Base Class to register as an interactive item
        base.Start();

        // Cache Inventory Item as correct type
        _audioItem = _inventoryItem as InventoryItemAudio;

        // If we have an audio item reference
        if (_audioItem)
        {
            if (_screenRenderer)
            {
                _screenRenderer.material.SetTexture("_EmissionMap", _audioItem.image);
                _screenRenderer.material.SetColor("_EmissionColor", _emissiveColor);
            }
        }
    }
Exemple #6
0
    public void OnBeginAudio(InventoryItemAudio audioItem)
    {
        if (!audioItem)
        {
            return;
        }

        if (_pdaOverlay)
        {
            _pdaOverlay.SetActive(true);
        }
        if (_pdaPerson)
        {
            _pdaPerson.text = audioItem.person;
        }
        if (_pdaSubject)
        {
            _pdaSubject.text = audioItem.subject;
        }
    }
    // --------------------------------------------------------------------------------------------
    // Name :   UpdateAudio (Coroutine)
    // Desc :   Is called each frame while the audio clip is playing.
    // --------------------------------------------------------------------------------------------
    protected IEnumerator UpdateAudio(InventoryItemAudio audioItem)
    {
        // If we have a valid InventoryItem and if this object has an audio source
        if (audioItem && _audioSource)
        {
            // Used for keeping track of timeline
            int previousStateKeyIndex   = 0;
            int previousCaptionKeyIndex = 0;

            // Used to store a reference of Audio Item's State and Caption keys
            // This is NOT a copy of the keys so don't alter
            List <TimedStateKey>   stateKeys   = audioItem.stateKeys;
            List <TimedCaptionKey> captionKeys = audioItem.captionKeys;

            // Keep iterating while sound clip is playing
            while (_audioSource.isPlaying)
            {
                // Invoke Update Event with normalized time
                OnUpdateAudio.Invoke(_audioSource.time / _audioSource.clip.length);

                // Do we have state keys to process and a valid app manager
                if (stateKeys != null && ApplicationManager.instance)
                {
                    // Loop from the previous key we found that we have not yet executed
                    for (int i = previousStateKeyIndex; i < stateKeys.Count; i++)
                    {
                        // Is it a legit key?
                        TimedStateKey keyFrame = stateKeys[i];
                        if (keyFrame != null)
                        {
                            // If we haven't reached this key yet then store this
                            // as our previous key and abort so we can test from this
                            // key next time
                            if (keyFrame.Time > _audioSource.time)
                            {
                                previousStateKeyIndex = i;
                                break;
                            }

                            // Set the state described by the keyframe
                            if (ApplicationManager.instance.SetGameState(keyFrame.Key, keyFrame.Value))
                            {
                                // Add Key Message to Shared Notification Queue
                                if (_notificationQueue)
                                {
                                    _notificationQueue.Enqueue(keyFrame.UIMessage);
                                }

                                // Play notification Sound
                                if (AudioManager.instance && _stateNotificationSounds)
                                {
                                    AudioClip clip = _stateNotificationSounds.audioClip;
                                    if (clip)
                                    {
                                        AudioManager.instance.PlayOneShotSound(_stateNotificationSounds.audioGroup,
                                                                               clip,
                                                                               _playerPosition ? _playerPosition.value : Vector3.zero,
                                                                               _stateNotificationSounds.volume,
                                                                               _stateNotificationSounds.spatialBlend,
                                                                               _stateNotificationSounds.priority,
                                                                               0.0f,
                                                                               true);
                                    }
                                }
                            }

                            previousStateKeyIndex++;
                        }
                    }
                }

                // Do we have Caption keys to process
                if (captionKeys != null)
                {
                    // Loop from the previous key we found that we have not yet executed
                    for (int i = previousCaptionKeyIndex; i < captionKeys.Count; i++)
                    {
                        // Is it a legit key?
                        TimedCaptionKey keyFrame = captionKeys[i];
                        if (keyFrame != null)
                        {
                            // If we haven't reached this key yet then store this
                            // as our previous key and abort so we can test from this
                            // key next time
                            if (keyFrame.Time > _audioSource.time)
                            {
                                previousCaptionKeyIndex = i;
                                break;
                            }

                            // Set the global shared transcript variable to the caption text
                            if (_transcriptText)
                            {
                                _transcriptText.value = keyFrame.Text;
                            }

                            previousCaptionKeyIndex++;
                        }
                    }
                }

                yield return(null);
            }
        }

        // Stop the audio and invoke ending event
        StopAudio();
    }