Guest User

Untitled

a guest
Oct 22nd, 2018
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. /*
  2. *
  3. * Adventure Creator
  4. * by Chris Burton, 2013-2018
  5. *
  6. * "ActionSound.cs"
  7. *
  8. * This action triggers the sound component of any GameObject, overriding that object's play settings.
  9. *
  10. */
  11.  
  12. using UnityEngine;
  13. using System.Collections.Generic;
  14.  
  15. #if UNITY_EDITOR
  16. using UnityEditor;
  17. #endif
  18.  
  19. namespace AC
  20. {
  21.  
  22. [System.Serializable]
  23. public class ActionMusicVolume : Action
  24. {
  25. private static float originalVolume = 1f;
  26. public bool setTrueVolume;
  27. public float volumeAdjustment;
  28. public float transition;
  29. public bool isInstant;
  30. public bool undoLastAdjustment;
  31.  
  32.  
  33. public ActionMusicVolume()
  34. {
  35. this.isDisplayed = true;
  36. category = ActionCategory.Sound;
  37. title = "Music Volume";
  38. description = "Blends music volume to a new loudness";
  39. }
  40.  
  41. override public float Run ()
  42. {
  43. if( isInstant)
  44. {
  45. KickStarter.options.SetVolume(SoundType.Music, volumeAdjustment);
  46. return 0f;
  47. }
  48.  
  49. originalVolume = Options.optionsData.musicVolume;
  50. float target = originalVolume * volumeAdjustment;
  51. if (undoLastAdjustment)
  52. target = originalVolume;
  53.  
  54. EnvironmentManager.Instance.StartCoroutine( CoroutineUtils.DoInterpolation(transition, f =>
  55. {
  56. float newVol = Mathf.Lerp(originalVolume, target, f);
  57. KickStarter.options.SetVolume(SoundType.Music, newVol);
  58. Debug.Log(newVol);
  59. return true;
  60. }));
  61. return transition;
  62. }
  63.  
  64.  
  65. #if UNITY_EDITOR
  66.  
  67. override public void ShowGUI (List<ActionParameter> parameters)
  68. {
  69. setTrueVolume = EditorGUILayout.Toggle("Is true volume change?", setTrueVolume);
  70. undoLastAdjustment = EditorGUILayout.Toggle("Undo Last Adjustment", undoLastAdjustment);
  71. if( !undoLastAdjustment)
  72. {
  73. volumeAdjustment = EditorGUILayout.FloatField(setTrueVolume ? "New volume" : "Relative Volume", volumeAdjustment);
  74. }
  75. transition = EditorGUILayout.FloatField("Transition", transition);
  76. isInstant = EditorGUILayout.Toggle("Is Instant?", isInstant);
  77.  
  78. AfterRunningOption ();
  79. }
  80.  
  81. override public string SetLabel ()
  82. {
  83.  
  84. return string.Format("( Adjust volume - {0})", volumeAdjustment);
  85. }
  86.  
  87. #endif
  88.  
  89. }
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment