예제 #1
0
    // Start is called before the first frame update
    void Start()
    {
        p1HygieneBar.UpdateColor(Color.red);
        p2HygieneBar.UpdateColor(Color.red);
        p3HygieneBar.UpdateColor(Color.red);
        p4HygieneBar.UpdateColor(Color.red);

        p1SanityBar.UpdateColor(Color.magenta);
        p2SanityBar.UpdateColor(Color.magenta);
        p3SanityBar.UpdateColor(Color.magenta);
        p4SanityBar.UpdateColor(Color.magenta);

        p1EnergyBar.UpdateColor(Color.yellow);
        p2EnergyBar.UpdateColor(Color.yellow);
        p3EnergyBar.UpdateColor(Color.yellow);
        p4EnergyBar.UpdateColor(Color.yellow);

        p1FoodnessBar.UpdateColor(Color.grey);
        p2FoodnessBar.UpdateColor(Color.grey);
        p3FoodnessBar.UpdateColor(Color.grey);
        p4FoodnessBar.UpdateColor(Color.grey);
    }
    public void Configure(GameObject unit)
    {
        // Rect
        RectTransform slotRect = GetComponent <RectTransform>();

        slotRect.localScale = new Vector3(1, 1, 1);
        slotRect.offsetMin  = new Vector2(0, 0);
        slotRect.offsetMax  = new Vector2(0, 0);
        slotRect.sizeDelta  = new Vector2(65, 65);

        // Unit
        _unit     = unit;
        _unitUnit = unit.GetComponent <Unit>();

        // Image
        if (_unitIcon == null)
        {
            _unitIcon = transform.GetChild(0).GetComponent <Image>();
        }
        _unitIcon.sprite = unit.GetComponent <UnitTraining>().GetUnitSprite();

        // Health Bar
        GameObject healthBar = Instantiate(unit.GetComponent <Unit>().GetHealthBar());

        _healthBar = healthBar.transform.GetChild(0).GetComponent <SimpleHealthBar>();
        healthBar.transform.SetParent(transform.GetChild(1));

        RectTransform rect = healthBar.GetComponent <RectTransform>();

        rect.localScale = new Vector3(1, 1, 1);
        rect.offsetMin  = new Vector2(0, 0);
        rect.offsetMax  = new Vector2(0, 0);
        rect.sizeDelta  = new Vector2(60, 5);

        _healthBar.UpdateColor(Color.white);
    }
예제 #3
0
    // Update is called once per frame
    void Update()
    {
        Debug.Log("INSIDE UPDATE");
        // Battery Power
        //float battery_power = .78F;
        Debug.Log("BATTERY READING INSIDE UPDATE IS " + batteryReading);
        // check if any values are null; if so, break
        // if batteryReading is null, so are the rest
        if (batteryReading == null)
        {
            return;
        }

        float battery_power = float.Parse(batteryReading.ToString());

        if (battery_power < 1 && battery_power > .50)
        {
            BatteryPower.UpdateColor(Color.green);
        }
        else if (battery_power < .50 && battery_power > .25)
        {
            BatteryPower.UpdateColor(Color.yellow);
        }
        else if (battery_power < .25 && battery_power > 0)
        {
            BatteryPower.UpdateColor(Color.red);
        }
        BatteryPower.UpdateBar(battery_power, 1);

        string touch_output;

        if (touchReading.ToString() == "1")
        {
            touch_output = "True";
        }
        else if (touchReading.ToString() == "0")
        {
            touch_output = "False";
        }
        else
        {
            touch_output = "what the heck";
        }


        // update text panel display
        Debug.Log("PRINTING STRING INSIDE UPDATE");
        string output = "Distance: " + distReading.ToString() + "cm" + "\n" + "Angle: " + angleReading.ToString() + "\n" + "Color: " + colorReading.ToString() + "\n" + "Touch: " + touch_output;

        Debug.Log(output);
        tmProh.text  = output;
        tmpText.text = output;

        string  color = colorReading.ToString();
        Color32 brown = new Color32(114, 96, 96, 255);

        // sets text bubble to corresponding color reading
        switch (color)
        {
        case "white":
            sphere_for_color.GetComponent <Renderer>().material.color = Color.white;
            break;

        case "red":
            sphere_for_color.GetComponent <Renderer>().material.color = Color.red;
            break;

        case "yellow":
            sphere_for_color.GetComponent <Renderer>().material.color = Color.yellow;
            break;

        case "green":
            sphere_for_color.GetComponent <Renderer>().material.color = Color.green;
            break;

        case "blue":
            sphere_for_color.GetComponent <Renderer>().material.color = Color.blue;
            break;

        case "brown":
            sphere_for_color.GetComponent <Renderer>().material.color = brown;
            break;

        case "black":
            sphere_for_color.GetComponent <Renderer>().material.color = Color.black;
            break;

        default:
            sphere_for_color.GetComponent <Renderer>().material.color = Color.grey;
            break;
        }
        // This is where the cone updates
        double size_cone = double.Parse(distReading.ToString());

        // Convert to inches
        size_cone = size_cone / 3.2;
        // Convert to cm
        size_cone = size_cone / 2.54;
        float size_cone_new = (float)size_cone;

        temp   = cone_for_distance.transform.localScale;
        temp.z = size_cone_new;
        temp.y = size_cone_new / 3;
        temp.x = size_cone_new / 3;
        cone_for_distance.transform.localScale = temp;

        // This is where the sphere for touch updates
        float sphere_touch = float.Parse(touchReading.ToString());

        temp_2 = sphere_for_touch.transform.localScale;
        //Debug.Log("the touch is-----" + sphere_touch);
        temp_2.z = sphere_touch / 4;
        temp_2.y = sphere_touch / 4;
        temp_2.x = sphere_touch / 4;
        sphere_for_touch.transform.localScale = temp_2;

        // This is where the angle is measured
        float angle = float.Parse(angleReading.ToString());

        needle_for_angle.transform.rotation = Quaternion.Euler(0, 0, angle);

        // This is where the forward is shown
        float line_forward = float.Parse(forwardReading.ToString());

        temp_3   = forward_line.transform.localScale;
        temp_3.z = line_forward;
        temp_3.y = line_forward;
        temp_3.x = line_forward;
        forward_line.transform.localScale = temp_3;

        // This is where the right is shown
        float line_right = float.Parse(rightReading.ToString());

        temp_4   = right_line.transform.localScale;
        temp_4.z = line_right;
        temp_4.y = line_right;
        temp_4.x = line_right;
        right_line.transform.localScale = temp_4;

        // This is where the left is shown
        float line_left = float.Parse(leftReading.ToString());

        temp_5   = left_line.transform.localScale;
        temp_5.z = line_left;
        temp_5.y = line_left;
        temp_5.x = line_left;
        left_line.transform.localScale = temp_5;

        // CODE FOR DROPDOWN
        switch (select_visualization.value)
        {
        case 0:
            x_input.text    = (sphere_for_color.transform.localPosition.x).ToString();
            y_input.text    = (sphere_for_color.transform.localPosition.y).ToString();
            z_input.text    = (sphere_for_color.transform.localPosition.z).ToString();
            x_mov_total_val = double.Parse(x_input.text);
            y_mov_total_val = double.Parse(y_input.text);
            z_mov_total_val = double.Parse(z_input.text);

            if (x_plus.x_plus_apply == true)
            {
                apply            = true;
                x_mov_total_val += .5;
                x_input.text     = x_mov_total_val.ToString();
                x_plus.apply_equals_false();
            }
            if (X_minus.x_minus_apply == true)
            {
                apply            = true;
                x_mov_total_val -= .5;
                x_input.text     = x_mov_total_val.ToString();
                X_minus.apply_equals_false();
            }
            if (Y_plus.y_plus_apply == true)
            {
                apply            = true;
                y_mov_total_val += .5;
                y_input.text     = y_mov_total_val.ToString();
                Y_plus.apply_equals_false();
            }
            if (Y_minus.y_minus_apply == true)
            {
                apply            = true;
                y_mov_total_val -= .5;
                y_input.text     = y_mov_total_val.ToString();
                Y_minus.apply_equals_false();
            }
            if (Z_plus.z_plus_apply == true)
            {
                apply            = true;
                z_mov_total_val += .5;
                z_input.text     = z_mov_total_val.ToString();
                Z_plus.apply_equals_false();
            }
            if (Z_minus.z_minus_apply == true)
            {
                apply            = true;
                z_mov_total_val -= .5;
                z_input.text     = z_mov_total_val.ToString();
                Z_minus.apply_equals_false();
            }
            if (apply == true)
            {
                PlayerPrefs.SetInt("player_prefs_color", 1);
                sphere_for_color.transform.localPosition = new Vector3(float.Parse(x_input.text), float.Parse(y_input.text), float.Parse(z_input.text));
                PlayerPrefs.SetFloat("color_transform_x", sphere_for_color.transform.localPosition.x);
                PlayerPrefs.SetFloat("color_transform_y", sphere_for_color.transform.localPosition.y);
                PlayerPrefs.SetFloat("color_transform_z", sphere_for_color.transform.localPosition.z);
                apply = false;
                break;
            }
            else
            {
                break;
            }

        case 1:
            x_input.text    = (cone_for_distance.transform.localPosition.x).ToString();
            y_input.text    = (cone_for_distance.transform.localPosition.y).ToString();
            z_input.text    = (cone_for_distance.transform.localPosition.z).ToString();
            x_mov_total_val = double.Parse(x_input.text);
            y_mov_total_val = double.Parse(y_input.text);
            z_mov_total_val = double.Parse(z_input.text);

            if (x_plus.x_plus_apply == true)
            {
                apply            = true;
                x_mov_total_val += .5;
                x_input.text     = x_mov_total_val.ToString();
                x_plus.apply_equals_false();
            }
            if (X_minus.x_minus_apply == true)
            {
                apply            = true;
                x_mov_total_val -= .5;
                x_input.text     = x_mov_total_val.ToString();
                X_minus.apply_equals_false();
            }
            if (Y_plus.y_plus_apply == true)
            {
                apply            = true;
                y_mov_total_val += .5;
                y_input.text     = y_mov_total_val.ToString();
                Y_plus.apply_equals_false();
            }
            if (Y_minus.y_minus_apply == true)
            {
                apply            = true;
                y_mov_total_val -= .5;
                y_input.text     = y_mov_total_val.ToString();
                Y_minus.apply_equals_false();
            }
            if (Z_plus.z_plus_apply == true)
            {
                apply            = true;
                z_mov_total_val += .5;
                z_input.text     = z_mov_total_val.ToString();
                Z_plus.apply_equals_false();
            }
            if (Z_minus.z_minus_apply == true)
            {
                apply            = true;
                z_mov_total_val -= .5;
                z_input.text     = z_mov_total_val.ToString();
                Z_minus.apply_equals_false();
            }
            if (apply == true)
            {
                PlayerPrefs.SetInt("player_prefs_cone", 1);
                cone_for_distance.transform.localPosition = new Vector3(float.Parse(x_input.text), float.Parse(y_input.text), float.Parse(z_input.text));
                PlayerPrefs.SetFloat("cone_transform_x", cone_for_distance.transform.localPosition.x);
                PlayerPrefs.SetFloat("cone_transform_y", cone_for_distance.transform.localPosition.y);
                PlayerPrefs.SetFloat("cone_transform_z", cone_for_distance.transform.localPosition.z);
                apply = false;
                break;
            }
            else
            {
                break;
            }

        case 2:
            x_input.text    = (sphere_for_touch.transform.localPosition.x).ToString();
            y_input.text    = (sphere_for_touch.transform.localPosition.y).ToString();
            z_input.text    = (sphere_for_touch.transform.localPosition.z).ToString();
            x_mov_total_val = double.Parse(x_input.text);
            y_mov_total_val = double.Parse(y_input.text);
            z_mov_total_val = double.Parse(z_input.text);

            if (x_plus.x_plus_apply == true)
            {
                apply            = true;
                x_mov_total_val += .5;
                x_input.text     = x_mov_total_val.ToString();
                x_plus.apply_equals_false();
            }
            if (X_minus.x_minus_apply == true)
            {
                apply            = true;
                x_mov_total_val -= .5;
                x_input.text     = x_mov_total_val.ToString();
                X_minus.apply_equals_false();
            }
            if (Y_plus.y_plus_apply == true)
            {
                apply            = true;
                y_mov_total_val += .5;
                y_input.text     = y_mov_total_val.ToString();
                Y_plus.apply_equals_false();
            }
            if (Y_minus.y_minus_apply == true)
            {
                apply            = true;
                y_mov_total_val -= .5;
                y_input.text     = y_mov_total_val.ToString();
                Y_minus.apply_equals_false();
            }
            if (Z_plus.z_plus_apply == true)
            {
                apply            = true;
                z_mov_total_val += .5;
                z_input.text     = z_mov_total_val.ToString();
                Z_plus.apply_equals_false();
            }
            if (Z_minus.z_minus_apply == true)
            {
                apply            = true;
                z_mov_total_val -= .5;
                z_input.text     = z_mov_total_val.ToString();
                Z_minus.apply_equals_false();
            }
            if (apply == true)
            {
                PlayerPrefs.SetInt("player_prefs_touch", 1);
                sphere_for_touch.transform.localPosition = new Vector3(float.Parse(x_input.text), float.Parse(y_input.text), float.Parse(z_input.text));
                PlayerPrefs.SetFloat("touch_transform_x", sphere_for_touch.transform.localPosition.x);
                PlayerPrefs.SetFloat("touch_transform_y", sphere_for_touch.transform.localPosition.y);
                PlayerPrefs.SetFloat("touch_transform_z", sphere_for_touch.transform.localPosition.z);
                apply = false;
                break;
            }
            else
            {
                break;
            }

        case 3:
            x_input.text    = (angle_visual.transform.localPosition.x).ToString();
            y_input.text    = (angle_visual.transform.localPosition.y).ToString();
            z_input.text    = (angle_visual.transform.localPosition.z).ToString();
            x_mov_total_val = double.Parse(x_input.text);
            y_mov_total_val = double.Parse(y_input.text);
            z_mov_total_val = double.Parse(z_input.text);

            if (x_plus.x_plus_apply == true)
            {
                apply            = true;
                x_mov_total_val += .5;
                x_input.text     = x_mov_total_val.ToString();
                x_plus.apply_equals_false();
            }
            if (X_minus.x_minus_apply == true)
            {
                apply            = true;
                x_mov_total_val -= .5;
                x_input.text     = x_mov_total_val.ToString();
                X_minus.apply_equals_false();
            }
            if (Y_plus.y_plus_apply == true)
            {
                apply            = true;
                y_mov_total_val += .5;
                y_input.text     = y_mov_total_val.ToString();
                Y_plus.apply_equals_false();
            }
            if (Y_minus.y_minus_apply == true)
            {
                apply            = true;
                y_mov_total_val -= .5;
                y_input.text     = y_mov_total_val.ToString();
                Y_minus.apply_equals_false();
            }
            if (Z_plus.z_plus_apply == true)
            {
                apply            = true;
                z_mov_total_val += .5;
                z_input.text     = z_mov_total_val.ToString();
                Z_plus.apply_equals_false();
            }
            if (Z_minus.z_minus_apply == true)
            {
                apply            = true;
                z_mov_total_val -= .5;
                z_input.text     = z_mov_total_val.ToString();
                Z_minus.apply_equals_false();
            }
            if (apply == true)
            {
                PlayerPrefs.SetInt("player_prefs_gyro", 1);
                angle_visual.transform.localPosition = new Vector3(float.Parse(x_input.text), float.Parse(y_input.text), float.Parse(z_input.text));
                PlayerPrefs.SetFloat("gyro_transform_x", angle_visual.transform.localPosition.x);
                PlayerPrefs.SetFloat("gyro_transform_y", angle_visual.transform.localPosition.y);
                PlayerPrefs.SetFloat("gyro_transform_z", angle_visual.transform.localPosition.z);
                apply = false;
                break;
            }
            else
            {
                break;
            }

        case 4:
            x_input.text    = (all_data_panel.transform.localPosition.x).ToString();
            y_input.text    = (all_data_panel.transform.localPosition.y).ToString();
            z_input.text    = (all_data_panel.transform.localPosition.z).ToString();
            x_mov_total_val = double.Parse(x_input.text);
            y_mov_total_val = double.Parse(y_input.text);
            z_mov_total_val = double.Parse(z_input.text);


            if (x_plus.x_plus_apply == true)
            {
                apply            = true;
                x_mov_total_val += .5;
                x_input.text     = x_mov_total_val.ToString();
                x_plus.apply_equals_false();
            }
            if (X_minus.x_minus_apply == true)
            {
                apply            = true;
                x_mov_total_val -= .5;
                x_input.text     = x_mov_total_val.ToString();
                X_minus.apply_equals_false();
            }
            if (Y_plus.y_plus_apply == true)
            {
                apply            = true;
                y_mov_total_val += .5;
                y_input.text     = y_mov_total_val.ToString();
                Y_plus.apply_equals_false();
            }
            if (Y_minus.y_minus_apply == true)
            {
                apply            = true;
                y_mov_total_val -= .5;
                y_input.text     = y_mov_total_val.ToString();
                Y_minus.apply_equals_false();
            }
            if (Z_plus.z_plus_apply == true)
            {
                apply            = true;
                z_mov_total_val += .5;
                z_input.text     = z_mov_total_val.ToString();
                Z_plus.apply_equals_false();
            }
            if (Z_minus.z_minus_apply == true)
            {
                apply            = true;
                z_mov_total_val -= .5;
                z_input.text     = z_mov_total_val.ToString();
                Z_minus.apply_equals_false();
            }
            if (apply == true)
            {
                PlayerPrefs.SetInt("player_prefs_data", 1);
                all_data_panel.transform.localPosition = new Vector3(float.Parse(x_input.text), float.Parse(y_input.text), float.Parse(z_input.text));
                PlayerPrefs.SetFloat("data_transform_x", all_data_panel.transform.localPosition.x);
                PlayerPrefs.SetFloat("data_transform_y", all_data_panel.transform.localPosition.y);
                PlayerPrefs.SetFloat("data_transform_z", all_data_panel.transform.localPosition.z);
                apply = false;
                break;
            }
            else
            {
                break;
            }

        case 5:
            x_input.text    = (all_arrows.transform.localPosition.x).ToString();
            y_input.text    = (all_arrows.transform.localPosition.y).ToString();
            z_input.text    = (all_arrows.transform.localPosition.z).ToString();
            x_mov_total_val = double.Parse(x_input.text);
            y_mov_total_val = double.Parse(y_input.text);
            z_mov_total_val = double.Parse(z_input.text);

            if (x_plus.x_plus_apply == true)
            {
                apply            = true;
                x_mov_total_val += .5;
                x_input.text     = x_mov_total_val.ToString();
                x_plus.apply_equals_false();
            }
            if (X_minus.x_minus_apply == true)
            {
                apply            = true;
                x_mov_total_val -= .5;
                x_input.text     = x_mov_total_val.ToString();
                X_minus.apply_equals_false();
            }
            if (Y_plus.y_plus_apply == true)
            {
                apply            = true;
                y_mov_total_val += .5;
                y_input.text     = y_mov_total_val.ToString();
                Y_plus.apply_equals_false();
            }
            if (Y_minus.y_minus_apply == true)
            {
                apply            = true;
                y_mov_total_val -= .5;
                y_input.text     = y_mov_total_val.ToString();
                Y_minus.apply_equals_false();
            }
            if (Z_plus.z_plus_apply == true)
            {
                apply            = true;
                z_mov_total_val += .5;
                z_input.text     = z_mov_total_val.ToString();
                Z_plus.apply_equals_false();
            }
            if (Z_minus.z_minus_apply == true)
            {
                apply            = true;
                z_mov_total_val -= .5;
                z_input.text     = z_mov_total_val.ToString();
                Z_minus.apply_equals_false();
            }
            if (apply == true)
            {
                PlayerPrefs.SetInt("player_prefs_arrows", 1);
                all_arrows.transform.localPosition = new Vector3(float.Parse(x_input.text), float.Parse(y_input.text), float.Parse(z_input.text));
                PlayerPrefs.SetFloat("arrows_transform_x", all_arrows.transform.localPosition.x);
                PlayerPrefs.SetFloat("arrows_transform_y", all_arrows.transform.localPosition.y);
                PlayerPrefs.SetFloat("arrows_transform_z", all_arrows.transform.localPosition.z);
                apply = false;
                break;
            }
            else
            {
                break;
            }
        }
    }