Animation Synchronizer with SFS[Unity3d]

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

djoscar
Posts: 4
Joined: 24 Dec 2009, 16:36

Animation Synchronizer with SFS[Unity3d]

Postby djoscar » 30 Dec 2009, 14:46

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;
      animation.Play(lastState);
   }

   
   void PlayAnimation(string message) {
      if (sendMode) {
         //if the new state differs, send animation message to other clients
         if (lastState!=message) {
            lastState = message;
            SendAnimationMessage(message);
         }         
      }
      else if (receiveMode) {
         // Just play this animation
         animation.CrossFade(message);   
      }
   }   
   
   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);
      client.SendObject(data);
   }
}

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.
djoscar
Posts: 4
Joined: 24 Dec 2009, 16:36

Postby djoscar » 30 Dec 2009, 20:36

bump. please somebody :)
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 03 Jan 2010, 21:08

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

/Thomas

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 6 guests