Unity Get Steam Friends

[Solved] Unity Get Steam Friends | Shell - Code Explorer | yomemimo.com
Question : Unity Get Steam Friends

Answered by : vexeval

using System.Collections;
using System.Collections.Generic;
using Steamworks;
using UnityEngine;
public class QueryFriendsList : MonoBehaviour
{ private Callback<PersonaStateChange_t> m_PersonaStateChange; private void OnEnable() { if (SteamManager.Initialized) { // Register the callback for receiving notifications when the player's friends list changes m_PersonaStateChange = Callback<PersonaStateChange_t>.Create(OnPersonaStateChange); } } private void OnDisable() { if (SteamManager.Initialized) { // Unregister the callback m_PersonaStateChange.Dispose(); } } private void OnPersonaStateChange(PersonaStateChange_t pCallback) { // Check if this callback is for the player's friends list changing if (pCallback.m_ulChangeFlags == (uint)EPersonaChange.k_EPersonaChangeFriendList) { // The player's friends list has changed, so we can query it to get the current list of friends int friendCount = SteamFriends.GetFriendCount(EFriendFlags.k_EFriendFlagImmediate); Debug.Log($"Player has {friendCount} friends."); for (int i = 0; i < friendCount; i++) { CSteamID friendId = SteamFriends.GetFriendByIndex(i, EFriendFlags.k_EFriendFlagImmediate); string friendName = SteamFriends.GetFriendPersonaName(friendId); Debug.Log($"Friend {i + 1}: {friendName} ({friendId.ToString()})"); // Log each friend's name and Steam ID } } }
}

Source : | Last Update : Sat, 21 Jan 23

Answers related to unity get steam friends

Code Explorer Popular Question For Shell