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 System.Collections;
using Fungus; using Fungus;
// Listens for animation events
// The string parameter specifies a method name on the active room class
public class AnimationEventListener : MonoBehaviour public class AnimationEventListener : MonoBehaviour
{ {
void OnAnimationEvent(string eventName) void OnAnimationEvent(string methodName)
{ {
Room room = Game.GetInstance().activeRoom; Room room = Game.GetInstance().activeRoom;
if (room == null) if (room == null)
@ -12,6 +14,6 @@ public class AnimationEventListener : MonoBehaviour
return; 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 // Internal use only! Called by AnimationEventListener
public void AnimationEvent(string eventName) public void AnimationEvent(string methodName)
{ {
commandQueue.Reset(); ExecuteCommandMethod(methodName);
SendMessage("OnAnimationEvent", eventName, SendMessageOptions.DontRequireReceiver);
commandQueue.Execute();
} }
// Internal use only! // 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!"); 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.
if (eventName == "GreenAnimationFinished") void AlienAnimationFinished()
{ {
SetAnimatorTrigger(blueAlienAnim, "Stop"); SetAnimatorTrigger(blueAlienAnim, "Stop");
@ -56,4 +56,3 @@ public class SpritesRoom : Room
MoveToRoom(menuRoom); MoveToRoom(menuRoom);
} }
} }
}

Loading…
Cancel
Save