Browse Source

Added sound commands. Improved command buttons.

master
chrisgregan 11 years ago
parent
commit
06e14afb8c
  1. 34
      Assets/Fungus/Audio/Scripts/PlayMusic.cs
  2. 8
      Assets/Fungus/Audio/Scripts/PlayMusic.cs.meta
  3. 37
      Assets/Fungus/Audio/Scripts/PlaySound.cs
  4. 8
      Assets/Fungus/Audio/Scripts/PlaySound.cs.meta
  5. 33
      Assets/Fungus/Audio/Scripts/SetMusicVolume.cs
  6. 8
      Assets/Fungus/Audio/Scripts/SetMusicVolume.cs.meta
  7. 22
      Assets/Fungus/Audio/Scripts/StopMusic.cs
  8. 8
      Assets/Fungus/Audio/Scripts/StopMusic.cs.meta
  9. 60
      Assets/Fungus/FungusScript/Editor/FungusCommandEditor.cs
  10. 17
      Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs
  11. 12
      Assets/Fungus/FungusScript/Scripts/FungusCommand.cs

34
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;
}
}
}

8
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:

37
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;
}
}
}

8
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:

33
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.";
}
}
}

8
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:

22
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();
}
}
}

8
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:

60
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);
}
}

17
Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs

@ -196,7 +196,7 @@ namespace Fungus.Script
List<string> commandNames = new List<string>();
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;
}
}
}

12
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 "";

Loading…
Cancel
Save