Page 1 of 1

Animation Synchronizer with SFS[Unity3d]

Posted: 30 Dec 2009, 14:46
by djoscar
hello guys

I know this is probably a "nooby" question, but I haven't worked that much with networking before so I find it a bit difficult to understand.

Here's an AnimationSynchronizer script that was included with Unity3d SFS island demo:

Code: Select all

using UnityEngine;
using System.Collections;
using System;

using SmartFoxClientAPI;
using SmartFoxClientAPI.Data;

public class AnimationSynchronizer : MonoBehaviour {
   private bool sendMode = false;
   private bool receiveMode = false;
   private string lastState = "idle111";
   // We call it on local player to start sending animation messages
   void StartSending() {
      sendMode = true;
      receiveMode = false;      
   // We call it on remote player model to start receiving animation messages
   void StartReceiving() {
      sendMode = false;
      receiveMode = true;

   void PlayAnimation(string message) {
      if (sendMode) {
         //if the new state differs, send animation message to other clients
         if (lastState!=message) {
            lastState = message;
      else if (receiveMode) {
         // Just play this animation
   void SendAnimationMessage(string message) {
      SmartFoxClient client = NetworkController.GetClient();
      SFSObject data = new SFSObject();
      data.Put("_cmd", "a");  //We put _cmd = "a" here to know that this object contains animation message
      data.Put("mes", message);

Now I want to add more animations, for e.g. punch animation when player clicks mouse button or jump animation when player presses Space.

How do I do that? Could anyone please give me a very basic example of how to add more animations to this Animation Synchronizer script?

It's really unclear how to do that in the island demo, so I'm seeking for a simplest example of what to add to this script for example for "jump" animation to be played when Space is pressed.
(I know how to do it for local player but not for remote >.<)

Thanks in advance.

Posted: 30 Dec 2009, 20:36
by djoscar
bump. please somebody :)

Posted: 03 Jan 2010, 21:08
by ThomasLund
Hey hey

I'm fresh back from vacation. I'm semi-unsure how to answer your question.

Basically this animation synchronizer simply takes any animation name as argument and plays it on remote avatars.

Simply call PlayAnimation(XXX); where XXX is the name of the animation top sync - e.g. "jump", and the remote avatar will then perform the "jump" animation.

No changes to the script are needed to add anything