码迷,mamicode.com
首页 > 其他好文 > 详细

画谱段

时间:2016-04-14 08:13:09      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:

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();
    }
}

 

画谱段

标签:

原文地址:http://www.cnblogs.com/redUnity/p/5389682.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!