void CreateRemotePlayer(SFSUser user,Vector3 vector)
 {
     GameObject player = Instantiate (playerPrefab) as GameObject;
     player.transform.position = vector;
     remotePlayers.Add (user, player);
     player.GetComponent<PlayerSetup> ().Setup (sfs.UserManager.SmartFoxClient,user);
 }
    public void Setup(SmartFox client , SFSUser user)
    {
        if (!user.IsItMe) {
            mobileStickController.enabled = false;
            userControllder2D.enabled = false;

        }
    }
Example #3
0
    public void OnObjectMessage(BaseEvent evt)
    {
        Debug.LogWarning("OnObjectMessage");
        ISFSObject dataObj = (SFSObject)evt.Params["message"];
        SFSUser    sender  = (SFSUser)evt.Params["sender"];

        if (dataObj.ContainsKey("cmd"))
        {
            switch (dataObj.GetUtfString("cmd"))
            {
            case "rm":
                Debug.Log("Removing player unit " + sender.Id);
                RemoveRemotePlayer(sender);
                break;
            }
        }
    }
Example #4
0
    public void OnObjectMessage(BaseEvent evt)
    {
        // The only messages being sent around are remove messages from users that are leaving the game
        ISFSObject dataObj = (SFSObject)evt.Params["message"];
        SFSUser    sender  = (SFSUser)evt.Params["sender"];

        if (dataObj.ContainsKey("cmd"))
        {
            switch (dataObj.GetUtfString("cmd"))
            {
            case "rm":
                Debug.Log("Removing player unit " + sender.Id);
                RemoveRemotePlayer(sender);
                break;
            }
        }
    }
Example #5
0
    private void RemoveRemotePlayer(SFSUser user)
    {
        if (user == smartFox.MySelf)
        {
            return;
        }

        if (remotePlayers.ContainsKey(user.Id))
        {
            Destroy(remotePlayers[user.Id]);
            remotePlayers.Remove(user.Id);
        }
        if (recipients.ContainsKey(user.Id) && recipients[user.Id] != null)
        {
            Destroy(recipients[user.Id]);
            recipients.Remove(user.Id);
        }
    }
Example #6
0
    public void RemoveRemotePlayer(SFSUser user)
    {
        if (user == CommunicationManager.MySelf)
        {
            return;
        }

        if (remotePlayers.ContainsKey(user))
        {
            Destroy(remotePlayers[user]);
            remotePlayers.Remove(user);
            string cmd = "removeFromUserList({name:\"" + players[user.Id].Name + "\",userid:\"" + players[user.Id].ParseId + "\"});";
            players.Remove(user.Id);
            if (GameGUI.Inst.guiLayer != null)
            {
                GameGUI.Inst.guiLayer.ExecuteJavascriptWithValue(cmd);
            }
        }
    }
Example #7
0
    private void SpawnRemotePlayer(SFSUser user, Vector3 pos)
    {
        // see if already exists so we can destroy first
        // ???
        if (remotePlayers.ContainsKey(user) && remotePlayers[user] != null)
        {
            Destroy(remotePlayers[user]);
            remotePlayers.Remove(user);
        }

        // Lets spawn our remote player model
        GameObject remotePlayer = GameObject.Instantiate(playerObject) as GameObject;

        remotePlayer.AddComponent <SimpleRemoteInterpolation>();
        remotePlayer.GetComponent <SimpleRemoteInterpolation>().SetTransform(pos, false);

        // Lets track the dude
        remotePlayers.Add(user, remotePlayer);
    }
Example #8
0
    private void SpawnRemotePlayer(SFSUser user, int numModel, Vector3 pos, Quaternion rot)
    {
        Debug.LogWarning("SpawnRemotePlayer");
        // See if there already exists a model so we can destroy it first
        if (remotePlayers.ContainsKey(user) && remotePlayers[user] != null)
        {
            Destroy(remotePlayers[user]);
            remotePlayers.Remove(user);
        }

        // Lets spawn our remote player model
        GameObject remotePlayer = GameObject.Instantiate(playerModels[numModel]) as GameObject;

        remotePlayer.AddComponent <SimpleRemoteInterpolation>();
        remotePlayer.GetComponent <SimpleRemoteInterpolation>().SetTransform(pos, rot, false);

        // Lets track the dude
        remotePlayers.Add(user, remotePlayer);
    }
Example #9
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);
        }
    }
Example #10
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)
    {
        List <string> changedVars = (List <string>)evt.Params["changedVars"];

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

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

        changedVars.Contains("x");
        changedVars.Contains("y");
        changedVars.Contains("z");
        changedVars.Contains("rot");

        // Check if the remote user changed his position or rotation
        if (changedVars.Contains("x") || changedVars.Contains("y") || changedVars.Contains("z") || changedVars.Contains("rot"))
        {
            if (remotePlayers.ContainsKey(user))
            {
                // Move the character to a new position...
                remotePlayers[user].GetComponent <SimpleRemoteInterpolation>().SetTransform(
                    new Vector3((float)user.GetVariable("x").GetDoubleValue(), 1, (float)user.GetVariable("z").GetDoubleValue()),
                    Quaternion.Euler(0, (float)user.GetVariable("rot").GetDoubleValue(), 0),
                    true
                    );
            }
        }

        // Remote client selected new model?
        if (changedVars.Contains("model"))
        {
            SpawnRemotePlayer(user, user.GetVariable("model").GetIntValue(), user.GetVariable("mat").GetIntValue(), remotePlayers[user].transform.position, remotePlayers[user].transform.rotation);
        }

        // Remote client selected new material?
        if (changedVars.Contains("mat"))
        {
            remotePlayers[user].GetComponentInChildren <Renderer>().material = playerMaterials[user.GetVariable("mat").GetIntValue()];
        }
    }
Example #11
0
    private void UserEnterRoom(SFSUser user)
    {
        ISFSArray pos = user.GetVariable("pos").GetSFSArrayValue();
        ISFSArray ori = user.GetVariable("ori").GetSFSArrayValue();

        GameObject playerGo = Instantiate(playerPrefab,
                                          new Vector3(pos.GetFloat(0), pos.GetFloat(1) - 1.0f, pos.GetFloat(2)),
                                          new Quaternion(ori.GetFloat(0), ori.GetFloat(2), ori.GetFloat(2), ori.GetFloat(3)))
                              as GameObject;

        //playerGo.AddComponent<PlayerInput>();
        playerGo.AddComponent <PlayerInterpolation>();

        playerGo.GetComponent <Animator>().runtimeAnimatorController = animatorController;

        user.Properties.Add("GameObject", playerGo);
        users.Add(user.Id, user);

        //chaserCamera.target = playerGo.transform;
    }
Example #12
0
    //----------------------------------------------------------
    // Private player helper methods
    //----------------------------------------------------------
    private void SpawnRemotePlayer(SFSUser user, int numModel, Vector3 pos, Vector3 rot)
    {
        // See if there already exists a model so we can destroy it first
        if (remotePlayers.ContainsKey(user.Id) && remotePlayers[user.Id] != null)
        {
            Destroy(remotePlayers[user.Id]);
            remotePlayers.Remove(user.Id);
        }
        // Lets spawn our remote player model
        GameObject remotePlayer = GameObject.Instantiate(playerModels[1]) as GameObject;

        remotePlayer.transform.position         = pos;
        remotePlayer.transform.localEulerAngles = rot;
        Debug.Log("inside spwan remote player");
        remotePlayer.AddComponent <NetworkTransformInterpolation>();
        remotePlayer.AddComponent <NetworkTransformReceiver>();

        recipients.Add(user.Id, remotePlayer.GetComponent <NetworkTransformReceiver> ());
        remotePlayers.Add(user.Id, remotePlayer);
    }
Example #13
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());
     }
 }
Example #14
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);
            }
        }
    }
    /// <summary>
    /// This is called by Smartfox when the mmo api detects that a user enters or leaves the AoI.
    /// For that, it is necessary to have an extension that sends a setUserPosition to the mmo api.
    /// </summary>
    /// <param name="e"></param>
    private void OnProximityListUpdate(BaseEvent e)
    {
        List <User> addedUsers   = e.Params.GetAddedUsers();
        List <User> removedUsers = e.Params.GetRemovedUsers();

        // Handle all new Users
        foreach (User user in addedUsers)
        {
            Vector3    pos     = new Vector3(user.AOIEntryPoint.FloatX, user.AOIEntryPoint.FloatY, user.AOIEntryPoint.FloatZ);
            Quaternion quat    = Quaternion.Euler(0, (float)user.GetVariable("rot").GetDoubleValue(), 0);
            SFSUser    sfsuser = (SFSUser)user;

            SpawnRemotePlayer(sfsuser, pos, quat);
        }

        // Handle removed users
        foreach (User user in removedUsers)
        {
            RemoveRemotePlayer((SFSUser)user);
        }
    }
Example #16
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();
        }
    }
Example #17
0
    private void SpawnRemotePlayer(SFSUser user, int numModel, int numMaterial, Vector3 pos, Quaternion rot)
    {
        // See if there already exists a model so we can destroy it first
        if (remotePlayers.ContainsKey(user) && remotePlayers[user] != null)
        {
            Destroy(remotePlayers[user]);
            remotePlayers.Remove(user);
        }

        // Lets spawn our remote player model
        GameObject remotePlayer = GameObject.Instantiate(playerModels[numModel]) as GameObject;

        remotePlayer.AddComponent <SimpleRemoteInterpolation>();
        remotePlayer.GetComponent <SimpleRemoteInterpolation>().SetTransform(pos, rot, false);

        // Color and name
        remotePlayer.GetComponentInChildren <TextMesh>().text     = user.Name;
        remotePlayer.GetComponentInChildren <Renderer>().material = playerMaterials[numMaterial];

        // Lets track the dude
        remotePlayers.Add(user, remotePlayer);
    }
Example #18
0
    private Player CreateRemotePlayer(SFSUser user, int modelIndex, Vector3 pos, Quaternion rot, string optionsStr, string parseId, string displayName, int teamID, PlayerType ptype, bool isSitting)
    {
        GameObject remotePlayerGO = CreateRemotePlayerGO(modelIndex);

        remotePlayerGO.GetComponent <SimpleRemoteInterpolation>().SetTransform(pos, rot, false);
        GameObject oldGO = null;

        if (remotePlayers.TryGetValue(user, out oldGO) && oldGO != null)
        {
            Destroy(oldGO);
        }
        remotePlayers[user] = remotePlayerGO;
        Player remotePlayer;

        if (players.TryGetValue(user.Id, out remotePlayer))
        {
            remotePlayer.ModelIdx    = modelIndex;
            remotePlayer.gameObject  = remotePlayerGO;
            remotePlayer.ParseId     = parseId;
            remotePlayer.DisplayName = displayName;
            remotePlayer.Type        = ptype;
        }
        else
        {
            remotePlayer = new Player(user, remotePlayerGO, modelIndex, ptype, parseId, displayName, teamID);
            players.Add(user.Id, remotePlayer);
            if (parseId != "" && GameGUI.Inst.guiLayer != null)
            {
                GameGUI.Inst.guiLayer.ExecuteJavascriptWithValue(remotePlayer.GetAddToGUIUserListJSCmd());
            }
        }
        remotePlayer.UpdateTransform(pos, rot.eulerAngles.y);
        remotePlayer.ApplyAvatarOptions(optionsStr);
        if (isSitting)
        {
            remotePlayer.Sit();
        }
        return(remotePlayer);
    }
Example #19
0
    public void OnUserEnterRoom(BaseEvent evt)
    {
        if (evt == null)
        {
            Debug.Log("self localplayer has just joined default Room");
        }
        else
        {
            SFSRoom room = (SFSRoom)evt.Params["room"];
            SFSUser user = (SFSUser)evt.Params["user"];
            Debug.Log("User: "******" has just joined Room: " + room.Name);

            //lets spawn the remote user after some delay so server can receive its position
            delayedSpawnRemotePlayer(user, room.Name, 1);

            Player player = null;
            if (TryGetPlayer(user.Id, out player) && CommunicationManager.IsPrivateRoom(room.Name))
            {
                GameGUI.Inst.ExecuteJavascriptOnGui(player.GetUserEnterPrivateRoomJSCmd(room.Name));
                Debug.LogError(user.Name + " entered private room");
            }
        }
    }
Example #20
0
    private void SpawnRemotePlayer(SFSUser user, string room = "")
    {
        VDebug.Log("Spawning user: "******" room: " + room);

        // New client just started transmitting - lets create remote player
        PlayerInit pInit = InitPlayerVariablesFromUserVariables(user.GetVariables());

        pInit.displayName = (string.IsNullOrEmpty(pInit.displayName)) ? user.Name : pInit.displayName;


        // See if there already exists a model so we can destroy it first
        if (remotePlayers.ContainsKey(user) && remotePlayers[user] != null)
        {
            Destroy(remotePlayers[user]);
            remotePlayers.Remove(user);
            players.Remove(user.Id);
            if (user.Name == GetLocalPlayer().SFSName)
            {
                Debug.LogError("Caught someone logging in with my name, logging out");
                CommunicationManager.Inst.LogOut();
                return;
            }
        }

        if (pInit.ptype != PlayerType.STEALTH && roomEntrySoundFlag)
        {
            SoundManager.Inst.PlayEnter();
        }

        Player remotePlayer = CreateRemotePlayer(user, pInit.modelIndex, pInit.Pos, pInit.Rot, pInit.optionsStr, pInit.parseID, pInit.displayName, pInit.teamID, pInit.ptype, pInit.sit);

        if (CommunicationManager.IsPrivateRoom(room))
        {
            GameGUI.Inst.ExecuteJavascriptOnGui(remotePlayer.GetUserEnterPrivateRoomJSCmd(room));
        }
    }
Example #21
0
    private void OnUserExitRoom(BaseEvent e)
    {
        SFSUser user = (SFSUser)e.Params["user"];

        RemoveRemotePlayer(user);
    }
 public void SetRemoteUser(SFSUser sfsUser)
 {
     user = sfsUser;
 }
Example #23
0
    private void userVarUpdateHandler(BaseEvent evt)
    {
        List <string> changedVars = (List <string>)evt.Params["changedVars"];

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

        // Exit from funciton if user is the local player himself
        if (user == sfs.MySelf)
        {
            return;
        }

        // Get remote player form list
        if (gm.remotePlayers.ContainsKey(user))
        {
            remotePlayer = gm.remotePlayers[user];
        }
        else // Spawn remote player if it's not ins the list
        {
            gm.SpawnRemotePlayer(user);
            remotePlayer = gm.remotePlayers[user];
        }

        //gm.trace("(" + user.Name + ") Changed its vars!");

        // Change remote player's position and velocity on change
        if (changedVars.Contains("px") || changedVars.Contains("py"))
        {
            remotePlayer.transform.position = new Vector3((float)user.GetVariable("px").GetDoubleValue(), (float)user.GetVariable("py").GetDoubleValue(), 0);
        }
        if (changedVars.Contains("vx"))
        {
            remotePlayer.GetComponent <Rigidbody2D>().velocity = new Vector3((float)user.GetVariable("vx").GetDoubleValue(), (float)user.GetVariable("vy").GetDoubleValue(), 0);
        }
        if (changedVars.Contains("vely"))
        {
            remotePlayer.GetComponent <Rigidbody2D>().velocity = new Vector3((float)user.GetVariable("vx").GetDoubleValue(), (float)user.GetVariable("vy").GetDoubleValue(), 0);
        }

        // Change remote player's animation based on velocity
        if (remotePlayer.GetComponent <Rigidbody2D>().velocity.x == 0 && remotePlayer.GetComponent <Rigidbody2D>().velocity.y == 0)
        {
            remotePlayer.GetComponent <Animator>().SetBool("Running", false);
        }
        else
        {
            remotePlayer.GetComponent <Animator>().SetBool("Running", true);
        }


        // Redirecting remote player direction
        if (remotePlayer.GetComponent <Rigidbody2D>().velocity.x != 0)
        {
            remotePlayerDirection = (remotePlayer.GetComponent <Rigidbody2D>().velocity.x < 0) ? false : true;
        }
        Vector3 trueDirection = new Vector3(remotePlayerDirection ? 1 : -1, 1, 1);

        remotePlayer.GetComponent <Transform>().localScale = trueDirection;
        remotePlayer.transform.FindChild("name").GetComponent <Transform>().localScale = trueDirection;
        //if(user.ContainsVariable("vx"))
        //    if (user.GetVariable("vx").GetDoubleValue() != 0)
        //        remotePlayerDirection = (user.GetVariable("vx").GetDoubleValue() < 0) ? false : true;
    }
Example #24
0
    private void RemoveRemotePlayer(SFSUser user)
    {
        if (user == smartFox.MySelf) return;

        if (remotePlayers.ContainsKey(user)) {
            Destroy(remotePlayers[user]);
            remotePlayers.Remove(user);
        }
    }
Example #25
0
    IEnumerator delayedSpawnRemotePlayer(SFSUser user, string room, int delay)
    {
        yield return(new WaitForSeconds(delay));

        SpawnRemotePlayer(user, room);
    }
    private void RemoveRemotePlayer(SFSUser user)
    {
        if (user == sfs.MySelf) return;

        if (Statici.PlayersRemoti.ContainsKey(user.Id))
        {
            minimappa.DistruggiMarcatore(user.Id);
            Destroy(Statici.PlayersRemoti[user.Id]);
            Statici.RimuoviDizionarioUtenteNetwork(user.Id);

        }
    }
Example #27
0
    public void OnUserVariableUpdate(BaseEvent evt)
    {
        // When user variable is updated on any client, then this callback is being received

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

        if (user == CommunicationManager.MySelf || user == null)
        {
            return;
        }

        //GameGUI.Inst.WriteToConsoleLog("OnUserVariableUpdate() " + Time.time);


        if (!remotePlayers.ContainsKey(user))
        {
            SpawnRemotePlayer(user);
        }

        Player remotePlayer = players[user.Id];

        try {
            // Check if the remote user changed his position or rotation
            if (changedVars.Contains("x") || changedVars.Contains("y") || changedVars.Contains("z") || changedVars.Contains("rot"))
            {
                float   rotAngle   = (float)user.GetVariable("rot").GetDoubleValue();
                bool    rotChanged = rotAngle != remotePlayer.gameObject.transform.rotation.eulerAngles.y;
                Vector3 newPos     = new Vector3((float)user.GetVariable("x").GetDoubleValue(), (float)user.GetVariable("y").GetDoubleValue(), (float)user.GetVariable("z").GetDoubleValue());
                remotePlayer.UpdateTransform(newPos, rotAngle);
                if (rotChanged)
                {
                    remotePlayer.playerController.shuffleTime = 0.25f;
                }
            }

            if (changedVars.Contains("scl"))
            {
                remotePlayer.UpdateScale(user.GetVariable("scl"));
            }

            if (changedVars.Contains("modelAnimation"))
            {
                remotePlayer.UpdateAnimState(user.GetVariable("modelAnimation"));
            }

            if (changedVars.Contains("spd"))
            {
                remotePlayer.UpdateSpeed(user.GetVariable("spd"));
            }

            if (changedVars.Contains("gt"))
            {
                remotePlayer.playerController.gazePanTilt.x = (float)user.GetVariable("gt").GetDoubleValue();
                remotePlayer.playerController.gazePanTilt.y = (float)user.GetVariable("gp").GetDoubleValue();
            }

            if (changedVars.Contains("ptype"))
            {
                remotePlayer.UpdateType(user.GetVariable("ptype"));
            }

            if (changedVars.Contains("playerModel"))
            {
                SetRemotePlayerModel(user, user.GetVariable("playerModel").GetIntValue());
                Debug.Log("remote changed model!:" + user.GetVariable("playerModel").GetIntValue());
            }
        }
        catch (KeyNotFoundException e) {
            Debug.LogError("KeyNotFoundException, changed vars dont exist for user, msg from different level? " + e.StackTrace);
        }
    }
Example #28
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());
        //}
    }
Example #29
0
    private void SpawnRemotePlayer(SFSUser user, int numModel, int numMaterial, Vector3 pos, Quaternion rot)
    {
        // See if there already exists a model so we can destroy it first
        if (remotePlayers.ContainsKey(user) && remotePlayers[user] != null) {
            Destroy(remotePlayers[user]);
            remotePlayers.Remove(user);
        }

        // Lets spawn our remote player model
        GameObject remotePlayer = GameObject.Instantiate(playerModels[numModel]) as GameObject;
        remotePlayer.AddComponent<SimpleRemoteInterpolation>();
        remotePlayer.GetComponent<SimpleRemoteInterpolation>().SetTransform(pos, rot, false);

        // Color and name
        remotePlayer.GetComponentInChildren<TextMesh>().text = user.Name;
        remotePlayer.GetComponentInChildren<Renderer>().material = playerMaterials[numMaterial];

        // Lets track the dude
        remotePlayers.Add(user, remotePlayer);
    }
Example #30
0
    private void OnUserEnterRoom(BaseEvent evt)
    {
        SFSUser user = (SFSUser)evt.Params["user"];

        UserEnterRoom(user);
    }