Esempio n. 1
0
    void SetColor(MessageSetColor colorAdjust)
    {
        // get the hsva for the baseColor
        Vector4 hsva = ColorUtils.ColorToHSVA(baseColor);

        // adjust that base color by the amount we picked
        hsva.x += colorAdjust.h;
        hsva.y += colorAdjust.s;
        hsva.w += colorAdjust.v;

        // now get the adjusted color.
        Color playerColor = ColorUtils.HSVAToColor(hsva);

        // Create a 1 pixel texture for the OnGUI code to draw the label
        Color[] pix = new Color[1];
        pix[0] = playerColor;
        Texture2D tex = new Texture2D(1, 1);

        tex.SetPixels(pix);
        tex.Apply();
        m_guiStyle.normal.background = tex;

        // Set the HSVA material of the character to the color adjustments.
        m_material.SetVector("_HSVAAdjust", new Vector4(colorAdjust.h, colorAdjust.s, colorAdjust.v, 0.0f));
        m_material.SetFloat("_HSVRangeMin", colorAdjust.rangeMin);
        m_material.SetFloat("_HSVRangeMax", colorAdjust.rangeMax);
    }
Esempio n. 2
0
    // Called when player connects with their phone
    void InitializeNetPlayer(SpawnInfo spawnInfo)
    {
        Init();

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

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

        MoveToRandomSpawnPoint();

        SetName(m_netPlayer.Name);

        // Pick a random amount to adjust the hue and saturation
        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);
    }
Esempio n. 3
0
    // Called when player connects with their phone
    void InitializeNetPlayer(SpawnInfo spawnInfo)
    {
        Init();

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

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

        SetName(m_netPlayer.Name);

        // Pick a random amount to adjust the hue and saturation
        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);
    }
    // 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 SetColor(MessageSetColor color)
    {
        m_color = color;
        Color[] pix  = new Color[1];
        Vector4 hsva = ColorUtils.ColorToHSVA(baseColor);

        hsva.x += color.h;
        hsva.y += color.s;
        hsva.w += color.v;
        pix[0]  = ColorUtils.HSVAToColor(hsva);
        Texture2D tex = new Texture2D(1, 1);

        tex.SetPixels(pix);
        tex.Apply();
        m_guiStyle.normal.background = tex;
        m_material.SetVector("_HSVAAdjust", new Vector4(color.h, color.s, color.v, 0.0f));
        m_material.SetFloat("_HSVRangeMin", color.rangeMin);
        m_material.SetFloat("_HSVRangeMax", color.rangeMax);
    }
	void SetColor(MessageSetColor colorAdjust) {
		// get the hsva for the baseColor
		Vector4 hsva = ColorUtils.ColorToHSVA(baseColor);
		// adjust that base color by the amount we picked
		hsva.x += colorAdjust.h;
		hsva.y += colorAdjust.s;
		hsva.w += colorAdjust.v;
		
		// now get the adjusted color.
		Color playerColor = ColorUtils.HSVAToColor(hsva);
		
		// Create a 1 pixel texture for the OnGUI code to draw the label
		Color[] pix = new Color[1];
		pix[0] = playerColor;
		Texture2D tex = new Texture2D(1, 1);
		tex.SetPixels(pix);
		tex.Apply();
		m_guiStyle.normal.background = tex;
		
		// Set the HSVA material of the character to the color adjustments.
		m_material.SetVector("_HSVAAdjust", new Vector4(colorAdjust.h, colorAdjust.s, colorAdjust.v, 0.0f));
		m_material.SetFloat("_HSVRangeMin", colorAdjust.rangeMin);
		m_material.SetFloat("_HSVRangeMax", colorAdjust.rangeMax);
	}
Esempio n. 7
0
 void SetColor(MessageSetColor color)
 {
     Color[] pix = new Color[1];
     Vector4 hsva = ColorUtils.ColorToHSVA(baseColor);
     hsva.x += color.h;
     hsva.y += color.s;
     hsva.w += color.v;
     pix[0] = ColorUtils.HSVAToColor(hsva);
     Texture2D tex = new Texture2D(1, 1);
     tex.SetPixels(pix);
     tex.Apply();
     m_guiStyle.normal.background = tex;
     m_material.SetVector("_HSVAAdjust", new Vector4(color.h, color.s, color.v, 0.0f));
     m_material.SetFloat("_HSVRangeMin", color.rangeMin);
     m_material.SetFloat("_HSVRangeMax", color.rangeMax);
 }