Ejemplo n.º 1
0
    public void HandlePropCommand(string message)
    {
        var motorCommands = message.Split(':');

        var LeftPropValue      = 0;
        var LeftPropValueValid = Int32.TryParse(motorCommands[0], out LeftPropValue);

        var RightPropValue      = 0;
        var RightPropValueValid = Int32.TryParse(motorCommands[1], out RightPropValue);

        var TopPropValue      = 0;
        var TopPropValueValid = Int32.TryParse(motorCommands[2], out TopPropValue);

        if (LeftPropValueValid)
        {
            if (LeftPropValue > 0)
            {
                LeftProp.MoveForward(Mathf.Abs(LeftPropValue));
            }
            else if (LeftPropValue < 0)
            {
                LeftProp.MoveReverse(Mathf.Abs(LeftPropValue));
            }
            else
            {
                LeftProp.Stop();
            }
        }

        if (RightPropValueValid)
        {
            if (RightPropValue > 0)
            {
                RightProp.MoveForward(Mathf.Abs(RightPropValue));
            }
            else if (RightPropValue < 0)
            {
                RightProp.MoveReverse(Mathf.Abs(RightPropValue));
            }
            else
            {
                RightProp.Stop();
            }
        }

        if (TopPropValueValid)
        {
            if (TopPropValue > 0)
            {
                TopProp.MoveForward(Mathf.Abs(TopPropValue));
            }
            else if (TopPropValue < 0)
            {
                TopProp.MoveReverse(Mathf.Abs(TopPropValue));
            }
            else
            {
                TopProp.Stop();
            }
        }
    }
Ejemplo n.º 2
0
    public override bool HandleMessage(string message)
    {
        var motorCommands = JSON.Parse(message);


        var LeftPropValueValid  = false;
        var RightPropValueValid = false;
        var TopPropValueValid   = false;

        if (motorCommands["Motor1"] != null)
        {
            LeftPropValueValid = true;
            LeftPropValue      = motorCommands["Motor1"].AsInt;
        }

        if (motorCommands["Motor2"] != null)
        {
            RightPropValueValid = true;
            RightPropValue      = motorCommands["Motor2"].AsInt;
        }

        if (motorCommands["Motor3"] != null)
        {
            TopPropValueValid = true;
            TopPropValue      = motorCommands["Motor3"].AsInt;
        }


        if (motorCommands["Camera"] != null)
        {
            var cameraValue = motorCommands["Camera"].AsInt;

            switch (cameraValue)
            {
            case 1:
                Light1.localRotation = Quaternion.Euler(-25.0f, 0.0f, 0.0f);
                Light2.localRotation = Quaternion.Euler(-25.0f, 0.0f, 0.0f);
                break;

            case 0:
                Light1.localRotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
                Light2.localRotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
                break;

            case -1:
                Light1.localRotation = Quaternion.Euler(25.0f, 0.0f, 0.0f);
                Light2.localRotation = Quaternion.Euler(25.0f, 0.0f, 0.0f);
                break;
            }
        }

        if (motorCommands["Brightness"] != null)
        {
            var brightness = motorCommands["Brightness"].AsInt;

            brightness = Mathf.Clamp(brightness, 0, 8);

            Light1.light.intensity = brightness;
            Light2.light.intensity = brightness;
        }

        if (LeftPropValueValid)
        {
            if (LeftPropValue > 0)
            {
                LeftProp.MoveForward(Mathf.Abs(LeftPropValue));
            }
            else if (LeftPropValue < 0)
            {
                LeftProp.MoveReverse(Mathf.Abs(LeftPropValue));
            }
            else
            {
                LeftProp.Stop();
            }
        }

        if (RightPropValueValid)
        {
            if (RightPropValue > 0)
            {
                RightProp.MoveForward(Mathf.Abs(RightPropValue));
            }
            else if (RightPropValue < 0)
            {
                RightProp.MoveReverse(Mathf.Abs(RightPropValue));
            }
            else
            {
                RightProp.Stop();
            }
        }

        if (TopPropValueValid)
        {
            if (TopPropValue > 0)
            {
                TopProp.MoveForward(Mathf.Abs(TopPropValue));
            }
            else if (TopPropValue < 0)
            {
                TopProp.MoveReverse(Mathf.Abs(TopPropValue));
            }
            else
            {
                TopProp.Stop();
            }
        }

        return(true);
    }