alap
This commit is contained in:
15
Assets/Scripts/Extensions/ArrayExtension.cs
Normal file
15
Assets/Scripts/Extensions/ArrayExtension.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
|
||||
public static class ArrayExtension
|
||||
{
|
||||
|
||||
public static T GetRandomFromArray<T>(T[] array)
|
||||
{
|
||||
if (array.Length > 0)
|
||||
{
|
||||
return array[Random.Range(0, array.Length)];
|
||||
}
|
||||
return default;
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/Extensions/ArrayExtension.cs.meta
Normal file
11
Assets/Scripts/Extensions/ArrayExtension.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c0653a9321e8014ea8aaade33c69f45
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
49
Assets/Scripts/Extensions/MonoBehaviourExtensions.cs
Normal file
49
Assets/Scripts/Extensions/MonoBehaviourExtensions.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public static class MonoBehaviourExtensions
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This will Call a method wtih a delay (including being able to use delegates unlike Invoke(nameof(method), delay);)
|
||||
/// </summary>
|
||||
/// <param name="mono"></param>
|
||||
/// <param name="method"></param>
|
||||
/// <param name="delay"></param>
|
||||
public static void CallWithDelay(this MonoBehaviour mono, Action method, float delay)
|
||||
=> mono.StartCoroutine(CallWithDelayRoutine(method, delay));
|
||||
|
||||
static IEnumerator CallWithDelayRoutine(Action method, float delay)
|
||||
{
|
||||
yield return new WaitForSeconds(delay);
|
||||
method();
|
||||
}
|
||||
|
||||
|
||||
public static GameObject[] ShuffleList(this MonoBehaviour mono, List<GameObject> list)
|
||||
{
|
||||
GameObject[] array = list.ToArray();
|
||||
|
||||
// Shuffle the array using Fisher-Yates algorithm
|
||||
for (int i = 0; i < array.Length - 1; i++)
|
||||
{
|
||||
int randomIndex = UnityEngine.Random.Range(i, array.Length);
|
||||
GameObject temp = array[i];
|
||||
array[i] = array[randomIndex];
|
||||
array[randomIndex] = temp;
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
public static float RoundValue(float value, int decimalAmount)
|
||||
{
|
||||
float multiplier = Mathf.Pow(10.0f, decimalAmount);
|
||||
return Mathf.Round(value * multiplier) / multiplier;
|
||||
}
|
||||
|
||||
}
|
||||
|
11
Assets/Scripts/Extensions/MonoBehaviourExtensions.cs.meta
Normal file
11
Assets/Scripts/Extensions/MonoBehaviourExtensions.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8546b79ebab6cc544b7e02354332a262
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
56
Assets/Scripts/Extensions/SteamHelper.cs
Normal file
56
Assets/Scripts/Extensions/SteamHelper.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using Steamworks;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public static class SteamHelper
|
||||
{
|
||||
|
||||
public static Texture2D GetAvatar(CSteamID steamID)
|
||||
{
|
||||
int imageID = SteamFriends.GetLargeFriendAvatar(steamID);
|
||||
if (imageID == -1) return null;
|
||||
|
||||
Texture2D texture = null;
|
||||
|
||||
bool isValid = SteamUtils.GetImageSize(imageID, out uint width, out uint height);
|
||||
|
||||
if (isValid)
|
||||
{
|
||||
byte[] image = new byte[width * height * 4];
|
||||
|
||||
isValid = SteamUtils.GetImageRGBA(imageID, image, (int)(width * height * 4));
|
||||
|
||||
if (isValid)
|
||||
{
|
||||
texture = new Texture2D((int)width, (int)height, TextureFormat.RGBA32, false, false);
|
||||
texture.LoadRawTextureData(image);
|
||||
texture.Apply();
|
||||
}
|
||||
}
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Sprite ConvertTextureToSprite(Texture2D texture)
|
||||
{
|
||||
return Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
|
||||
}
|
||||
|
||||
|
||||
public static List<CSteamID> GetMembersInLobby()
|
||||
{
|
||||
List<CSteamID> members = new List<CSteamID>();
|
||||
int memberAmount = SteamMatchmaking.GetNumLobbyMembers(SteamLobby.LobbyID);
|
||||
|
||||
for (int i = 0; i < memberAmount; i++)
|
||||
{
|
||||
CSteamID cSteamID = SteamMatchmaking.GetLobbyMemberByIndex(SteamLobby.LobbyID, i);
|
||||
members.Add(cSteamID);
|
||||
}
|
||||
|
||||
return members;
|
||||
}
|
||||
}
|
||||
|
11
Assets/Scripts/Extensions/SteamHelper.cs.meta
Normal file
11
Assets/Scripts/Extensions/SteamHelper.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7faf9027c4eb4594798d708da42bd056
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user