Skip to content

Instantly share code, notes, and snippets.

@Raveler
Raveler / ListExtensions.cs
Created February 1, 2024 08:26
Useful extension methods for Lists in C#
using System;
using System.Collections.Generic;
using System.Linq;
public static class ListExtensions
{
public static T MaxBy<T, U>(this IEnumerable<T> data, Func<T, U> f) where U : IComparable
{
if (data.Count() == 0) throw new ArgumentException($"Cannot get the max of an empty list.");
using UnityEngine;
using System.IO;
using System;
public static class RenderTextureExtensions
{
private static DefaultDictionary<RenderTexture, Texture2D> _cachedTextures = new DefaultDictionary<RenderTexture, Texture2D>();
using UnityEngine;
public static class TransformExtension
{
public static T[] GetAllComponentsInChildren<T>(this Transform transform)
{
return transform.GetComponentsInChildren<T>(true);
}
public static T[] GetAllComponentsInParent<T>(this Transform transform)
using System;
using UnityEngine;
//by Pepijn Willekens
// https://github.com/peperbol
// https://twitter.com/PepijnWillekens
public static class VectorExtension
{
public static Vector3 ChangeX(this Vector3 parent, float newX)
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Bombardel
{
public class BetterToggle : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler
{
String fileName = "test";
List<String> fileNames = new ArrayList<String>();
for (fileName : fileNames) {
// error?
}