Example #1
0
    public void UpdateHealthForEnemy(int id, int health)
    {
        NetworkTransformReceiver rec = GetRecipient(id);

        rec.GetComponent <Enemy>().UpdateHealth(health);

        BloodEffect(rec.transform);
    }
Example #2
0
    public void DestroyEnemy(int id)
    {
        NetworkTransformReceiver rec = GetRecipient(id);

        if (rec == null)
        {
            return;
        }
        Destroy(rec.gameObject);
        recipients.Remove(id);
    }
Example #3
0
    // 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);
            }
        }
    }
Example #4
0
    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);
        }
    }
Example #5
0
    /**
     * 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);
            }
        }
    }
Example #6
0
    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);
    }