Exemplo n.º 1
0
    public void UpdatePercentageDisplay()
    {
        DroneStatSet currentStats;
        DroneStatSet maxStats;

        if (drone == null)
        {
            return;
        }

        drone.GetDroneStats(out currentStats, out maxStats);

        // Stat percentages for both bar and text display
        float hp = currentStats.Health / maxStats.Health;
        float pp = currentStats.Power / maxStats.Power;
        float rp = 0.0f;

        if (currentStats.Storage != 0.0f)
        {
            rp = currentStats.Storage / maxStats.Storage;
        }

        /*// Bar relative y locations
         * float hpos = (int)(hp * (-0.5 * barWidth));
         * float ppos = (int)(pp * (-0.5 * barWidth));
         * float rpos = (int)(rp * (-0.5 * barWidth));
         *
         * // Bar widths
         * float hw = (int)(hp * barWidth);
         * float pw = (int)(pp * barWidth);
         * float rw = (int)(rp * barWidth);*/

        healthPercent.text   = "%" + (hp * 100).ToString("f2");
        powerPercent.text    = "%" + (pp * 100).ToString("f2");
        resourcePercent.text = "%" + (rp * 100).ToString("f2");

        healthBar.size   = Mathf.Clamp(hp, 0.0f, 1.0f);
        powerBar.size    = Mathf.Clamp(pp, 0.0f, 1.0f);
        resourceBar.size = Mathf.Clamp(rp, 0.0f, 1.0f);
    }