public void UpdateHealthForEnemy(int id, int health) { NetworkTransformReceiver rec = GetRecipient(id); rec.GetComponent <Enemy>().UpdateHealth(health); BloodEffect(rec.transform); }
public void DestroyEnemy(int id) { NetworkTransformReceiver rec = GetRecipient(id); if (rec == null) { return; } Destroy(rec.gameObject); recipients.Remove(id); }
// Updating transform of the remote player from server private void HandleTransform(ISFSObject dt) { int userId = dt.GetInt("id"); NetworkTransform ntransform = NetworkTransform.FromSFSObject(dt); if (userId != smartFox.MySelf.Id) { // Update transform of the remote user object NetworkTransformReceiver recipient = PlayerManager.Instance.GetRecipient(userId); if (recipient != null) { recipient.ReceiveTransform(ntransform); } } }
public void SyncAnimation(int id, string msg, int layer) { NetworkTransformReceiver rec = GetRecipient(id); if (rec == null) { return; } if (layer == 0) { rec.GetComponent <AnimationSynchronizer>().RemoteStateUpdate(msg); } else if (layer == 1) { rec.GetComponent <AnimationSynchronizer>().RemoteSecondStateUpdate(msg); } }
/** * 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); } } }
public void KillEnemy(int id) { NetworkTransformReceiver rec = GetRecipient(id); if (rec == null) { return; } GameObject obj = rec.gameObject; BloodEffect(obj.transform); GameObject hero = obj.transform.Find("Hero").gameObject; hero.transform.parent = null; Destroy(obj); hero.transform.Rotate(Vector3.right * 90); hero.GetComponent <Animation>().Stop(); Destroy(hero, 10); recipients.Remove(id); }