// Update is called once per frame
    void Update()
    {
        float currentHP     = unit.GetCurrentHP();
        float maxHP         = unit.GetMaxHP();
        float HPPercentage  = currentHP / maxHP;
        int   TextureNumber = LayerHealthBarGUIDataArray.Length;
        float divisor       = 1f / (float)TextureNumber;
        int   currentForegroundTextureIndex = HPPercentage == 1 ? TextureNumber - 1 : (int)(HPPercentage * 100) / (int)(divisor * 100);

        topLayeredHealthbar = LayerHealthBarGUIDataArray[currentForegroundTextureIndex];
        if (currentForegroundTextureIndex != 0)
        {
            bottomLayedHealthbar = LayerHealthBarGUIDataArray[currentForegroundTextureIndex - 1];
        }
        else
        {
            bottomLayedHealthbar = null;
        }
        float divisorHP = divisor * maxHP;

        topLayeredHealthbar.realtimeHealthPercentage = (currentHP % divisorHP == 0) ? 1 : (currentHP % divisorHP) / divisorHP;

        topLayeredHealthbar.realtimeColor = Color.Lerp(LayerHealthBarGUIDataArray[currentForegroundTextureIndex].ZeroHealthColor,
                                                       LayerHealthBarGUIDataArray[currentForegroundTextureIndex].FullHealthColor,
                                                       topLayeredHealthbar.realtimeHealthPercentage);

        LocationRect                = HealthBarLocation.GetBound();
        RectOfHealthRealtime        = new Rect(LocationRect);
        RectOfHealthRealtime.width *= topLayeredHealthbar.realtimeHealthPercentage;
        foreach (AdaptiveIcon adaptiveIcon in adaptiveIcons)
        {
            adaptiveIcon.realtimeRect = adaptiveIcon.adaptiveRect.GetBound();
        }
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        thevalue = unit.GetCurrentHP();
        float percentage   = Mathf.Clamp01(thevalue / theMaxValue);
        Rect  LocationRect = HealthBarLocation.GetBound();

        RectOfHealthRealtime        = new Rect(LocationRect);
        RectOfHealthRealtime.width *= percentage;
        theTextCoord        = new Rect(TextCoord);
        theTextCoord.width *= percentage;
        theColor            = Color.Lerp(endColor, startColor, percentage);
        if (wink == false && percentage <= winkValue)
        {
            wink = true;
        }
        if (wink == true && percentage > winkValue)
        {
            wink = false;
            show = true;
        }
        if (wink)
        {
            if ((Time.time - lastChangeShowHideTime) >= 0.1f)
            {
//				Debug.Log("winking:"+Time.frameCount);
                show = !show;
                lastChangeShowHideTime = Time.time;
            }
        }
    }