Browse Source

Animation Event Listener now uses the event string parameter to call a room method with the same name.

master
chrisgregan 11 years ago
parent
commit
ab4207ef84
  1. 6
      Assets/Fungus/Scripts/AnimationEventListener.cs
  2. 6
      Assets/Fungus/Scripts/Room.cs
  3. BIN
      Assets/FungusExample/Animations/GreenAlienWalk.anim
  4. 7
      Assets/FungusExample/Scripts/SpritesRoom.cs

6
Assets/Fungus/Scripts/AnimationEventListener.cs

@ -2,9 +2,11 @@
using System.Collections;
using Fungus;
// Listens for animation events
// The string parameter specifies a method name on the active room class
public class AnimationEventListener : MonoBehaviour
{
void OnAnimationEvent(string eventName)
void OnAnimationEvent(string methodName)
{
Room room = Game.GetInstance().activeRoom;
if (room == null)
@ -12,6 +14,6 @@ public class AnimationEventListener : MonoBehaviour
return;
}
room.AnimationEvent(eventName);
room.AnimationEvent(methodName);
}
}

6
Assets/Fungus/Scripts/Room.cs

@ -149,11 +149,9 @@ namespace Fungus
}
// Internal use only! Called by AnimationEventListener
public void AnimationEvent(string eventName)
public void AnimationEvent(string methodName)
{
commandQueue.Reset();
SendMessage("OnAnimationEvent", eventName, SendMessageOptions.DontRequireReceiver);
commandQueue.Execute();
ExecuteCommandMethod(methodName);
}
// Internal use only!

BIN
Assets/FungusExample/Animations/GreenAlienWalk.anim

Binary file not shown.

7
Assets/FungusExample/Scripts/SpritesRoom.cs

@ -40,9 +40,9 @@ public class SpritesRoom : Room
Say("Never mind, you'll feel better soon!");
}
void OnAnimationEvent(string eventName)
{
if (eventName == "GreenAnimationFinished")
// This method is called by the Animation Event Listener component on the blue alien.
// When the GreenAlienWalk animation finishes it fires an event which calls this method.
void AlienAnimationFinished()
{
SetAnimatorTrigger(blueAlienAnim, "Stop");
@ -55,5 +55,4 @@ public class SpritesRoom : Room
MoveToRoom(menuRoom);
}
}
}

Loading…
Cancel
Save