Skip to content

Instantly share code, notes, and snippets.

@takoyakiroom
Created August 25, 2016 15:29
Show Gist options
  • Save takoyakiroom/2c140f0bdb257f24966dd89d35fb34f6 to your computer and use it in GitHub Desktop.
Save takoyakiroom/2c140f0bdb257f24966dd89d35fb34f6 to your computer and use it in GitHub Desktop.
CPU使用率DLL使う側(Unity)
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