// Called by ExampleCharacterSelect using GameObject.SendMessage
        void InitializeFromCharacterSelect(ExampleCharacterSelect.StartInfo startInfo)
        {
            Init();
            // Save the netplayer object so we can use it send messages to the phone
            m_netPlayer = startInfo.netPlayer;

            // Register handler to call if the player disconnects from the game.
            m_netPlayer.OnDisconnect += Remove;

            // Handle Namechange. Either use the one passed in or make a new one
            m_playerNameManager = startInfo.playerNameManager;
            m_playerNameManager.OnNameChange += ChangeName;

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

            ExampleCharacterSelectGameSettings settings = ExampleCharacterSelectGameSettings.settings();
            m_position = new Vector3(Random.Range(0.0f, settings.areaWidth), 0, Random.Range(0.0f, settings.areaHeight));
            transform.localPosition = m_position;

            SetName(m_playerNameManager.Name);
            Color color = new Color(Random.value, Random.value, Random.value);
            // make one random component a minimum brightness
            color[RandInt(3)] = Random.value * 0.5f + 0.5f;
            SetColor(color);
        }
 void OnDestroy()
 {
     if (m_playerNameManager != null)
     {
         m_playerNameManager.Close();
         m_playerNameManager = null;
     }
 }
    // 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);
        }
    }
 void Cleanup()
 {
     m_netPlayer.OnDisconnect -= HandleDisconnect;
     if (m_playerNameManager != null)
     {
         m_playerNameManager.Close();
         m_playerNameManager = null;
     }
 }
        void InitializeNetPlayer(SpawnInfo spawnInfo)
        {
            // Save the netplayer object so we can use it send messages to the phone
            m_netPlayer = spawnInfo.netPlayer;

            // Register handler to call if the player disconnects from the game.
            m_netPlayer.OnDisconnect += Remove;

            // Track name changes
            m_playerNameManager = new HFTPlayerNameManager(m_netPlayer);

            // Setup events for the different messages.
            m_netPlayer.RegisterCmdHandler<MessageCharacter>("character", OnCharacter);
        }
        void InitializeNetPlayer(SpawnInfo spawnInfo)
        {
            // Save the netplayer object so we can use it send messages to the phone
            m_netPlayer = spawnInfo.netPlayer;

            // Register handler to call if the player disconnects from the game.
            m_netPlayer.OnDisconnect += Remove;

            // Track name changes
            m_playerNameManager = new HFTPlayerNameManager(m_netPlayer);

            // Setup events for the different messages.
            m_netPlayer.RegisterCmdHandler <MessageCharacter>("character", OnCharacter);
        }
    void InitializeNetPlayer(SpawnInfo spawnInfo)
    {
        m_netPlayer = spawnInfo.netPlayer;
        m_netPlayer.OnDisconnect += HandleDisconnect;

        // Setup events for the different messages.
        m_netPlayer.RegisterCmdHandler <MessageButton>("button", HandleButton);
        m_netPlayer.RegisterCmdHandler <MessageDPad>("dpad", HandleDPad);
        m_netPlayer.RegisterCmdHandler <MessageOrient>("orient", HandleOrient);
        m_netPlayer.RegisterCmdHandler <MessageAccel>("accel", HandleAccel);
        m_netPlayer.RegisterCmdHandler <MessageRot>("rot", HandleRot);
        m_netPlayer.RegisterCmdHandler <MessageTouch>("touch", HandleTouch);

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

        // If the controller is showing the player "game full"
        // then tell it can play.
        m_netPlayer.SendCmd("play");
        SendControllerOptions();
        SendColor();
    }
        void InitializeNetPlayer(SpawnInfo spawnInfo)
        {
            // Save the netplayer object so we can use it send messages to the phone
            m_netPlayer = spawnInfo.netPlayer;

            // Register handler to call if the player disconnects from the game.
            m_netPlayer.OnDisconnect += Remove;

            // Track name changes
            m_playerNameManager = new HFTPlayerNameManager(m_netPlayer);
            m_playerNameManager.OnNameChange += ChangeName;

            // Setup events for the different messages.
            m_netPlayer.RegisterCmdHandler<MessageMove>("move", OnMove);
            m_netPlayer.RegisterCmdHandler<MessageColor>("color", OnColor);

            ExampleSimpleGameSettings settings = ExampleSimpleGameSettings.settings();
            m_position = new Vector3(UnityEngine.Random.Range(0, settings.areaWidth), 0, UnityEngine.Random.Range(0, settings.areaHeight));
            transform.localPosition = m_position;

            SetName(m_playerNameManager.Name);
        }
Esempio n. 9
0
        void InitializeNetPlayer(SpawnInfo spawnInfo)
        {
            // Save the netplayer object so we can use it send messages to the phone
            m_netPlayer = spawnInfo.netPlayer;

            // Register handler to call if the player disconnects from the game.
            m_netPlayer.OnDisconnect += Remove;

            // Track name changes
            m_playerNameManager = new HFTPlayerNameManager(m_netPlayer);
            m_playerNameManager.OnNameChange += ChangeName;

            // Setup events for the different messages.
            m_netPlayer.RegisterCmdHandler <MessageMove>("move", OnMove);
            m_netPlayer.RegisterCmdHandler <MessagePic>("pic", OnPicture);

            ExampleCameraGameSettings settings = ExampleCameraGameSettings.settings();

            m_position = new Vector3(UnityEngine.Random.Range(0, settings.areaWidth), 0, UnityEngine.Random.Range(0, settings.areaHeight));
            transform.localPosition = m_position;

            SetName(m_playerNameManager.Name);
        }
Esempio n. 10
0
    void InitializeNetPlayer(SpawnInfo spawnInfo)
    {
        m_netPlayer = spawnInfo.netPlayer;
        m_netPlayer.OnDisconnect += HandleDisconnect;

        // Setup events for the different messages.
        m_netPlayer.RegisterCmdHandler<MessageButton>("button", HandleButton);
        m_netPlayer.RegisterCmdHandler<MessageDPad>("dpad", HandleDPad);
        m_netPlayer.RegisterCmdHandler<MessageOrient>("orient", HandleOrient);
        m_netPlayer.RegisterCmdHandler<MessageAccel>("accel", HandleAccel);
        m_netPlayer.RegisterCmdHandler<MessageRot>("rot", HandleRot);
        m_netPlayer.RegisterCmdHandler<MessageTouch>("touch", HandleTouch);

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

        // If the controller is showing the player "game full"
        // then tell it can play.
        m_netPlayer.SendCmd("play");
        SendControllerOptions();
        SendColor();
    }
Esempio n. 11
0
 void Cleanup()
 {
     m_netPlayer.OnDisconnect -= HandleDisconnect;
     if (m_playerNameManager != null) {
       m_playerNameManager.Close();
       m_playerNameManager = null;
     }
 }
 public StartInfo(NetPlayer netPlayer, HFTPlayerNameManager playerNameManager)
 {
     this.netPlayer = netPlayer;
     this.playerNameManager = playerNameManager;
 }
 public StartInfo(NetPlayer netPlayer, HFTPlayerNameManager playerNameManager)
 {
     this.netPlayer         = netPlayer;
     this.playerNameManager = playerNameManager;
 }