Skip to content

Instantly share code, notes, and snippets.

View adamski11's full-sized avatar

Adam adamski11

View GitHub Profile
@adamski11
adamski11 / ComponentVariable.cs
Last active March 20, 2023 16:39
A ComponentVariable<T> can be used as a mini dependancy injection system to allow for rapid prototyping and the referencing of values without having to hard set those references in your scripts.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using UnityEngine.Serialization;
/*To use this script, when you need to get a variable from another script/component, instead of directly
referencing the component and then the specific variable (e.g. rBody.velocity), you would make a "ComponentVariable"
@adamski11
adamski11 / TextureFlip.cs
Last active August 14, 2020 15:14
I have found no solution for flipping a texture in Unity that is particularly efficient without going into multi-threading, which may or may not be possible depending on the project at hand, as to truly flip the texture you have to move all the pixels in the image around to "flip" the image. I've attempted to create the most efficient method for…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TextureFlip
{
public static Texture2D FlipTexture(this Texture2D original)
{
int textureWidth = original.width;
int textureHeight = original.height;
@adamski11
adamski11 / NumberiseChildrenUtility.cs
Last active November 21, 2019 16:23
Use this in Unity to quickly give the children of a transform a number. You can use a prefix to replace their existing name, a suffix to add information after the number, and choose to start from zero.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode()]
public class NumberiseChildrenUtility : MonoBehaviour
{
//Use https://gist.github.com/adamski11/bd61693a1f90130c536d080496012ed9 to use a button in the inspector
//[TestButton("Numberise Children", "NumberiseChildren")]
[Header("Click to Run")]
@adamski11
adamski11 / FillBarGradientScript.cs
Last active July 3, 2020 11:12
Add this script to any game object with an image component you're using as a fill bar colour the bar based on the current fill amount and a gradient set by you. Works in the editor for testing as well.
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(Image))]
[ExecuteInEditMode]
public class FillBarGradientScript : MonoBehaviour
{
public Gradient gradient;
Image fillImage;