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. 19
      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.

19
Assets/FungusExample/Scripts/SpritesRoom.cs

@ -40,20 +40,19 @@ public class SpritesRoom : Room
Say("Never mind, you'll feel better soon!");
}
void OnAnimationEvent(string eventName)
// 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()
{
if (eventName == "GreenAnimationFinished")
{
SetAnimatorTrigger(blueAlienAnim, "Stop");
SetAnimatorTrigger(blueAlienAnim, "Stop");
Say("Well done Blue Alien! Time to say goodbye!");
Say("Well done Blue Alien! Time to say goodbye!");
FadeSprite(blueAlienSprite, 0, 1f);
Wait(1f);
FadeSprite(blueAlienSprite, 0, 1f);
Wait(1f);
Say("Heh. That Blue Alien - what a guy!");
Say("Heh. That Blue Alien - what a guy!");
MoveToRoom(menuRoom);
}
MoveToRoom(menuRoom);
}
}

Loading…
Cancel
Save