// Called when player connects with their phone
    void InitializeNetPlayer(SpawnInfo spawnInfo)
    {
        Init();

        m_netPlayer = spawnInfo.netPlayer;
        m_netPlayer.OnDisconnect += Remove;

        // Setup events for the different messages.
        m_netPlayer.RegisterCmdHandler <MessageMove>("move", OnMove);
        m_netPlayer.RegisterCmdHandler <MessageJump>("jump", OnJump);

        m_playerNameManager = new HFTPlayerNameManager(m_netPlayer);
        m_playerNameManager.OnNameChange += HandleNameChange;

        // We always get a `data` so check if it has one key from our expected message
        Dictionary <string, object> dict = spawnInfo.data as Dictionary <string, object>;

        if (dict != null && dict.ContainsKey("dir"))
        {
            // This player was transferred from another game.

            // Turn the data back into our structure
            DeJson.Deserializer  deserializer = new DeJson.Deserializer();
            HFTMessageSwitchGame data         = deserializer.Deserialize <HFTMessageSwitchGame>(spawnInfo.data);

            // Choose a starting position based on the old position
            float x = (data.pos.x < MultiMachineLevelSettings.settings.leftEdgeOfLevel.position.x)
                ? MultiMachineLevelSettings.settings.rightEdgeOfLevel.position.x - 1 : MultiMachineLevelSettings.settings.leftEdgeOfLevel.position.x + 1;
            transform.localPosition = new Vector3(x, data.pos.y, 0f);

            // Set the initial velocity
            m_rigidbody2d.velocity = data.vel;

            // And the direction
            m_direction = data.dir;

            SetName(data.name);
            SetColor(data.color);
        }
        else
        {
            // This player just joined.
            MoveToRandomSpawnPoint();
            SetName(m_playerNameManager.Name);
            float           hue   = Random.value;
            float           sat   = (float)Random.Range(0, 3) * -0.25f;
            MessageSetColor color = new MessageSetColor(
                hue,
                sat,
                0.0f,
                m_material.GetFloat("_HSVRangeMin"),
                m_material.GetFloat("_HSVRangeMax"));
            SetColor(color);

            // Send it to the phone
            m_netPlayer.SendCmd("setColor", color);
        }
    }
Ejemplo n.º 2
0
    public static void ShowSerializedMessage()
    {
        List <gm.sendIDMessageTP> sendIDMessageTPs = new List <gm.sendIDMessageTP>();
        Texture2D texture = Resources.Load <Texture2D>("Placeholders/test");

        Debug.Log(texture.GetPixel(0, 0));
        for (int i = 0; i < 10; i++)
        {
            sendIDMessageTPs.Add(new gm.sendIDMessageTP(i.ToString(), texture));
        }
        gm.listMessageTP listMessageTP = new gm.listMessageTP(sendIDMessageTPs);
        Debug.Log(DeJson.Serializer.Serialize(sendIDMessageTPs[0]));
        string output = DeJson.Serializer.Serialize(listMessageTP);

        Debug.Log(output);
        DeJson.Deserializer deserializer = new DeJson.Deserializer();
        listMessageTP = deserializer.Deserialize <gm.listMessageTP>(output);
        //Debug.Log(((Texture2D)listMessageTP._messages[0].playerPhoto).GetPixel(0, 0));
    }
Ejemplo n.º 3
0
        private void StartPlayer(MessageToClient msg)
        {
            if (m_players.ContainsKey(msg.id))
            {
                return;
            }

            string name = "";

            RealNetPlayer.Options options = new RealNetPlayer.Options();
            if (msg.data != null)
            {
                DeJson.Deserializer deserializer = new DeJson.Deserializer();
                HFTPlayerStartData  startData    = deserializer.Deserialize <HFTPlayerStartData>(msg.data);
                if (startData != null)
                {
                    options.sessionId = startData.__hft_session_id__;
                    name = startData.__hft_name__;
                }
            }

            if (System.String.IsNullOrEmpty(name))
            {
                name = "Player" + (++m_totalPlayerCount);
            }

            NetPlayer player = new RealNetPlayer(this, msg.id, name, options);

            m_players[msg.id] = player;
            QueueEvent(() =>
            {
                var handler = OnPlayerConnect;
                if (handler != null)
                {
                    handler(new PlayerConnectMessageArgs(player, name, msg.data));
                }
            });
        }