Files
2026-02-21 16:45:37 +08:00

158 lines
7.2 KiB
C#

using Steamworks;
using UnityEngine;
public class SteamUtilsTest : MonoBehaviour
{
private Vector2 m_ScrollPos;
private Texture2D m_Image;
protected Callback<IPCountry_t> m_IPCountry;
protected Callback<LowBatteryPower_t> m_LowBatteryPower;
protected Callback<SteamShutdown_t> m_SteamShutdown;
protected Callback<GamepadTextInputDismissed_t> m_GamepadTextInputDismissed;
private CallResult<CheckFileSignature_t> OnCheckFileSignatureCallResult;
public void OnEnable()
{
m_IPCountry = Callback<IPCountry_t>.Create(OnIPCountry);
m_LowBatteryPower = Callback<LowBatteryPower_t>.Create(OnLowBatteryPower);
m_SteamShutdown = Callback<SteamShutdown_t>.Create(OnSteamShutdown);
m_GamepadTextInputDismissed = Callback<GamepadTextInputDismissed_t>.Create(OnGamepadTextInputDismissed);
OnCheckFileSignatureCallResult = CallResult<CheckFileSignature_t>.Create(OnCheckFileSignature);
}
public static Texture2D GetSteamImageAsTexture2D(int iImage)
{
Texture2D texture2D = null;
uint pnWidth;
uint pnHeight;
if (SteamUtils.GetImageSize(iImage, out pnWidth, out pnHeight))
{
byte[] array = new byte[pnWidth * pnHeight * 4];
if (SteamUtils.GetImageRGBA(iImage, array, (int)(pnWidth * pnHeight * 4)))
{
texture2D = new Texture2D((int)pnWidth, (int)pnHeight, TextureFormat.RGBA32, false, true);
texture2D.LoadRawTextureData(array);
texture2D.Apply();
}
}
return texture2D;
}
public void RenderOnGUI()
{
GUILayout.BeginArea(new Rect(Screen.width - 200, 0f, 200f, Screen.height));
GUILayout.Label("Variables:");
GUILayout.Label("m_Image:");
GUILayout.Label(m_Image);
GUILayout.EndArea();
GUILayout.BeginVertical("box");
m_ScrollPos = GUILayout.BeginScrollView(m_ScrollPos, GUILayout.Width(Screen.width - 215), GUILayout.Height(Screen.height - 33));
GUILayout.Label("GetSecondsSinceAppActive() : " + SteamUtils.GetSecondsSinceAppActive());
GUILayout.Label("GetSecondsSinceComputerActive() : " + SteamUtils.GetSecondsSinceComputerActive());
GUILayout.Label("GetConnectedUniverse() : " + SteamUtils.GetConnectedUniverse());
GUILayout.Label("GetServerRealTime() : " + SteamUtils.GetServerRealTime());
GUILayout.Label("GetIPCountry() : " + SteamUtils.GetIPCountry());
uint pnWidth = 0u;
uint pnHeight = 0u;
bool imageSize = SteamUtils.GetImageSize(1, out pnWidth, out pnHeight);
GUILayout.Label("SteamUtils.GetImageSize(1, out ImageWidth, out ImageHeight) : " + imageSize + " -- " + pnWidth + " -- " + pnHeight);
if (GUILayout.Button("SteamUtils.GetImageRGBA(1, Image, (int)(ImageWidth * ImageHeight * 4)") && pnWidth != 0 && pnHeight != 0)
{
byte[] array = new byte[pnWidth * pnHeight * 4];
imageSize = SteamUtils.GetImageRGBA(1, array, (int)(pnWidth * pnHeight * 4));
MonoBehaviour.print(string.Concat("SteamUtils.GetImageRGBA(1, ", array, ", ", (int)(pnWidth * pnHeight * 4), ") - ", imageSize, " -- ", pnWidth, " -- ", pnHeight));
if (imageSize)
{
m_Image = new Texture2D((int)pnWidth, (int)pnHeight, TextureFormat.RGBA32, false, true);
m_Image.LoadRawTextureData(array);
m_Image.Apply();
}
}
uint unIP;
ushort usPort;
bool cSERIPPort = SteamUtils.GetCSERIPPort(out unIP, out usPort);
GUILayout.Label("GetCSERIPPort(out IP, out Port) : " + cSERIPPort + " -- " + unIP + " -- " + usPort);
GUILayout.Label("GetCurrentBatteryPower() : " + SteamUtils.GetCurrentBatteryPower());
GUILayout.Label("GetAppID() : " + SteamUtils.GetAppID());
if (GUILayout.Button("SetOverlayNotificationPosition(ENotificationPosition.k_EPositionTopRight)"))
{
SteamUtils.SetOverlayNotificationPosition(ENotificationPosition.k_EPositionTopRight);
MonoBehaviour.print(string.Concat("SteamUtils.SetOverlayNotificationPosition(", ENotificationPosition.k_EPositionTopRight, ")"));
}
GUILayout.Label("GetIPCCallCount() : " + SteamUtils.GetIPCCallCount());
GUILayout.Label("IsOverlayEnabled() : " + SteamUtils.IsOverlayEnabled());
GUILayout.Label("BOverlayNeedsPresent() : " + SteamUtils.BOverlayNeedsPresent());
if (GUILayout.Button("CheckFileSignature(\"FileNotFound.txt\")"))
{
SteamAPICall_t steamAPICall_t = SteamUtils.CheckFileSignature("FileNotFound.txt");
OnCheckFileSignatureCallResult.Set(steamAPICall_t);
MonoBehaviour.print("SteamUtils.CheckFileSignature(\"FileNotFound.txt\") : " + steamAPICall_t);
}
if (GUILayout.Button("ShowGamepadTextInput(EGamepadTextInputMode.k_EGamepadTextInputModeNormal, EGamepadTextInputLineMode.k_EGamepadTextInputLineModeSingleLine, \"Description Test!\", 32, \"test\")"))
{
bool flag = SteamUtils.ShowGamepadTextInput(EGamepadTextInputMode.k_EGamepadTextInputModeNormal, EGamepadTextInputLineMode.k_EGamepadTextInputLineModeSingleLine, "Description Test!", 32u, "test");
MonoBehaviour.print(string.Concat("SteamUtils.ShowGamepadTextInput(", EGamepadTextInputMode.k_EGamepadTextInputModeNormal, ", ", EGamepadTextInputLineMode.k_EGamepadTextInputLineModeSingleLine, ", \"Description Test!\", ", 32, ", \"test\") : ", flag));
}
GUILayout.Label("GetSteamUILanguage() : " + SteamUtils.GetSteamUILanguage());
GUILayout.Label("IsSteamRunningInVR() : " + SteamUtils.IsSteamRunningInVR());
if (GUILayout.Button("SetOverlayNotificationInset(400, 400)"))
{
SteamUtils.SetOverlayNotificationInset(400, 400);
MonoBehaviour.print("SteamUtils.SetOverlayNotificationInset(" + 400 + ", " + 400 + ")");
}
GUILayout.Label("IsSteamInBigPictureMode() : " + SteamUtils.IsSteamInBigPictureMode());
if (GUILayout.Button("StartVRDashboard()"))
{
SteamUtils.StartVRDashboard();
MonoBehaviour.print("SteamUtils.StartVRDashboard()");
}
GUILayout.Label("IsVRHeadsetStreamingEnabled() : " + SteamUtils.IsVRHeadsetStreamingEnabled());
if (GUILayout.Button("SetVRHeadsetStreamingEnabled(!SteamUtils.IsVRHeadsetStreamingEnabled())"))
{
SteamUtils.SetVRHeadsetStreamingEnabled(!SteamUtils.IsVRHeadsetStreamingEnabled());
MonoBehaviour.print("SteamUtils.SetVRHeadsetStreamingEnabled(" + !SteamUtils.IsVRHeadsetStreamingEnabled() + ")");
}
GUILayout.EndScrollView();
GUILayout.EndVertical();
}
private void OnIPCountry(IPCountry_t pCallback)
{
Debug.Log("[" + 701 + " - IPCountry]");
}
private void OnLowBatteryPower(LowBatteryPower_t pCallback)
{
Debug.Log("[" + 702 + " - LowBatteryPower] - " + pCallback.m_nMinutesBatteryLeft);
}
private void OnSteamShutdown(SteamShutdown_t pCallback)
{
Debug.Log("[" + 704 + " - SteamShutdown]");
}
private void OnCheckFileSignature(CheckFileSignature_t pCallback, bool bIOFailure)
{
Debug.Log("[" + 705 + " - CheckFileSignature] - " + pCallback.m_eCheckFileSignature);
}
private void OnGamepadTextInputDismissed(GamepadTextInputDismissed_t pCallback)
{
Debug.Log("[" + 714 + " - GamepadTextInputDismissed] - " + pCallback.m_bSubmitted + " -- " + pCallback.m_unSubmittedText);
if (pCallback.m_bSubmitted)
{
uint enteredGamepadTextLength = SteamUtils.GetEnteredGamepadTextLength();
Debug.Log("SteamUtils.GetEnteredGamepadTextLength() - " + enteredGamepadTextLength);
string pchText;
bool enteredGamepadTextInput = SteamUtils.GetEnteredGamepadTextInput(out pchText, pCallback.m_unSubmittedText + 1);
Debug.Log("SteamUtils.GetEnteredGamepadTextInput(out Text, pCallback.m_unSubmittedText + 1) - " + enteredGamepadTextInput + " -- " + pchText);
}
}
}