Ejemplo n.º 1
0
    void Update()
    {
        //set the Update Category (is the HP going up, down, or not moving)
        if (Mathf.Round(Value * 100f) / 100f == Mathf.Round(NewValue * 100f) / 100f)
        {
            UpdateCategory = Categories.NA;
        }
        else if (Value > NewValue)
        {
            UpdateCategory = Categories.decrease;
        }
        else if (Value < NewValue)
        {
            UpdateCategory = Categories.increase;
        }

        //Update the Mask locations (needed if you are going to move stuff arround)
        RectTransform MRT = (Mask.transform as RectTransform);

        if (FillStyle == FillStyles.horizontal)
        {
            Mask1 = new Vector3(MRT.position.x, MRT.position.y, MRT.position.z);
            Mask0 = new Vector3(MRT.position.x - MRT.rect.width + MaskOffset, MRT.position.y, MRT.position.z);
        }
        else
        {
            Mask1 = new Vector3(MRT.position.x, MRT.position.y, MRT.position.z);
            Mask0 = new Vector3(MRT.position.x, MRT.position.y - MRT.rect.height + MaskOffset, MRT.position.z);
        }

        //move the Current Value to the NewValue
        Value = Mathf.Lerp(Value, NewValue, Speed * Time.deltaTime);
        Value = Mathf.Clamp(Value, 0f, 1f);      //make sure the Value is between 0 and 1

        //move the Filler position to display the Correct Percent
        RectTransform FRT = (Filler.transform as RectTransform);

        FRT.position = Vector3.Lerp(Mask0, Mask1, Value);

        //set the color for the Fill Image, and the Text Objects
        Filler.GetComponent <Image>().color    = HPColor.Evaluate(Value);
        PercentTxt.GetComponent <Text>().color = TextColor.Evaluate(Value);
        RatioTxt.GetComponent <Text>().color   = TextColor.Evaluate(Value);

        //Execute Each Criteria Rule
        foreach (CriteriaRule CR in CriteriaRules)
        {
            if (CR.isImage())
            {
                CR.DefaultColor = HPColor.Evaluate(Value);
            }
            else
            {
                CR.DefaultColor = TextColor.Evaluate(Value);
            }

            CR.Use(Mathf.Round(Value * 100f) / 100f);
        }

        //Execute Each Update Animation Rule
        foreach (UpdateAnimationRule UAR in UpdateAnimationRules)
        {
            if (StartAnimate)
            {
                if (UAR.Category.ToString() == UpdateCategory.ToString())
                {
                    UAR.StartAnimation = true;
                }
            }

            UAR.Use();
        }

        //reset the StartAnimate variable
        StartAnimate = false;

        //activate or inactivate the text objects
        PercentTxt.SetActive(DisplayPercentTxt);
        RatioTxt.SetActive(DisplayRatioTxt);

        //update the PercentTxt
        PercentTxt.GetComponent <Text>().text = (Mathf.Round(Value * 100f)).ToString() + "%";
    }