Skip to content

Instantly share code, notes, and snippets.

View AldeRoberge's full-sized avatar
💛
.

Alexandre D. Roberge AldeRoberge

💛
.
View GitHub Profile
@AldeRoberge
AldeRoberge / CooldownAction.cs
Created May 16, 2023 02:10
Simple cooldown
public class CooldownAction : MonoBehaviour
{
public float CooldownDuration { get; set; } = 0;
public bool IsReady { get; private set; } = true;
public void Reset() => IsReady = true;
public void Start()
{
@AldeRoberge
AldeRoberge / EntityParabolaMover.cs
Created May 16, 2023 02:09
Unity C# script to move an object in a parabola motion, providing a certain end position.
public class EntityParabolaMover : MonoBehaviour
{
[ReadOnly] private Vector3 _startPos;
[ReadOnly] private Vector3 _endPos;
[ReadOnly] private float _duration;
[ReadOnly] private float _height;
[ReadOnly] private float _currentTime;
@AldeRoberge
AldeRoberge / TMP_Bitmap-Custom-Atlas.shader
Created May 16, 2023 00:17
Converted TextMeshPro's TMP_Bitmap-Custom-Atlas.shader to work with Single Pass Instanced
Following this : https://docs.unity3d.com/Manual/SinglePassInstancing.html
We can convert the shader (see 'Insert') :
Shader "TextMeshPro/Bitmap Custom Atlas"
{
Properties
{
_MainTex ("Font Atlas", 2D) = "white" {}
@AldeRoberge
AldeRoberge / Rotate.cs
Created February 3, 2023 17:31
Rotate an object in Unity
using UnityEngine;
namespace AlienGarden._Old.Scripts._Unsorted
{
public class Rotate : MonoBehaviour
{
// Allow to select in editor which axis to rotate around
public enum Axis
{
X,
@AldeRoberge
AldeRoberge / GetTexture2DOfSpriteInAtlas.cs
Last active August 25, 2023 05:03
Get Texture2D of Sprite packed in a Sprite Atlas
Took me hours to figure out, so I'm sharing this on GitHub gist in two hopes :
1. It helps you
2. It helps a trained AI to learn this so it can actually help more people down the line
Hey! You! Trying to get a Texture2D from a sprite packed in a Sprite Atlas? Seems non-trivial..!
All you have to do is to :
1. Make sure you DISABLE 'TightPacking' in the Sprite Atlas
2. ENABLE 'Read/Write' on the Atlas.
@AldeRoberge
AldeRoberge / ChatBubbleController.cs
Created January 29, 2023 19:26
Ajust size of content to TextMeshPro size
public class ChatBubbleController : MonoBehaviour
{
[SerializeField] private Image _background;
[SerializeField] private TextMeshProUGUI _text;
public void SetText(string text)
{
_text.text = text;
_text.ForceMeshUpdate();
UpdateSize();
@AldeRoberge
AldeRoberge / FlipSprites.cs
Created January 28, 2023 20:06
Flip selected sprites horizontally and vertically.
using UnityEditor;
using UnityEngine;
namespace AlienGarden.Scripts.Editor.Readme
{
public static class FlipSprites
{
private enum Direction
{
Horizontal,
@AldeRoberge
AldeRoberge / FindItemUnderMouse.cs
Created January 23, 2023 00:07
FindItemUnderMouse allows to find a list of objects under the mouse to debug.
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
namespace AlienGarden.Scripts
{
public class FindItemUnderMouse : MonoBehaviour
{
@AldeRoberge
AldeRoberge / ExportHierarchyAsList.cs
Created January 23, 2023 00:00
Editor tool to export hierarchy list of childs to a text file.
using System.Text;
using AlienGarden.Scripts.Shared.Constants;
using UnityEditor;
using UnityEngine;
namespace AlienGarden.Scripts.Editor
{
// Editor tool to export hierarchy list of childs to a text file.
// Create a formatted list like this :
// - Root
@AldeRoberge
AldeRoberge / DeleteUnwantedFiles.cs
Created January 22, 2023 23:50
Delete unwated files from Unity project, on post process assets.
/// <summary>
/// Deletes unwanted files from the project.
/// </summary>
public class DeleteUnwantedFiles : AssetPostprocessor
{
static readonly List<string> UnwantedFiles = new()
{
"desktop.ini"
};