Skip to content

Instantly share code, notes, and snippets.

View hasanbayatme's full-sized avatar
❤️
Perceiving Love

Hasan Bayat hasanbayatme

❤️
Perceiving Love
View GitHub Profile
@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
@hasanbayatme
hasanbayatme / GlobalVariables.cs
Last active November 17, 2023 09:14
A simple C# static class to get and set globally accessible variables through a key-value approach (C#, Unity, .NET)
using System.Collections.Generic;
/// <summary>
/// A simple static class to get and set globally accessible variables through a key-value approach.
/// </summary>
/// <remarks>
/// <para>Uses a key-value approach (dictionary) for storing and modifying variables.</para>
/// <para>It also uses a lock to ensure consistency between the threads.</para>
/// </remarks>
public static class GlobalVariables
@unitycoder
unitycoder / DebugLogColor.cs
Created February 18, 2020 09:49
Debug.Log with Color
Debug.Log("<color=#" + ColorUtility.ToHtmlStringRGB(col) + ">████████████</color> = " + col);
@cocowalla
cocowalla / Ecies.cs
Last active June 22, 2024 14:07
Simple ECIES implementation
using System;
using System.Security.Cryptography;
// ReSharper disable SuggestVarOrType_SimpleTypes - BCL rules
namespace Crypto
{
/// <summary>
/// Simple implementation of ECIES (Elliptic Curve Integrated Encryption Scheme) based on http://www.secg.org/sec1-v2.pdf, section 5.1
/// Things not implemented:
/// - Encoding parameters using compressed points; only uncompressed points are used
@hasanbayatme
hasanbayatme / ExtraEditorGUILayout.cs
Created July 14, 2019 05:00
Extra Editor GUI Layouot Methods for drawing GUI, such as ReadonlyTextArea, ReadonlyTextField and more.
using UnityEngine;
using UnityEditor;
public static class ExtraEditorGUILayout
{
public static void ReadonlyTextArea(string text, params GUILayoutOption[] options)
{
EditorGUILayout.SelectableLabel(text, EditorStyles.textArea, options);
}
@unitycoder
unitycoder / ContinueCoroutine.cs
Created June 18, 2019 19:27
Continue CoRoutine After Gameobject was disabled and then enabled (with .setActive)
// example script for restarting Coroutine after gameobject was disabled (and continue from previous timer value)
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class ContinueCoroutine : MonoBehaviour
{
public float duration = 5f;
@cjddmut
cjddmut / ValueTypeLists.cs
Last active September 13, 2024 15:20
C# struct based lists that can be created, passed around, and released without references or garbage.
/*
* Created by Galvanic Games (http://galvanicgames.com)
*
* The MIT License (MIT)
*
* Copyright (c) 2019
*
* 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
Texture2D[] layers;
Texture2D compiledTexture = new Texture2D(layers[0].width, layers[0].height);
foreach(Texture2D layer in layers){
Color[] baseColors = compiledTexture.GetPixels();
Color[] layerColors = layer.GetPixels();
for(int p = 0; p < baseColors.Length; p++){
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
// This is only useful for spritesheets that need to be automatically sliced (Sprite Editor > Slice > Automatic)
public class AutoSpriteSlicer
{
[MenuItem("Tools/Slice Spritesheets %&s")]
@hasanbayatme
hasanbayatme / MinMax.cs
Last active November 23, 2020 16:00
Unity Min Max Slider Implementation
using System;
using UnityEngine;
[Serializable]
public struct MinMax
{
[SerializeField]
private float min;
[SerializeField]