Created
August 25, 2016 15:29
-
-
Save takoyakiroom/2c140f0bdb257f24966dd89d35fb34f6 to your computer and use it in GitHub Desktop.
CPU使用率DLL使う側(Unity)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using UnityEngine.UI; | |
using System.Runtime.InteropServices; | |
public class CPUUsage : MonoBehaviour { | |
[DllImport("CPUUsage")] | |
private static extern void StartCPUUsage(uint usage); | |
[DllImport("CPUUsage")] | |
private static extern long GetCPUUsage(); | |
// Use this for initialization | |
void Start () { | |
// CPU測定開始(1000m秒毎) | |
StartCPUUsage(1000); | |
} | |
// Update is called once per frame | |
void Update () { | |
// 測定結果取得 | |
long usage = GetCPUUsage(); | |
this.GetComponent<Text>().text = string.Format("CPU {0,3}%", usage.ToString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment