/** * When user variable is updated on any client within the AoI, then this event is received. * This is where most of the game logic for this example is contained. */ public void OnUserVariableUpdate(BaseEvent evt) { #if UNITY_WSA && !UNITY_EDITOR List <string> changedVars = (List <string>)evt.Params["changedVars"]; #else ArrayList changedVars = (ArrayList)evt.Params["changedVars"]; #endif SFSUser user = (SFSUser)evt.Params["user"]; if (user == smartFox.MySelf) //spwanLocalPlayer { if (localPlayer == null) { NetworkTransform transform = NetworkTransform.FromUserVariables((float)user.GetVariable("x").GetDoubleValue(), 5.36f, (float)user.GetVariable("z").GetDoubleValue(), 0, (float)user.GetVariable("r").GetDoubleValue(), 0, Convert.ToDouble(user.GetVariable("t").Value)); SpawnLocalPlayer(Convert.ToInt16(user.GetVariable("g").Value), transform); } return; } if (recipients.ContainsKey(user.Id)) { // Check if the remote user changed his position or rotation if (changedVars.Contains("x") || changedVars.Contains("z") || changedVars.Contains("r")) { // Move the character to a new position... NetworkTransform transform = NetworkTransform.FromUserVariables((float)user.GetVariable("x").GetDoubleValue(), 5.36f, (float)user.GetVariable("z").GetDoubleValue(), 0, (float)user.GetVariable("r").GetDoubleValue(), 0, Convert.ToDouble(user.GetVariable("t").Value)); NetworkTransformReceiver recipent = recipients [user.Id]; if (recipent != null) { recipent.ReceiveTransform(transform); } } // Remote client selected new model? if (changedVars.Contains("model")) { SpawnRemotePlayer(user, user.GetVariable("model").GetIntValue(), remotePlayers[user.Id].transform.position, remotePlayers[user.Id].transform.localEulerAngles); } } }