Hello everyone!
So, I am trying to work the OpenHardwareMonitorLib.dll with Unity to get some hardware stats displayed within Unity. I have added the plugin and it seems to be placed okay. I am getting some NullReferenceExceptions when I hit Play. Its because of the library for sure but I couldn’t figure out exactly how to fix that. Could anyone please share their experiences with it? Any help would be really appreciated!
The code I am using is as follows:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using OpenHardwareMonitor;
using OpenHardwareMonitor.Hardware;
using OpenHardwareMonitor.Collections;
public class MenuManager : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
GetSystemInfo();
}
// Update is called once per frame
void Update()
{
}
public class UpdateVisitor : IVisitor
{
public void VisitComputer(IComputer computer)
{
computer.Traverse(this);
}
public void VisitHardware(IHardware hardware)
{
hardware.Update();
foreach (IHardware subHardware in hardware.SubHardware) subHardware.Accept(this);
}
public void VisitSensor(ISensor sensor) { }
public void VisitParameter(IParameter parameter) { }
}
public static void GetSystemInfo()
{
UpdateVisitor updateVisitor = new UpdateVisitor();
Computer computer = new Computer();
computer.Open();
computer.CPUEnabled = true;
computer.Accept(updateVisitor);
for (int i = 0; i < computer.Hardware.Length; i++)
{
if (computer.Hardware*.HardwareType == HardwareType.CPU)*
{
for (int j = 0; j < computer.Hardware*.Sensors.Length; j++)*
{
if (computer.Hardware*.Sensors[j].SensorType == SensorType.Temperature)*
Console.WriteLine(computer.Hardware_.Sensors[j].Name + “:” + computer.Hardware*.Sensors[j].Value.ToString() + “\r”);
}
}
}
computer.Close();
}*_
}
[177006-logohm.png|177006]