using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
///
/// 自定义图片数字
///
public class UI_NumberFontComponment : MonoBehaviour
{
///
/// 数字对象集合
///
private Dictionary elements = new Dictionary();
///
/// 当前数
///
private int _curNum = -1;
///
/// 设置
///
public int CurrentNum
{
get
{
return _curNum;
}
set
{
if (_curNum != value)
{
_curNum = value;
if (value < 0)
{
_curNum = 0;
}
onStarNumChanged();
}
}
}
///
/// 显示星星啦啦啦
///
private void onStarNumChanged()
{
elements.Clear();
//先清理掉其他不需要的
for (int i = this.transform.childCount - 1; i >= 0; i--)
{
Transform rc = this.transform.GetChild(i);
if (rc.name.IndexOf("Clone") < 0)
{
if (rc.name == "X" || rc.name == "+" || rc.name == "-")
{
}
else
{
rc.gameObject.GetComponent().ignoreLayout = true;
rc.gameObject.SetActive(false);
elements.Add(rc.name, rc.gameObject);
}
continue;
}
else
{
Destroy(rc.gameObject);
}
}
char[] arr = CurrentNum.ToString().ToCharArray();
foreach (char c in arr)
{
int id = System.Convert.ToInt32(c);
if (!elements.ContainsKey(c.ToString()))
{
continue;
}
GameObject go = elements[c.ToString()];
////创建新的
GameObject card = (GameObject)Instantiate(go);
card.transform.SetParent(this.transform);
card.transform.localScale = Vector3.one;
card.transform.localPosition = Vector3.zero;
card.GetComponent().ignoreLayout = false;
card.SetActive(true);
}
}
}