Skip to content

Instantly share code, notes, and snippets.

@hasanbayatme
hasanbayatme / AnimatorUtility.cs
Last active March 16, 2024 18:55
Unity animator utilities such as checking if the animator has parameter or safely setting the animator parameters.
/**
MIT License
Copyright (c) 2023 Bayat Games
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@yasirkula
yasirkula / ScrollViewFocusFunctions.cs
Created October 23, 2021 10:09
Focus/center Scroll View to the specified point/item in Unity
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public static class ScrollViewFocusFunctions
{
public static Vector2 CalculateFocusedScrollPosition( this ScrollRect scrollView, Vector2 focusPoint )
{
Vector2 contentSize = scrollView.content.rect.size;
Vector2 viewportSize = ( (RectTransform) scrollView.content.parent ).rect.size;
@OscarAbraham
OscarAbraham / PlainDataInstancer.cs
Last active March 18, 2024 15:58
PlainDataInstancer ScriptableObject for Unity, so you can create deep clones of data stored in SO assets at runtime without the overhead of ScriptableObject copies.
using System.Collections.Generic;
using UnityEngine;
// TData should be a plain class or struct with the [System.Serializable] attribute.
// TData can implement ISerializationCallbackReceiver if needed for more advanced uses.
public class PlainDataInstancer<TData> : ScriptableObject
{
private static bool s_DataTypeValidated;
[SerializeField] private TData m_PrototypeData;
@Kryzarel
Kryzarel / EasingFunctions.cs
Last active November 8, 2024 17:23
C# Easing Functions
using System;
namespace Kryz.Tweening
{
// Made with the help of this great post: https://joshondesign.com/2013/03/01/improvedEasingEquations
// --------------------------------- Other Related Links --------------------------------------------------------------------
// Original equations, bad formulation: https://github.com/danro/jquery-easing/blob/master/jquery.easing.js
// A few equations, very simplified: https://gist.github.com/gre/1650294
// Easings.net equations, simplified: https://github.com/ai/easings.net/blob/master/src/easings/easingsFunctions.ts