//'Each' mode private void UpdateForEashTye(CpuRateInfo info) { float total = info.user; UserBarFill = total / 100f; total += info.nice; NiceBarFill = total / 100f; total += info.system; SystemBarFill = total / 100f; IdleBarFill = 1f; }
//'UseGrad' mode private void UpdateForUseGradTye(CpuRateInfo info) { NiceBarFill = 0f; SystemBarFill = 0f; IdleBarFill = 1f; float rate = (info.user + info.nice + info.system) / 100f; UserBarFill = rate; if (useGradColor != null) { UserBarColor = useGradColor.Evaluate(rate); } }
// Update is called once per frame //private void Update () { //} //'CpuRateInfo' to bar public void SetCpuRate(CpuRateInfo info) { if (nameText != null) { nameText.text = info.name.ToUpper() + " : "; } switch (barType) { case BarType.Each: UpdateForEashTye(info); break; case BarType.UseGrad: UpdateForUseGradTye(info); break; } }
//Callback handler for CPU Rate information. private void ReceiveStatus(string json) { if (string.IsNullOrEmpty(json)) { return; } string[] items = json.Split('\n'); CpuRateInfo[] infos = new CpuRateInfo[items.Length]; for (int i = 0; i < infos.Length; i++) { infos[i] = JsonUtility.FromJson <CpuRateInfo>(items[i]); } if (OnStatus != null) { OnStatus.Invoke(infos); } }