Exemplo n.º 1
0
 /// <summary> Panel to show all "Global" Sequences that have been added via script while playing </summary>
 /// <param name="inlineHelp">Should help be displayed? </param>
 void AddedSequencesPanel(bool inlineHelp)
 {
     foreach (Sequence data in GlobalSequences)
     {
         EditorGUILayout.BeginHorizontal();
         Rect r = EditorGUILayout.GetControlRect(GUILayout.ExpandWidth(true));
         if (Event.current.type == EventType.MouseDrag && r.Contains(Event.current.mousePosition))
         {
             DragAndDrop.PrepareStartDrag();
             DragAndDrop.objectReferences = new Object[] { data };
             DragAndDrop.StartDrag("Sequence:" + data.name);
             Event.current.Use();
             weStartedDrag = true;
         }
         else if ((Event.current.type == EventType.MouseUp || Event.current.type == EventType.DragExited) && weStartedDrag)
         {
             weStartedDrag = false;
             DragAndDrop.PrepareStartDrag();
         }
         EditorGUI.ObjectField(r, data, typeof(Sequence), false);
         if (m_editorUtils.Button("RemoveSequenceButton", GUILayout.ExpandWidth(false)))
         {
             AmbienceManager.RemoveSequence(data);
         }
         EditorGUILayout.EndHorizontal();
     }
 }
Exemplo n.º 2
0
 /// <summary> Panel to show all active "Events" while playing </summary>
 /// <param name="inlineHelp">Should help be displayed?</param>
 void EventsPanel(bool inlineHelp)
 {
     ++EditorGUI.indentLevel;
     EditorGUILayout.BeginHorizontal();
     {
         if (m_editorUtils.Button("AddEventButton", inlineHelp, GUILayout.Width(40)) && !string.IsNullOrEmpty(tmpTrigger))
         {
             AmbienceManager.ActivateEvent(tmpTrigger);
             tmpTrigger = "";
         }
         tmpTrigger = GUILayout.TextField(tmpTrigger);
     }
     EditorGUILayout.EndHorizontal();
     foreach (string str in AmbienceManager.GetEvents())
     {
         EditorGUILayout.BeginHorizontal();
         {
             if (m_editorUtils.Button("RemoveEventButton", GUILayout.Width(40)))
             {
                 AmbienceManager.DeactivateEvent(str);
             }
             GUILayout.Label(str);
         }
         EditorGUILayout.EndHorizontal();
     }
     --EditorGUI.indentLevel;
 }
Exemplo n.º 3
0
 private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     DontDestroyOnLoad(this);
 }
Exemplo n.º 4
0
    void Start()
    {
        musicManager    = GetComponentInChildren <MusicManager>();
        ambienceManager = GetComponentInChildren <AmbienceManager>();
        gameSFX         = GetComponentInChildren <GameSFX>();
        playerSFX       = GetComponentInChildren <PlayerSFX>();

        musicManager.GetComponent <AudioSource>().clip = sceneDefaultMusic;
    }
Exemplo n.º 5
0
 // Use this for initialization
 void Start()
 {
     if (main == null)
     {
         main = this;
     }
     else
     {
         Destroy(this.gameObject);
     }
     ambience = this.GetComponent <AudioSource>();
 }
Exemplo n.º 6
0
 private void Update()
 {
     if (enemyReference1 == null &&
         enemyReference2 == null &&
         enemyReference3 == null)
     {
         AmbienceManager.DeactivateEvent("Combat");
     }
     else
     {
         AmbienceManager.ActivateEvent("Combat");
     }
 }
Exemplo n.º 7
0
        void OnRemovedGlobalSequence(UnityEditorInternal.ReorderableList list)
        {
            if (list.index < 0 || list.index >= list.count)
            {
                return;
            }
            Sequence toRemove = m_globalSequences.GetArrayElementAtIndex(list.index).objectReferenceValue as Sequence;

            m_globalSequences.DeleteArrayElementAtIndex(list.index);
            if (Application.isPlaying && toRemove != null && !AmbienceManager.WasSequenceAdded(toRemove))
            {
                AmbienceManager.OnEditorRemovedSequence(toRemove);
            }
        }
Exemplo n.º 8
0
 /// <summary> Checks position in LateUpdate after everything should have finished moving </summary>
 private void LateUpdate()
 {
     if (PlayerObject == null)
     {
         AmbienceManager manager = FindObjectOfType <AmbienceManager>();
         if (manager)
         {
             PlayerObject = manager.m_playerObject;
         }
         else
         {
             Camera mainCamera = Camera.main;
             if (mainCamera)
             {
                 PlayerObject = mainCamera.transform;
             }
             else
             {
                 Debug.LogWarning("No Player Object specified, no AmbienceManager found, and no Camera. Unable to auto-select object.", this);
                 return;
             }
         }
     }
     if (PlayerObject)
     {
         if (isWithin(PlayerObject.position))
         {
             if (!lastWasSet)
             {
                 lastWasSet = true;
                 AmbienceManager.ActivateEvent(EventName);
             }
         }
         else
         {
             if (lastWasSet)
             {
                 lastWasSet = false;
                 AmbienceManager.DeactivateEvent(EventName);
             }
         }
     }
 }
Exemplo n.º 9
0
        /// <summary> Panel to show all Blocked Sequences </summary>
        /// <param name="inlineHelp">Should help be displayed?</param>
        void CurrentlyBlockedPanel(bool inlineHelp)
        {
            Event currentEvent = Event.current;

            foreach (KeyValuePair <Sequence, string> seq in GlobalBlocked)
            {
                EditorGUILayout.BeginHorizontal();
                Rect r         = EditorGUILayout.GetControlRect();
                Rect labelRect = r;
                labelRect.xMin += EditorGUIUtility.labelWidth;
                GUI.Label(labelRect, new GUIContent(seq.Value, seq.Value));
                labelRect.xMax = labelRect.xMin;
                labelRect.xMin = r.xMin;
                Rect meterRect = labelRect;
                meterRect.xMin = meterRect.xMax - meterRect.height;
                if (currentEvent.type == EventType.MouseDown && meterRect.Contains(currentEvent.mousePosition))
                {
                    currentEvent.Use();
                }
                else if (currentEvent.type == EventType.MouseDrag && r.Contains(currentEvent.mousePosition))
                {
                    DragAndDrop.PrepareStartDrag();
                    DragAndDrop.objectReferences = new Object[] { seq.Key };
                    DragAndDrop.StartDrag("Sequence:" + seq.Key.name);
                    currentEvent.Use();
                    weStartedDrag = true;
                }
                else if ((currentEvent.type == EventType.MouseUp || currentEvent.type == EventType.DragExited) && weStartedDrag)
                {
                    weStartedDrag = false;
                    DragAndDrop.PrepareStartDrag();
                }
                EditorGUI.ObjectField(labelRect, seq.Key, typeof(Sequence), false);
                meterRect.xMin  = labelRect.xMax - r.height * 0.75f;
                meterRect.xMax -= labelRect.height * 0.125f;
                if (m_editorUtils.Button("ForceUnblockSequence", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false)))
                {
                    AmbienceManager.Debug_UnBlockSequence(seq.Key);
                }
                EditorGUILayout.EndHorizontal();
            }
        }
Exemplo n.º 10
0
        /// <summary> Main GUI Function </summary>
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            m_editorUtils.Initialize(); // Do not remove this!
            m_editorUtils.GUIHeader();
            m_editorUtils.TitleNonLocalized(m_editorUtils.GetContent("SequenceDataHeader").text + serializedObject.targetObject.name);

            EditorGUI.BeginDisabledGroup(!Application.isPlaying);
            if (!Application.isPlaying || !AmbienceManager.WasSequenceAdded(target as Sequence))
            {
                if (m_editorUtils.Button("EditorPlayButton"))
                {
                    Sequence seq = target as Sequence;
                    seq.m_forcePlay = true;
                    AmbienceManager.AddSequence(seq);
                }
            }
            else
            {
                if (m_editorUtils.Button("EditorStopButton"))
                {
                    Sequence seq = target as Sequence;
                    seq.m_forcePlay = false;
                    AmbienceManager.RemoveSequence(seq);
                }
            }
            EditorGUI.EndDisabledGroup();

            m_editorUtils.Panel("RequirementsPanel", RequirementsPanel, true);
            m_editorUtils.Panel("ClipsPanel", ClipsPanel, true);
            m_editorUtils.Panel("OutputPanel", OutputPanel, true);
            m_editorUtils.Panel("RandomizationPanel", RandomizationPanel, true);
            m_editorUtils.Panel("ModifiersPanel", ModifiersPanel, true);
            m_editorUtils.Panel("EventsPanel", EventsPanel, true);
            m_editorUtils.Panel("SyncPanel", SyncPanel, true);

            //m_editorUtils.GUIFooter();
            serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 11
0
 /// <summary> Panel to show all active "Values" and thier values while playing </summary>
 /// <param name="inlineHelp">Should help be displayed?</param>
 void ValuesPanel(bool inlineHelp)
 {
     ++EditorGUI.indentLevel;
     EditorGUILayout.BeginHorizontal();
     {
         if (m_editorUtils.Button("AddValueButton", GUILayout.Width(40)) && !string.IsNullOrEmpty(tmpValueName))
         {
             AmbienceManager.SetValue(tmpValueName, tmpValueValue);
             tmpValueName  = "";
             tmpValueValue = 0f;
         }
         tmpValueName = GUILayout.TextField(tmpValueName, GUILayout.ExpandWidth(true)); //GUILayout.Width(Mathf.Clamp(EditorStyles.textField.CalcSize(new GUIContent(tmpValueName + "|")).x, 80f, EditorGUIUtility.currentViewWidth * 0.5f)));
         //tmpValueValue = EditorGUILayout.Slider(tmpValueValue, 0f, 1f);
     }
     EditorGUILayout.EndHorizontal();
     foreach (KeyValuePair <string, float> Value in AmbienceManager.GetValues())
     {
         EditorGUILayout.BeginHorizontal();
         {
             if (m_editorUtils.Button("RemoveValueButton", GUILayout.Width(40)))
             {
                 AmbienceManager.RemoveValue(Value.Key);
             }
             string label = Value.Key;
             if (label.Length > 25)
             {
                 label = label.Substring(0, 25);
             }
             GUILayout.Label(new GUIContent(label, Value.Key), GUILayout.ExpandWidth(false));
             EditorGUI.BeginChangeCheck();
             float tmpVal = EditorGUILayout.Slider(Value.Value, 0f, 1f, GUILayout.ExpandWidth(true));
             if (EditorGUI.EndChangeCheck())
             {
                 AmbienceManager.SetValue(Value.Key, tmpVal);
             }
         }
         EditorGUILayout.EndHorizontal();
     }
     --EditorGUI.indentLevel;
 }
Exemplo n.º 12
0
 /// <summary> Updates FadeValue. Called when updating events or values. </summary>
 public void UpdateFadeValue()
 {
     if (m_requirements == ValuesOrEvents.ValuesOrEvents)
     {
         FadeValue = Mathf.Max(AmbienceManager.CheckEvents(m_events, m_eventsMix) ? 1f : 0f, AmbienceManager.CheckValues(m_values, m_valuesMix));
         return;
     }
     if ((m_requirements & ValuesOrEvents.Events) == ValuesOrEvents.Events)
     {
         if (!AmbienceManager.CheckEvents(m_events, m_eventsMix))
         {
             FadeValue = 0f;
             return;
         }
     }
     if ((m_requirements & ValuesOrEvents.Values) == ValuesOrEvents.Values)
     {
         FadeValue = AmbienceManager.CheckValues(m_values, m_valuesMix);
     }
     else
     {
         FadeValue = 1f;
     }
 }
Exemplo n.º 13
0
    void Awake()
    {
        _charController         = GetComponent <CharacterController>();
        _initMovementSpeed      = _movementSpeed;
        _initPoisonCoolDownTime = _poisonCoolDownTime;
        _initFireCoolTime       = _fireCoolDownTime;
        _initStaminaLevel       = _staminaLevel;

        tm = FindObjectOfType <TerrainManager>();


#if UNITY_SERVER
        return;
#endif

        ambienceManager = FindObjectOfType <AmbienceManager>();
        if (ambienceManager == null)
        {
            ambienceManager = gameObject.AddComponent <AmbienceManager>();
        }
        ambienceManager.m_playerObject = transform;

        pCam = GetComponentInChildren <PlayerCamera>();
    }
Exemplo n.º 14
0
 public void PlayHeartBeat()
 {
     AmbienceManager.AddSequence(Heartbeat);
     AmbienceManager.ActivateEvent("Heartbeat");
 }
Exemplo n.º 15
0
 /// <summary> Removes this Positional from the AmbientSounds Manager when disabling/destroying </summary>
 private void OnDisable()
 {
     AmbienceManager.RemoveArea(this);
 }
Exemplo n.º 16
0
    void UpdatePlayerPostProcessing()
    {
        if (tm == null)
        {
            tm = FindObjectOfType <TerrainManager>();
        }
        if (tm == null)
        {
            return;
        }
        Biome biome = tm.GetBiome(transform.position);
        List <TerrainManager.BiomeStrength> biomes =
            tm.GetBiomes(transform.position);
        PostProcessVolume ppv;
        float             remainder = 0.0f;

        for (int i = 0; i < biomes.Count; i++)
        {
            if (!ppVolumes.ContainsKey(biomes[i].biome))
            {
                if (biomes[i].biome.postProcessing != null)
                {
                    ppv = postProcessVolume.gameObject.
                          AddComponent <PostProcessVolume>();
                    ppv.isGlobal = postProcessVolume.isGlobal;
                    ppv.priority = postProcessVolume.priority;
                    ppv.weight   = biomes[i].strength;
                    ppv.profile  = biomes[i].biome.postProcessing;
                }
                else
                {
                    ppv = null;
                }
                ppVolumes.Add(biomes[i].biome, ppv);
            }
        }

        List <KeyValuePair <Biome, PostProcessVolume> > ppvs = ppVolumes.ToList();

        for (int i = 0; i < ppvs.Count; i++)
        {
            ppvs[i].Value.weight = 0.0f;
            for (int j = 0; j < biomes.Count; j++)
            {
                if (ppvs[i].Key == biomes[j].biome)
                {
                    if (ppvs[i].Value != null)
                    {
                        ppvs[i].Value.weight = biomes[j].strength;
                    }
                    else
                    {
                        remainder += biomes[j].strength;
                    }
                }
            }
        }
        postProcessVolume.weight = remainder;

        if (previousBiome != biome)
        {
            if (previousBiome != null)
            {
                for (int i = 0; i < previousBiome.globalSounds.Length; i++)
                {
                    AmbienceManager.RemoveSequence(previousBiome.globalSounds[i]);
                }
            }
            if (biome != null)
            {
                for (int i = 0; i < biome.globalSounds.Length; i++)
                {
                    Debug.Log(" BSequence Name: " + biome.globalSounds[i].name);
                    AmbienceManager.AddSequence(biome.globalSounds[i]);
                }
            }

            /*
             * int idx = ambienceManager.m_globalSequences.Length;
             * Array.Resize(ref ambienceManager.m_globalSequences, idx + biome.globalSounds.Length);
             * foreach (var sequence in biome.globalSounds)
             * {
             *  //ambienceManager.m_globalSequences[idx++] = sequence;
             * }
             */
            previousBiome = biome;
        }
    }
Exemplo n.º 17
0
        /// <summary> Updates clip list if it changed. (Call from within Update() function) </summary>
        public void UpdateClips()
        {
            if (m_sequence == null)
            {
                return;
            }
            List <AudioClip> allClips = new List <AudioClip>(m_sequence.Clips.Length);

            foreach (Sequence.ClipData clip in m_sequence.Clips)
            {
                if (clip.m_clip != null)
                {
                    allClips.Add(clip.m_clip);
                }
            }
            if (allClips.Count == 0)
            {
                Debug.LogWarning("No audio clips found in Sequence '" + m_name + "'!");
            }
            bool changed = false;

            if (allClips.Count != DirectClipData.Length)
            {
                //length changed so it definitly changed.
                changed = true;
            }
            else
            {
                for (int c = 0; c < DirectClipData.Length; ++c)
                {
                    if (DirectClipData[c] != allClips[c])
                    {
                        changed = true;
                        break;
                    }
                }
            }
            if (changed)   //update current raw clip list then select our current track if it still exists.
            {
                RawAudioData[] newRawClipData = new RawAudioData[allClips.Count];
                AudioClip      curClip        = m_isOutputDirect ? DirectClipData[currentClipIdx] : RawClipData[currentClipIdx].BaseClip;
                int            newClipIdx     = -1;
                for (int c = 0; c < allClips.Count; ++c)
                {
                    if (allClips[c] == curClip)
                    {
                        newClipIdx = c;
                    }
                    newRawClipData[c] = AmbienceManager.GetAudioData(allClips[c]);
                }
                NextClipIdx = -1;
                if (newClipIdx < 0)
                {
                    PlayToFade    = RawClipData[currentClipIdx];
                    RawClipData   = newRawClipData;
                    newClipIdx    = NextClipIdx;
                    DirectFadeOut = true;
                }
                else
                {
                    RawClipData = newRawClipData;
                }
                currentClipIdx = newClipIdx;
                DirectClipData = allClips.ToArray();
                if (m_sequence.RandomizeVolume)
                {
                    curVolumeMod = Helpers.GetRandom(m_sequence.MinMaxVolume);
                }
                else
                {
                    curVolumeMod = 1f;
                }
                if (!isSynced && m_sequence.RandomizePlaybackSpeed)
                {
                    curPlaybackSpeedMod = Helpers.GetRandom(m_sequence.MinMaxPlaybackSpeed);
                }
                else
                {
                    curPlaybackSpeedMod = 1f;
                }
                if (MySyncGroup != null)
                {
                    MySyncGroup.UpdateLength();
                }
            }
        }
Exemplo n.º 18
0
 /// <summary> Adds this Positional to the AmbientSounds Manager when enabling </summary>
 private void OnEnable()
 {
     AmbienceManager.AddArea(this);
 }
Exemplo n.º 19
0
 bool CanAddStopMenuItem()
 {
     return(Application.isPlaying && AmbienceManager.WasSequenceAdded(this));
 }
Exemplo n.º 20
0
        /// <summary> To be called every time a Modifier changes so the properties can be recalculated </summary>
        public void UpdateModifiers()
        {
            m_hasBeenUpdated = true;
            List <ClipData> clips = new List <ClipData>(m_clipData);

            for (int m = 0; m < m_modifiers.Length; ++m)
            {
                if (m_modifiers[m] == null)
                {
                    continue;
                }
                m_modifiers[m].UpdateFadeValue();
                if (m_modifiers[m].m_modRandomizeVolume)
                {
                    if (m_modifiers[m].FadeValue > 0.5f)
                    {
                        _randomizeVolumeModIsSet = true;
                        _randomizeVolumeMod      = m_modifiers[m].m_randomizeVolume;
                    }
                }
                if (m_modifiers[m].m_modRandomizePlaybackSpeed)
                {
                    if (m_modifiers[m].FadeValue > 0.5f)
                    {
                        _randomizePlaybackSpeedModIsSet = true;
                        _randomizePlaybackSpeedMod      = m_modifiers[m].m_randomizePlaybackSpeed;
                    }
                }
                if (m_modifiers[m].m_modClips)
                {
                    if (m_modifiers[m].FadeValue >= 0.5f)   //can only change the array fully or not at all ... so do it at half way up
                    {
                        if (m_modifiers[m].m_modClipsType == ClipModType.Add)
                        {
                            clips.AddRange(m_modifiers[m].m_clipData);
                        }
                        else if (m_modifiers[m].m_modClipsType == ClipModType.Remove)
                        {
                            foreach (ClipData clip in m_modifiers[m].m_clipData)
                            {
                                if (clip.m_clip != null)
                                {
                                    clips.RemoveAll(delegate(ClipData c) {
                                        return(c.m_clip == clip.m_clip);
                                    });
                                }
                            }
                        }
                        else     //Replace
                        {
                            clips = new List <ClipData>(m_modifiers[m].m_clipData);
                        }
                    }
                }
            }
            float newLength = 0f;

            clips.RemoveAll(c => c.m_clip == null);
            foreach (ClipData clip in clips)
            {
                newLength += (AmbienceManager.GetAudioData(clip.m_clip).Length - m_crossFade) * PlaybackSpeed;
                //newLength += (clip.length - m_crossFade) * PlaybackSpeed;
            }
            if (newLength != TotalLength)
            {
                TotalLength = newLength;
                if (!string.IsNullOrEmpty(m_syncGroup))
                {
                    SyncGroup.Get(m_syncGroup).UpdateLength();
                }
            }
            lock (ClipsLockHandle)
                Clips = clips.ToArray();
        }
Exemplo n.º 21
0
        /// <summary> Main GUI function </summary>
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            m_editorUtils.Initialize(); // Do not remove this!

            m_editorUtils.Panel("GeneralPanel", GeneralPanel, true);
            m_editorUtils.Panel("GlobalSequencesPanel", GlobalSequencesPanel, true);
            m_editorUtils.Panel("OutputPanel", OutputPanel, true);

            if (EditorApplication.isPlaying)
            {
                AmbienceManager.GetSequences(ref GlobalSequences, ref AreaSequences);
                AllTracks     = AmbienceManager.GetTracks();
                GlobalBlocked = AmbienceManager.GetBlocked();
                if (AreaSequences.Count > 0)
                {
                    m_editorUtils.Panel("AreaAudioPanel", AreaAudioPanel, true);
                }
                if (GlobalSequences.Count > 0)
                {
                    m_editorUtils.Panel("AddedSequencesPanel", AddedSequencesPanel, true);
                }
                if (AllTracks.Count > 0)
                {
                    m_editorUtils.Panel("CurrentlyPlayingPanel", CurrentlyPlayingPanel, true);
                }
                if (GlobalBlocked.Count > 0)
                {
                    m_editorUtils.Panel("CurrentlyBlockedPanel", CurrentlyBlockedPanel, true);
                }
                m_editorUtils.Panel("ValuesPanel", ValuesPanel, true);
                m_editorUtils.Panel("EventsPanel", EventsPanel, true);
                EditorUtility.SetDirty(target);
            }

            Event currentEvent = Event.current;

            if (currentEvent.type == EventType.DragUpdated && DragAndDrop.objectReferences.Length > 0)
            {
                for (int x = 0; x < DragAndDrop.objectReferences.Length; ++x)
                {
                    if (DragAndDrop.objectReferences[x] is Sequence && string.IsNullOrEmpty((DragAndDrop.objectReferences[x] as Sequence).m_syncGroup))
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                        break;
                    }
                }
            }
            else if (currentEvent.type == EventType.DragPerform && DragAndDrop.objectReferences.Length > 0)
            {
                bool foundOne = false;
                for (int x = 0; x < DragAndDrop.objectReferences.Length; ++x)
                {
                    if (DragAndDrop.objectReferences[x] is Sequence)
                    {
                        Sequence seq = DragAndDrop.objectReferences[x] as Sequence;
                        m_globalSequences.InsertArrayElementAtIndex(m_globalSequences.arraySize);
                        m_globalSequences.GetArrayElementAtIndex(m_globalSequences.arraySize - 1).objectReferenceValue = seq;
                        foundOne = true;
                    }
                }
                if (foundOne)
                {
                    DragAndDrop.AcceptDrag();
                    currentEvent.Use();
                }
            }

            serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 22
0
 public void RemoveHeartBeat()
 {
     AmbienceManager.RemoveSequence(Heartbeat);
     AmbienceManager.DeactivateEvent("Heartbeat");
 }
Exemplo n.º 23
0
 private void OnEnable()
 {
     instance = this;
 }
Exemplo n.º 24
0
        /// <summary>
        /// Constructor using AmbienceData as the source
        /// </summary>
        /// <param name="source">AmbienceData to base this track on</param>
        /// <param name="startingTime">Time in seconds from start of track to begin playback</param>
        public AudioTrack(Sequence source, bool playOnce = false)
        {
            IsPlayOnce = playOnce;
            CurFade    = playOnce ? 1f : 0f;
            trackTime  = 0.0;
            m_sequence = source;
            if (m_sequence == null)
            {
                Debug.LogError("Cannot create AudioTrack data for null source.");
                RawClipData    = new RawAudioData[0];
                DirectClipData = new AudioClip[0];
                m_name         = "NULL";
                return;
            }
            curPlaybackSpeed = m_sequence.PlaybackSpeed;
            curVolume        = m_sequence.Volume;
            m_name           = m_sequence.name;
            //check for nulls and skip them
            List <AudioClip> allClips = new List <AudioClip>(m_sequence.Clips.Length);

            foreach (Sequence.ClipData clip in m_sequence.Clips)
            {
                if (clip.m_clip != null)
                {
                    if (clip.m_clip.loadType != AudioClipLoadType.DecompressOnLoad)
                    {
                        m_outputNeedsIntialized = true;
                        m_isOutputDirect        = true; //Cannot read streaming or compressed clip data
                    }
                    allClips.Add(clip.m_clip);
                }
            }
            if (allClips.Count == 0)
            {
                Debug.LogWarning("No audio clips found in Sequence '" + m_name + "'!");
            }

            //get the actual audio data for the clips
            DirectClipData = allClips.ToArray();
            RawClipData    = new RawAudioData[allClips.Count];
            for (int c = 0; c < RawClipData.Length; ++c)
            {
                RawClipData[c] = AmbienceManager.GetAudioData(allClips[c]);
            }
            currentClipIdx = NextClipIdx;
            if (m_sequence.m_clipData.Length > currentClipIdx)
            {
                curVolume *= m_sequence.m_clipData[currentClipIdx].m_volume;
            }
            if (m_sequence.RandomizeVolume)
            {
                curVolumeMod = Helpers.GetRandom(m_sequence.MinMaxVolume);
            }
            else
            {
                curVolumeMod = 1f;
            }
            if (!isSynced && m_sequence.RandomizePlaybackSpeed)
            {
                curPlaybackSpeedMod = Helpers.GetRandom(m_sequence.MinMaxPlaybackSpeed);
            }
            else
            {
                curPlaybackSpeedMod = 1f;
            }
            if (MySyncGroup == null && m_sequence.TrackDelayTime > 0)
            {
                //Debug.Log("Starting AudioTrack with delay of " + source.TrackDelayTime);
                isDelaying = true;
            }
        }
Exemplo n.º 25
0
 void PlayMenuItem()
 {
     m_forcePlay = true;
     AmbienceManager.AddSequence(this);
 }
Exemplo n.º 26
0
 /// <summary>
 /// Constructor using a single AudioClip as a source with optional AmbienceData source it came from
 /// </summary>
 /// <param name="clip">AudioClip to base AudioTrack on</param>
 /// <param name="source">AmbienceData with settings for audio clip</param>
 /// <param name="startingTime">Time in seconds from start of track to begin playback</param>
 public AudioTrack(AudioClip clip, Sequence source, bool playOnce = false)
 {
     IsPlayOnce = playOnce;
     CurFade    = playOnce ? 1f : 0f;
     trackTime  = 0.0;
     m_sequence = source;
     if (clip == null)
     {
         Debug.LogError("Cannot create AudioTrack data for null source clip.");
         RawClipData    = new RawAudioData[0];
         DirectClipData = new AudioClip[0];
         return;
     }
     if (clip.loadType != AudioClipLoadType.DecompressOnLoad)
     {
         m_outputNeedsIntialized = true;
         m_isOutputDirect        = true; //Cannot read streaming or compressed clip data
     }
     m_name         = clip.name;
     DirectClipData = new AudioClip[1] {
         clip
     };
     RawClipData = new RawAudioData[1] {
         AmbienceManager.GetAudioData(clip)
     };
     currentClipIdx = 0;
     if (m_sequence != null)
     {
         curPlaybackSpeed = m_sequence.PlaybackSpeed;
         curVolume        = m_sequence.Volume;
         for (int i = 0; i < m_sequence.Clips.Length; ++i)
         {
             if (m_sequence.Clips[i].m_clip == clip)
             {
                 curVolume *= m_sequence.Clips[i].m_volume;
                 break;
             }
         }
         if (MySyncGroup == null && m_sequence.TrackDelayTime > 0)
         {
             //Debug.Log("Starting AudioTrack with delay of " + source.TrackDelayTime);
             isDelaying = true;
         }
         if (m_sequence.RandomizeVolume)
         {
             curVolumeMod = Helpers.GetRandom(m_sequence.MinMaxVolume);
         }
         else
         {
             curVolumeMod = 1f;
         }
         if (!isSynced && m_sequence.RandomizePlaybackSpeed)
         {
             curPlaybackSpeedMod = Helpers.GetRandom(m_sequence.MinMaxPlaybackSpeed);
         }
         else
         {
             curPlaybackSpeedMod = 1f;
         }
     }
     else
     {
         curPlaybackSpeed    = 1f;
         curPlaybackSpeedMod = 1f;
         curVolume           = 1f;
         curVolumeMod        = 1f;
     }
 }
Exemplo n.º 27
0
 void StopMenuItem()
 {
     m_forcePlay = false;
     AmbienceManager.RemoveSequence(this);
 }
Exemplo n.º 28
0
        /// <summary> Displays a list of all Sequence assets in project </summary>
        /// <param name="inlineHelp">Should help be displayed?</param>
        void SequencesPanel(bool inlineHelp)
        {
            GUIStyle playButtonNormal;
            GUIStyle playButtonPressed;

            playButtonNormal         = EditorStyles.miniButtonLeft;
            playButtonPressed        = new GUIStyle(playButtonNormal);
            playButtonPressed.normal = playButtonNormal.active;
            GUIStyle muteButtonNormal;
            GUIStyle muteButtonPressed;

            muteButtonNormal         = EditorStyles.miniButtonRight;
            muteButtonPressed        = new GUIStyle(muteButtonNormal);
            muteButtonPressed.normal = muteButtonNormal.active;
            foreach (Sequence data in AllSequences)
            {
                EditorGUILayout.BeginHorizontal();
                Rect r = EditorGUILayout.GetControlRect();
                if (r.yMax > m_scrollPosition.y)
                {
                    if (Event.current.type == EventType.MouseDown && r.Contains(Event.current.mousePosition))
                    {
                        lastClickedOn = data;
                    }
                    else if (Event.current.type == EventType.MouseDrag && lastClickedOn == data && r.Contains(Event.current.mousePosition))
                    {
                        DragAndDrop.PrepareStartDrag();
                        DragAndDrop.objectReferences = new Object[] { data };
                        DragAndDrop.StartDrag("Sequence:" + data.name);
                        Event.current.Use();
                        weStartedDrag = true;
                    }
                    else if (Event.current.type == EventType.DragUpdated && r.Contains(Event.current.mousePosition))
                    {
                        bool found = false;
                        for (int o = 0; o < DragAndDrop.objectReferences.Length; ++o)
                        {
                            if (DragAndDrop.objectReferences[o] is AudioClip)
                            {
                                DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                                Event.current.Use();
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                            Event.current.Use();
                        }
                    }
                    else if (Event.current.type == EventType.DragPerform && r.Contains(Event.current.mousePosition))
                    {
                        List <Sequence.ClipData> clips = new List <Sequence.ClipData>(data.m_clipData);
                        bool foundOne = false;
                        for (int o = 0; o < DragAndDrop.objectReferences.Length; ++o)
                        {
                            if (DragAndDrop.objectReferences[o] is AudioClip)
                            {
                                foundOne = true;
                                clips.Add(DragAndDrop.objectReferences[o] as AudioClip);
                            }
                        }
                        if (foundOne)
                        {
                            data.m_clipData = clips.ToArray();
                        }
                    }
                    else if ((Event.current.type == EventType.DragExited || Event.current.type == EventType.MouseUp) && lastClickedOn == data && weStartedDrag)
                    {
                        weStartedDrag = false;
                        lastClickedOn = null;
                        DragAndDrop.PrepareStartDrag();
                    }
                }
                EditorGUI.ObjectField(r, data, typeof(Sequence), false);

                EditorGUI.BeginDisabledGroup(!Application.isPlaying);
                if (!Application.isPlaying || !AmbienceManager.WasSequenceAdded(data))
                {
                    if (m_editorUtils.Button(EditorGUIUtility.IconContent("PlayButton"), playButtonNormal, GUILayout.Height(EditorGUIUtility.singleLineHeight), GUILayout.ExpandWidth(false)))
                    {
                        data.m_forcePlay = true;
                        AmbienceManager.AddSequence(data);
                    }
                }
                else
                {
                    if (m_editorUtils.Button(EditorGUIUtility.IconContent("PlayButton On"), playButtonPressed, GUILayout.Height(EditorGUIUtility.singleLineHeight), GUILayout.ExpandWidth(false)))
                    {
                        data.m_forcePlay = false;
                        AmbienceManager.RemoveSequence(data);
                    }
                }

                Color    startColor  = GUI.color;
                GUIStyle buttonStyle = muteButtonNormal;
                if (data.m_forceMuted)
                {
                    GUI.color   = Color.red;
                    buttonStyle = muteButtonPressed;
                }
                if (m_editorUtils.Button(EditorGUIUtility.IconContent("preAudioAutoPlayOff"), buttonStyle, GUILayout.Height(EditorGUIUtility.singleLineHeight), GUILayout.ExpandWidth(false)))
                {
                    if (Event.current.button == 1)
                    {
                        data.m_forceMuted = false;
                        bool curMuted = true;
                        foreach (Sequence s in AllSequences)
                        {
                            if (s != null && s != data)
                            {
                                curMuted &= s.m_forceMuted;
                            }
                        }
                        foreach (Sequence s in AllSequences)
                        {
                            if (s != null && s != data)
                            {
                                s.m_forceMuted = !curMuted;
                            }
                        }
                    }
                    else
                    {
                        data.m_forceMuted = !data.m_forceMuted;
                    }
                }
                GUI.color = startColor;
                EditorGUI.EndDisabledGroup();
                EditorGUILayout.EndHorizontal();
            }
            ++EditorGUI.indentLevel;
            EditorGUILayout.BeginHorizontal();
            if (m_editorUtils.Button("SequenceCreateButton", GUILayout.ExpandWidth(false)))
            {
                GUIContent dialogContent = m_editorUtils.GetContent("SequenceCreateDialog");
                string     newPath       = EditorUtility.SaveFilePanelInProject(dialogContent.text, "Sequence", "asset", dialogContent.tooltip, newSequencePath);
                if (!string.IsNullOrEmpty(newPath))
                {
                    AssetDatabase.CreateAsset(CreateInstance <Sequence>(), newPath);
                    Sequence newSequence = AssetDatabase.LoadAssetAtPath <Sequence>(newPath);
                    Selection.activeInstanceID = newSequence.GetInstanceID();
                }
            }
            Rect buttonRect = GUILayoutUtility.GetLastRect();

            if (Event.current.type == EventType.DragUpdated && buttonRect.Contains(Event.current.mousePosition))
            {
                for (int o = 0; o < DragAndDrop.objectReferences.Length; ++o)
                {
                    if (DragAndDrop.objectReferences[o] is AudioClip)
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                        Event.current.Use();
                        break;
                    }
                }
            }
            else if (Event.current.type == EventType.DragPerform && buttonRect.Contains(Event.current.mousePosition))
            {
                List <Sequence.ClipData> clips = new List <Sequence.ClipData>();
                for (int o = 0; o < DragAndDrop.objectReferences.Length; ++o)
                {
                    if (DragAndDrop.objectReferences[o] is AudioClip)
                    {
                        clips.Add(DragAndDrop.objectReferences[o] as AudioClip);
                    }
                }
                if (clips.Count > 0)
                {
                    if (Event.current.control)   //create one for each
                    {
                        GUIContent dialogContent = m_editorUtils.GetContent("SequenceMultiCreateDialog");
                        string     saveFolder    = EditorUtility.SaveFolderPanel(dialogContent.text, "Assets", "Assets");
                        if (!string.IsNullOrEmpty(saveFolder))
                        {
                            if (saveFolder.StartsWith(Application.dataPath))
                            {
                                saveFolder = saveFolder.Substring(Application.dataPath.Length - 6);
                                if (!saveFolder.EndsWith("/"))
                                {
                                    saveFolder += "/";
                                }
                                foreach (Sequence.ClipData clip in clips)
                                {
                                    Sequence newSequence = CreateInstance <Sequence>();
                                    newSequence.m_clipData = new Sequence.ClipData[] { clip };
                                    AssetDatabase.CreateAsset(newSequence, saveFolder + clip.m_clip.name + ".asset");
                                }
                            }
                            else
                            {
                                GUIContent errorContent = m_editorUtils.GetContent("CreateWrongFolderError");
                                EditorUtility.DisplayDialog(errorContent.text, errorContent.tooltip, "Ok");
                            }
                        }
                    }
                    else     //stack all into one sequence
                    {
                        GUIContent dialogContent = m_editorUtils.GetContent("SequenceCreateDialog");
                        string     savePath      = EditorUtility.SaveFilePanelInProject(dialogContent.text, "Sequence", "asset", dialogContent.tooltip);
                        if (!string.IsNullOrEmpty(savePath))
                        {
                            Sequence newSequence = CreateInstance <Sequence>();
                            newSequence.m_clipData = clips.ToArray();
                            AssetDatabase.CreateAsset(newSequence, savePath);
                        }
                    }
                }
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            m_editorUtils.InlineHelp("SequenceCreateButton", inlineHelp);
            --EditorGUI.indentLevel;
        }