Skip to content

Instantly share code, notes, and snippets.

public class PoolList<T>
{
public List<(bool IsAvailable, T type)> Pool = new();
public (bool success, (bool IsAvailable, T instance) item) TryGetFromPool(out T value)
{
for (int i = 0; i < Pool.Count; i++)
{
var item = Pool[i];
@st4rdog
st4rdog / TerrainColorTint.cs
Last active May 6, 2024 03:04
Unity Terrain - Tint TerrainLayers. Gets TerrainLayers assets used on selected terrain and applies tint/color.
using System.Collections.Generic;
using UnityEngine;
// https://gist.github.com/st4rdog/40fc14a8a256c2376ba121bca33d7571
// Gets TerrainLayers assets used on selected terrain and applies tint/color.
// TerrainLayer color can be changed in Debug inspector view.
public class TerrainColorTint : MonoBehaviour
{
public List<Terrain> Terrains = new();
public List<Color> TargetColors = new();
@st4rdog
st4rdog / PrivacyPolicy.txt
Created November 30, 2023 22:14
PrivacyPolicy
Privacy Policy for One Brutal Dungeon
No Data Collection:
One Brutal Dungeon does not collect, store, or transmit any user data.
Contact:
If you have any questions or concerns regarding this Privacy Policy, please contact us at stardoggames@gmail.com.
@st4rdog
st4rdog / ListNonAlloc.cs
Last active July 4, 2024 16:18
Unity C# - Garbage-free List with Add/Remove functions
// Drop-in replacement for List<T>. Presized List so no garbage when adding/removing.
// Further reading:
// - Collections without the boxing - https://www.jacksondunstan.com/articles/5148
// - https://stackoverflow.com/questions/3737997/why-implement-ienumerablet-if-i-can-just-define-one-getenumerator
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@st4rdog
st4rdog / FPSCounter.cs
Last active November 27, 2023 17:35
Unity C# FPS Counter - Add to any GameObject, then assign any Text using inspector.
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FPSCounter : MonoBehaviour
{
public enum DeltaTimeType
{
Smooth,
@st4rdog
st4rdog / FSM.cs
Last active January 17, 2024 22:51
C# Finite State Machine for Unity
using System;
using System.Collections.Generic;
using UnityEngine;
/* Example usage:
public FSM GameFSM = new();
private void Awake()
{
GameFSM.AddState("Init",
@st4rdog
st4rdog / msi-afterburner-undervolt-how-to.md
Last active July 14, 2024 04:05
MSI Afterburner Voltage Curve Editor Tutorial - Undervolt

Tutorial

  • Start at default curve.
  • Ctrl-click-drag any point in right-half to bend it until a point intersects with desired mhz/voltage.
  • Select point and adjust to perfection using shift-up-down.
  • Shift-click-drag empty space and select points (including selected point) on the right. Selected point should be left-most point.
  • Shift-Enter twice to flatten all points in selection area. They will flatten to match the selected point.
  • Adjust if required.

Controls

@st4rdog
st4rdog / SmoothMouseLook.cs
Last active October 14, 2022 21:59
Unity - Smoothed mouse look for an FPS
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SmoothMouseLook : MonoBehaviour
{
private List<float> _xBuffer = new List<float>();
private List<float> _yBuffer = new List<float>();
private int _bufferIndex;
@st4rdog
st4rdog / Messaging.cs
Created December 20, 2021 01:23
Event/Messaging system for C# - strongly typed
// Created by lordofduct - https://forum.unity.com/threads/recommended-event-system.856294/#post-5644981
//
// Usage example:
//
// public delegate void OnDiedEvent(GameObject go);
//
// Messaging<OnDiedEvent>.Trigger?.Invoke(gameObject);
//
// Messaging<OnDiedEvent>.Register(go => {
// Debug.Log($"{go.name} died.");
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.UI;
namespace UIGradient
{
[AddComponentMenu("UI/Effects/Gradient")]
public class Gradient : BaseMeshEffect
{