using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
public class SizeCompute : MonoBehaviour
{
public Text SumSize;//显示最终结果的Text
public Button SubmitBtn;//提交按钮
public GameObject Ruler;//点击确定按钮后要显示的工具
float sum = 0;
/// <summary>
/// 标记
/// </summary>
public List<Toggle> togList;
void Start()
{
for (int i = 0; i < togList.Count; i++)
{
int j = i;//依次执行加法操作,不加此句,会显示最终结果。
togList[j].onValueChanged.AddListener(delegate
{
this.OnValueAdd(togList[j]);
});
}
SubmitBtn.onClick.AddListener(delegate()
{
this.SubmitInfoOnClick();
});
}
void SubmitInfoOnClick()
{
if (sum > 0 && sum < 0.7f)
{
gameObject.SetActive(false);
Ruler.SetActive(true);
}
}
void OnMouseDrag()
{
Ruler.transform.position = Input.mousePosition;
}
void OnValueAdd(Toggle tog)
{
sum = 0;
for (int i = 0; i < togList.Count; i++)
{
if (togList[i].isOn)
{
sum += togList[i].GetComponent<data>().i;
}
}
SumSize.text = sum + "mm";
}
}
注:
运行结果:选中Toggle所显示的数值,在SumSize(Text)显示最终加法结果,点击确定的同时显示Ruler(尺子工具)。