画谱段

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

/// <summary>
/// 主界面的三层标的显示百分比
/// </summary>
public class TiaoFade : MonoBehaviour {

    public Text text_Name;

    public string name;

    public Toggle tog;

    public RectTransform[] first = new RectTransform[2];

    public RectTransform second, third;

    /// <summary>
    /// 第一个 隐现百分比  二三显示百分比
    /// </summary>
    public float[] percentages = new float[4];


    public float[] sizeData = new float[2];

    public float xL, xR;

    /// <summary>
    /// 边界
    /// </summary>
    public float sideLine1 = 17, sideline2 = 55.7f;
    void Update()
    {
        Percentage();
    }

    float ChangNum(float num)
    {
        if (num < 0)
        {
            num = 0;
        }
        else if (num <= 38)
        {
            num = num / 38 * sideLine1;
        }
        else if (num > 38 && num <= 100)
        {
            num = (sideline2 - sideLine1) / 62 * (num - 38) + sideLine1;
        }
        else if (num > 100)
        {
            num = (100 - sideline2) / 1400 * (num - 100) + sideline2;
        }
        return num;
    }

    /// <summary>
    /// 谱段条各个信息输入
    /// </summary>
    public void Percentage()
    {
        if(tog !=null)
            tog.isOn = gameObject.activeSelf;

        if(text_Name!=null)
            text_Name.text = name;


        first[0].sizeDelta = new Vector2((1 - ChangNum(xL) / 100) * 1706, first[1].sizeDelta.y);
        first[0].anchoredPosition = new Vector2(1706 * (ChangNum(xL) / 100 - 0.5f), first[0].anchoredPosition.y);

        sizeData[0] = first[0].sizeDelta.x;
        sizeData[1] = first[0].sizeDelta.y;

        first[1].GetComponent<Image>().fillAmount = ChangNum(xR) / 100;

        second.GetComponent<Image>().fillAmount = percentages[2]/100;

        if(third!=null)
            third.GetComponent<Image>().fillAmount = percentages[3]/100;

        transform.parent.gameObject.GetComponent<Sorting>().Sort();
    }
}

 

posted @ 2016-04-14 08:03  1A7487  阅读(209)  评论(0编辑  收藏  举报