Exemple #1
0
    // LOTSA GAME LOGIC
    private void OnUserVariableUpdate(BaseEvent e)
    {
        List <string> changedVars = (List <string>)e.Params["changedVars"];

        SFSUser user = (SFSUser)e.Params["user"];

        if (user == sfs.MySelf)
        {
            return;
        }

        if (!remotePlayers.ContainsKey(user))
        {
            // New client just started transmitting - lets create remote player
            Vector3 pos = new Vector3(0, 0);
            if (user.ContainsVariable("x") && user.ContainsVariable("y"))
            {
                pos.x = (float)user.GetVariable("x").GetDoubleValue();
                pos.y = (float)user.GetVariable("y").GetDoubleValue();
            }

            SpawnRemotePlayer(user, pos);
        }

        // Check if the remote user changed position
        if (changedVars.Contains("x") && changedVars.Contains("y"))
        {
            // Move the character to a new position... (holy shit lol)
            remotePlayers[user].GetComponent <SimpleRemoteInterpolation>().SetTransform(
                new Vector3((float)user.GetVariable("x").GetDoubleValue(), (float)user.GetVariable("y").GetDoubleValue()), true);
        }
    }
Exemple #2
0
    public void OnUserVariableUpdate(BaseEvent evt)
    {
        //Debug.LogWarning("OnUserVariableUpdate");
        List <string> changedVars = (List <string>)evt.Params["changedVars"];
        SFSUser       user        = (SFSUser)evt.Params["user"];

        if (user == sfs.MySelf)
        {
            return;
        }
        if (!remotePlayers.ContainsKey(user))
        {
            // New client just started transmitting - lets create remote player
            Vector3 pos = new Vector3(0, 1, 0);
            if (user.ContainsVariable("x") && user.ContainsVariable("y") && user.ContainsVariable("z"))
            {
                pos.x = (float)user.GetVariable("x").GetDoubleValue();
                pos.y = (float)user.GetVariable("y").GetDoubleValue();
                pos.z = (float)user.GetVariable("z").GetDoubleValue();
            }
            float rotAngle = 0;
            if (user.ContainsVariable("rot"))
            {
                rotAngle = (float)user.GetVariable("rot").GetDoubleValue();
            }
            int numModel = 0;
            if (user.ContainsVariable("model"))
            {
                numModel = user.GetVariable("model").GetIntValue();
            }
            SpawnRemotePlayer(user, numModel, pos, Quaternion.Euler(0, rotAngle, 0));
        }
        // Check if the remote user changed his position or rotation
        if (changedVars.Contains("x") && changedVars.Contains("y") && changedVars.Contains("z") && changedVars.Contains("rot"))
        {
            // Move the character to a new position...
            remotePlayers[user].GetComponent <SimpleRemoteInterpolation>().SetTransform(
                new Vector3((float)user.GetVariable("x").GetDoubleValue(), (float)user.GetVariable("y").GetDoubleValue(), (float)user.GetVariable("z").GetDoubleValue()),
                Quaternion.Euler(0, (float)user.GetVariable("rot").GetDoubleValue(), 0),
                true);
        }
    }
Exemple #3
0
    private 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 == sfs.MySelf)
        {
            return;
        }
        if (!remotePlayers.ContainsKey(user))
        {
            Vector3 pos = new Vector3(0, 1, 0);
            if (user.ContainsVariable("x") && user.ContainsVariable("y"))
            {
                pos.x = (float)user.GetVariable("x").GetDoubleValue();
                pos.y = (float)user.GetVariable("y").GetDoubleValue();
            }
            float rotAngle = 0;
            if (user.ContainsVariable("rot"))
            {
                rotAngle = (float)user.GetVariable("rot").GetDoubleValue();
            }
            SpawnRemotePlayer(user, pos, Quaternion.Euler(0, rotAngle, 0));
        }
        if (changedVars.Contains("x") && changedVars.Contains("y") && changedVars.Contains("rot"))
        {
            remotePlayers[user].GetComponent <SimpleRemoteInterpolation>().SetTransform(
                new Vector3((float)user.GetVariable("x").GetDoubleValue(), (float)user.GetVariable("y").GetDoubleValue(), (float)0),
                Quaternion.Euler(0, 0, (float)user.GetVariable("rot").GetDoubleValue()), true);
        }


        if (changedVars.Contains("shot"))
        {
            remotePlayers[user].GetComponent <shoot>().Fire();
        }
    }
Exemple #4
0
 public void SetRemotePlayerModel(SFSUser user, int modelIndex)
 {
     if (user == CommunicationManager.MySelf)
     {
         return;
     }
     if (remotePlayers.ContainsKey(user))
     {
         PlayerType pType = PlayerType.NORMAL;
         Player     p;
         if (players.TryGetValue(user.Id, out p))
         {
             pType = p.Type;
         }
         Vector3    pos         = remotePlayers[user].transform.position;
         Quaternion rot         = remotePlayers[user].transform.rotation;
         string     displayName = (user.ContainsVariable("displayName")) ? user.GetVariable("displayName").GetStringValue() : user.Name;
         CreateRemotePlayer(user, modelIndex, pos, rot, user.GetVariable("op").GetStringValue(), user.GetVariable("parseId").GetStringValue(), displayName, user.GetVariable("team").GetIntValue(), pType, user.GetVariable("sit").GetBoolValue());
     }
 }
Exemple #5
0
    private void OnUserVariablesUpdate(BaseEvent evt)
    {
        List <string> changedVars = (List <string>)evt.Params["changedVars"];

        SFSUser user = (SFSUser)evt.Params["user"];

        if (user == sfs.MySelf)
        {
            return;
        }

        Vector3 pos   = Posplayer.position;
        int     index = 0;

        if (!remotePlayers.ContainsKey(user))
        {
            if (user.ContainsVariable("x") && user.ContainsVariable("y"))
            {
                pos.x = (float)user.GetVariable("x").GetDoubleValue();
                pos.y = (float)user.GetVariable("y").GetDoubleValue();
                pos.z = (float)user.GetVariable("z").GetDoubleValue();
            }

            if (user.ContainsVariable("index"))
            {
                index = (int)user.GetVariable("index").GetIntValue();
            }



            GameObject remotePlayer = GameObject.Instantiate(Players[index]) as GameObject;
            remotePlayer.AddComponent <SimpleRemoteInterpolation>();
            remotePlayer.GetComponent <SimpleRemoteInterpolation>().SetTransform(pos, Quaternion.identity, false);

            // Color and name


            // Lets track the dude
            remotePlayers.Add(user, remotePlayer);
        }


        if (changedVars.Contains("x") && changedVars.Contains("y") && changedVars.Contains("z"))
        {
            // Move the character to a new position...
            remotePlayers[user].GetComponent <SimpleRemoteInterpolation>().SetTransform(
                new Vector3((float)user.GetVariable("x").GetDoubleValue(), (float)user.GetVariable("y").GetDoubleValue(), (float)user.GetVariable("z").GetDoubleValue()),
                //Quaternion.Euler(0, (float)user.GetVariable("rot").GetDoubleValue(), 0),
                Quaternion.identity,
                true);
        }

        //if (changedVars.Contains("x_Health") && changedVars.Contains("y_Health") && changedVars.Contains("z_Health"))
        //{
        //    remotePlayers[user].transform.GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetComponent<SimpleRemoteInterpolation>().SetTransform(
        //        new Vector3((float)user.GetVariable("x_Health").GetDoubleValue(), (float)user.GetVariable("y_Health").GetDoubleValue(),
        //        (float)user.GetVariable("z_Health").GetDoubleValue()), Quaternion.identity, true);
        //}
        //if(user.ContainsVariable("index"))
        //{
        //    Debug.Log(" Gia tri Index:" + user.GetVariable("index").GetIntValue());
        //}
    }