NumberDrawer.SetNumberRapid C# (CSharp) Method

SetNumberRapid() public method

public SetNumberRapid ( int number ) : void
number int
return void
    public void SetNumberRapid(int number)
    {
        if (m_curNumber == number)
        {
            return;
        }
		
		m_curNumber = number;
		
		if(number == 0 && !FilledWithZero)		//0特殊处理一下
		{
            for (int i = 0; i < maxIntLenth; ++i)
            {
                if (i==0)
                {
                    m_numbers[i].GetComponent<UISprite>().spriteName = SurName + 0;
                    m_numbers[i].gameObject.SetActive(true);
                    m_numbers[i].LocalPositionX(0);
                }
                else
                {
                    m_numbers[i].gameObject.SetActive(false);
                }
            }
            return;
		}

        int curNumStartIndex = 0;
        int factor = 10;									//用来取某个位的数字的因子
        if (!FilledWithZero)
        {
            //第一遍找到开始的数字位置
            for (int i = 0; i < maxIntLenth; ++i)		//处理整数部分
            {
                int tempNumber = (number % factor) / (factor / 10);		//取出正在处理的位的数字
                if (tempNumber != 0)
                {
                    curNumStartIndex = maxIntLenth - 1 - i;
                }
                factor *= 10;
            }
        }

        factor = 10;
        string newName = "";
        for (int i = 0; i < maxIntLenth; ++i)
        {
            if (i < curNumStartIndex)
            {
                m_numbers[i].gameObject.SetActive(false);
            }
            else
            {
                int tempNumber = (number % factor) / (factor / 10);		//取出正在处理的位的数字
                m_numbers[i].gameObject.SetActive(true);
                newName = SurName + tempNumber;
                m_numbers[i].GetComponent<UISprite>().spriteName = newName;
				if(Align == NumberAlign.Center)
				{
					m_numbers[i].LocalPositionX((maxIntLenth - curNumStartIndex - 1) * NumberInterval / 2 - NumberInterval * (i - curNumStartIndex));	
				}
                else if(Align == NumberAlign.Left)
				{
					m_numbers[i].LocalPositionX((maxIntLenth - curNumStartIndex - 1) * NumberInterval - NumberInterval * (i - curNumStartIndex));
				}
				else if(Align == NumberAlign.Right)
				{
					m_numbers[i].LocalPositionX(- (i - curNumStartIndex) * NumberInterval);
				}
                factor *= 10;
            }
        }
    }
}

Usage Example

Exemplo n.º 1
0
    public override void OnUpdate()
    {
        base.OnUpdate();

        if (GlobalVars.CurStageData.TimeLimit > 0)          //限制时间的关卡
        {
            int min    = (int)GameLogic.Singleton.GetTimeRemain() / 60;
            int second = (int)GameLogic.Singleton.GetTimeRemain() % 60;
            m_minNumber.SetNumberRapid(min);
            m_secNumber.SetNumberRapid(second);

            if (GameLogic.Singleton.GetTimeRemain() > 0.01 && GameLogic.Singleton.GetTimeRemain() <= 15 && GameLogic.Singleton.GetGameFlow() == TGameFlow.EGameState_Playing)       //小于15秒播粒子
            {
                if (!m_hurryTimeParticle.activeSelf)
                {
                    m_hurryTimeParticle.SetActive(true);
                }
            }
            else                    //大于15秒关闭粒子
            {
                if (m_hurryTimeParticle.activeSelf)
                {
                    m_hurryTimeParticle.SetActive(false);
                }
            }
            m_timeBar.fillAmount = GameLogic.Singleton.GetTimeRemain() / GlobalVars.CurStageData.TimeLimit;
        }
    }
All Usage Examples Of NumberDrawer::SetNumberRapid