diff --git a/Assets/Fungus/Audio/Scripts/PlayMusic.cs b/Assets/Fungus/Audio/Scripts/PlayMusic.cs new file mode 100644 index 00000000..da7ca3c0 --- /dev/null +++ b/Assets/Fungus/Audio/Scripts/PlayMusic.cs @@ -0,0 +1,34 @@ +using UnityEngine; +using System.Collections; + +namespace Fungus.Script +{ + [CommandName("Play Music")] + [HelpText("Plays game music. If any game music is already playing, it is stopped. Music continues playing across scene loads.")] + public class PlayMusic : FungusCommand + { + public AudioClip musicClip; + + public override void OnEnter() + { + MusicController musicController = MusicController.GetInstance(); + if (musicController != null) + { + musicController.PlayMusic(musicClip); + } + + Continue(); + } + + public override string GetSummary() + { + if (musicClip == null) + { + return "No music clip selected"; + } + + return musicClip.name; + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/Audio/Scripts/PlayMusic.cs.meta b/Assets/Fungus/Audio/Scripts/PlayMusic.cs.meta new file mode 100644 index 00000000..d8381fe7 --- /dev/null +++ b/Assets/Fungus/Audio/Scripts/PlayMusic.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1902400ccc99b45d69ad01cb86b57d0f +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Fungus/Audio/Scripts/PlaySound.cs b/Assets/Fungus/Audio/Scripts/PlaySound.cs new file mode 100644 index 00000000..7f90166c --- /dev/null +++ b/Assets/Fungus/Audio/Scripts/PlaySound.cs @@ -0,0 +1,37 @@ +using UnityEngine; +using System.Collections; + +namespace Fungus.Script +{ + [CommandName("Play Sound")] + [HelpText("Plays a sound effect. Multiple sound effects can play at the same time.")] + public class PlaySound : FungusCommand + { + public AudioClip soundClip; + + [Range(0,1)] + public float volume = 1; + + public override void OnEnter() + { + MusicController musicController = MusicController.GetInstance(); + if (musicController != null) + { + musicController.PlaySound(soundClip, volume); + } + + Continue(); + } + + public override string GetSummary() + { + if (soundClip == null) + { + return "No sound clip selected"; + } + + return soundClip.name; + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/Audio/Scripts/PlaySound.cs.meta b/Assets/Fungus/Audio/Scripts/PlaySound.cs.meta new file mode 100644 index 00000000..7070dcd7 --- /dev/null +++ b/Assets/Fungus/Audio/Scripts/PlaySound.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bd2f6be51b3d7490ba5633ee095d0391 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Fungus/Audio/Scripts/SetMusicVolume.cs b/Assets/Fungus/Audio/Scripts/SetMusicVolume.cs new file mode 100644 index 00000000..b02e85d9 --- /dev/null +++ b/Assets/Fungus/Audio/Scripts/SetMusicVolume.cs @@ -0,0 +1,33 @@ +using UnityEngine; +using System.Collections; + +namespace Fungus.Script +{ + [CommandName("Set Music Volume")] + [HelpText("Sets the game music volume level.")] + public class SetMusicVolume : FungusCommand + { + [Range(0,1)] + public float volume = 1; + + [Range(0,30)] + public float fadeDuration; + + public override void OnEnter() + { + MusicController musicController = MusicController.GetInstance(); + if (musicController != null) + { + musicController.SetMusicVolume(volume, fadeDuration); + } + + Continue(); + } + + public override string GetSummary() + { + return "Set to " + volume + " over " + fadeDuration + " seconds."; + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/Audio/Scripts/SetMusicVolume.cs.meta b/Assets/Fungus/Audio/Scripts/SetMusicVolume.cs.meta new file mode 100644 index 00000000..6b742183 --- /dev/null +++ b/Assets/Fungus/Audio/Scripts/SetMusicVolume.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e5f62b7b5779c46aba13ef24141b2729 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Fungus/Audio/Scripts/StopMusic.cs b/Assets/Fungus/Audio/Scripts/StopMusic.cs new file mode 100644 index 00000000..062c25cf --- /dev/null +++ b/Assets/Fungus/Audio/Scripts/StopMusic.cs @@ -0,0 +1,22 @@ +using UnityEngine; +using System.Collections; + +namespace Fungus.Script +{ + [CommandName("Stop Music")] + [HelpText("Stops the currently playing game music.")] + public class StopMusic : FungusCommand + { + public override void OnEnter() + { + MusicController musicController = MusicController.GetInstance(); + if (musicController != null) + { + musicController.StopMusic(); + } + + Continue(); + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/Audio/Scripts/StopMusic.cs.meta b/Assets/Fungus/Audio/Scripts/StopMusic.cs.meta new file mode 100644 index 00000000..93822f1a --- /dev/null +++ b/Assets/Fungus/Audio/Scripts/StopMusic.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b359b09a7ba2e4af981f07c07f8af85a +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs b/Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs index 5df5d869..01f8252a 100644 --- a/Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs @@ -34,33 +34,33 @@ namespace Fungus.Script GUILayout.BeginHorizontal(); - string commandLabel = commandIndex.ToString() + " " + t.GetType().Name; - - bool expanded = EditorGUILayout.Foldout(t.expanded, commandLabel); - - if (expanded != t.expanded) + if (t.expanded) { - Undo.RecordObject(t, "Set Expanded"); - t.expanded = expanded; + GUI.backgroundColor = Color.yellow; } - GUIStyle labelStyle = EditorStyles.miniLabel; - labelStyle.wordWrap = true; - string summary = t.GetSummary().Replace("\n", "").Replace("\r", ""); - if (summary.Length > 80) + string commandName = FungusScriptEditor.GetCommandName(t.GetType()); + if (GUILayout.Button(commandName, EditorStyles.miniButton)) { - summary = summary.Substring(0, 80) + "..."; + Undo.RecordObject(t, "Toggle Expanded"); + t.expanded = !t.expanded; } - GUILayout.Label(summary, labelStyle); - - GUILayout.FlexibleSpace(); - - GUILayout.EndHorizontal(); + GUI.backgroundColor = Color.white; - if (t.expanded) + if (!t.expanded) + { + GUIStyle labelStyle = EditorStyles.miniLabel; + labelStyle.wordWrap = true; + string summary = t.GetSummary().Replace("\n", "").Replace("\r", ""); + if (summary.Length > 80) + { + summary = summary.Substring(0, 80) + "..."; + } + GUILayout.Label(summary, labelStyle); + GUILayout.FlexibleSpace(); + } + else { - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); if (GUILayout.Button("Up", EditorStyles.miniButtonLeft)) @@ -95,25 +95,23 @@ namespace Fungus.Script Undo.DestroyObjectImmediate(t); return; } + } - GUILayout.FlexibleSpace(); - - GUILayout.EndHorizontal(); + GUILayout.EndHorizontal(); - EditorGUILayout.Separator(); + if (t.expanded) + { + //EditorGUILayout.Separator(); DrawCommandGUI(); EditorGUILayout.Separator(); - if (t != null) + if (t.errorMessage.Length > 0) { - if (t.errorMessage.Length > 0) - { - GUIStyle style = new GUIStyle(GUI.skin.label); - style.normal.textColor = new Color(1,0,0); - EditorGUILayout.LabelField(new GUIContent("Error: " + t.errorMessage), style); - } + GUIStyle style = new GUIStyle(GUI.skin.label); + style.normal.textColor = new Color(1,0,0); + EditorGUILayout.LabelField(new GUIContent("Error: " + t.errorMessage), style); } } diff --git a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs index 4df393c5..98f5379a 100644 --- a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs @@ -196,7 +196,7 @@ namespace Fungus.Script List commandNames = new List(); foreach(System.Type type in commandTypes) { - commandNames.Add(type.Name); + commandNames.Add(GetCommandName(type)); } EditorGUI.BeginChangeCheck(); @@ -283,6 +283,21 @@ namespace Fungus.Script variable.key = fungusScript.GetUniqueVariableKey(""); fungusScript.variables.Add(variable); } + + public static string GetCommandName(System.Type commandType) + { + object[] attributes = commandType.GetCustomAttributes(typeof(CommandNameAttribute), false); + foreach (object obj in attributes) + { + CommandNameAttribute commandNameAttr = obj as CommandNameAttribute; + if (commandNameAttr != null) + { + return commandNameAttr.CommandName; + } + } + + return commandType.Name; + } } } \ No newline at end of file diff --git a/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs b/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs index db0c4538..c3e73774 100644 --- a/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs +++ b/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs @@ -8,6 +8,16 @@ using System.Collections.Generic; namespace Fungus.Script { + public class CommandNameAttribute : Attribute + { + public CommandNameAttribute(string commandName) + { + this.CommandName = commandName; + } + + public string CommandName { get; set; } + } + public class HelpTextAttribute : Attribute { public HelpTextAttribute(string helpText) @@ -103,7 +113,7 @@ namespace Fungus.Script { return false; } - + public virtual string GetSummary() { return "";