Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- * Adventure Creator
- * by Chris Burton, 2013-2018
- *
- * "ActionSound.cs"
- *
- * This action triggers the sound component of any GameObject, overriding that object's play settings.
- *
- */
- using UnityEngine;
- using System.Collections.Generic;
- #if UNITY_EDITOR
- using UnityEditor;
- #endif
- namespace AC
- {
- [System.Serializable]
- public class ActionMusicVolume : Action
- {
- private static float originalVolume = 1f;
- public bool setTrueVolume;
- public float volumeAdjustment;
- public float transition;
- public bool isInstant;
- public bool undoLastAdjustment;
- public ActionMusicVolume()
- {
- this.isDisplayed = true;
- category = ActionCategory.Sound;
- title = "Music Volume";
- description = "Blends music volume to a new loudness";
- }
- override public float Run ()
- {
- if( isInstant)
- {
- KickStarter.options.SetVolume(SoundType.Music, volumeAdjustment);
- return 0f;
- }
- originalVolume = Options.optionsData.musicVolume;
- float target = originalVolume * volumeAdjustment;
- if (undoLastAdjustment)
- target = originalVolume;
- EnvironmentManager.Instance.StartCoroutine( CoroutineUtils.DoInterpolation(transition, f =>
- {
- float newVol = Mathf.Lerp(originalVolume, target, f);
- KickStarter.options.SetVolume(SoundType.Music, newVol);
- Debug.Log(newVol);
- return true;
- }));
- return transition;
- }
- #if UNITY_EDITOR
- override public void ShowGUI (List<ActionParameter> parameters)
- {
- setTrueVolume = EditorGUILayout.Toggle("Is true volume change?", setTrueVolume);
- undoLastAdjustment = EditorGUILayout.Toggle("Undo Last Adjustment", undoLastAdjustment);
- if( !undoLastAdjustment)
- {
- volumeAdjustment = EditorGUILayout.FloatField(setTrueVolume ? "New volume" : "Relative Volume", volumeAdjustment);
- }
- transition = EditorGUILayout.FloatField("Transition", transition);
- isInstant = EditorGUILayout.Toggle("Is Instant?", isInstant);
- AfterRunningOption ();
- }
- override public string SetLabel ()
- {
- return string.Format("( Adjust volume - {0})", volumeAdjustment);
- }
- #endif
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment