Skip to content

Instantly share code, notes, and snippets.

View SiarheiPilat's full-sized avatar
🍌
Working from home

spilat12 SiarheiPilat

🍌
Working from home
View GitHub Profile
@SiarheiPilat
SiarheiPilat / RemoveEventFromAnimator.cs
Last active November 23, 2019 20:19
Unity animation events or AnimationUtility API does not contain methods for deleting animation clip events at runtime. The following code makes it possible.
/// <summary>
/// Unity animation events or AnimationUtility API does not contain methods for deleting animation clip events at runtime.The following code makes it possible.
/// Taken from (with a minor bug fix): https://forum.unity.com/threads/remove-animation-event.78957/
/// </summary>
public static void RemoveEventFromAnimator(string functionName, Animator animator)
{
AnimatorClipInfo animationClipInfo = animator.GetCurrentAnimatorClipInfo(0)[0];
AnimationClip animationClip = animationClipInfo.clip;
using UnityEngine;
/// <summary>
/// The following script converts camera viewport corners' coordinates from viewport to world space.
/// </summary>
public class ScreenCornersToWorld : MonoBehaviour
{
public Camera Camera;
public Vector3 BottomLeftCorner, TopLeftCorner, TopRightCorner, BottomRightCorner;
using UnityEngine;
using UnityEditor;
/// <summary>
/// Copies pivot from one sprite to another.
/// Adapted from: https://forum.unity.com/threads/copy-spritesheet-slices-and-pivots-solved.301340/
/// </summary>
[CanEditMultipleObjects]
public class SpritePivotCopier : EditorWindow
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
/// <summary>
///
/// Copies the pivot coordinates of a first slice of the spritesheet and applies them to the pivots of other slices in the same spritesheet.
/// This script only works for spritesheets that were sliced using the grid option.
/// How to: select your spritesheet in the project files and go to the menu item to run the command.
///
using UnityEngine;
using UnityEditor;
using System.Reflection;
public class ActiveEditorWindowValidator : MonoBehaviour
{
/// <summary>
/// Checks whether an active window is a window that you require, for example: ValidateEditorWindow("UnityEditor.AnimationWindow");
/// </summary>
bool ValidateEditorWindow(string EditorWindowType)
@SiarheiPilat
SiarheiPilat / ScriptableObjectUtility.cs
Created November 23, 2019 22:20
Create a ScriptableObject from script.
using UnityEngine;
using UnityEditor;
using System.IO;
public static class ScriptableObjectUtility
{
/// <summary>
/// Create, name and place unique new ScriptableObject asset files.
/// Taken from: https://wiki.unity3d.com/index.php/CreateScriptableObjectAsset
/// </summary>
@SiarheiPilat
SiarheiPilat / EditorSceneAutosave.cs
Created November 25, 2019 22:55
This tiny class will Autosave your project whenever you play your scene!
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
// Credit goes to Comp-3 Interactive, thanks for sharing the script!
// This tiny class will Autosave your project whenever you play your scene!
[InitializeOnLoad]
public class Autosave
{
@SiarheiPilat
SiarheiPilat / BezierCurve3PointLineRenderer.cs
Created December 17, 2019 00:15
Bezier Curve Line Renderer for Unity, credit goes to World of Zero: https://www.youtube.com/watch?v=tgCFzoG_BJM
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Bezier Curve Line Renderer for Unity, credit goes to World of Zero: https://www.youtube.com/watch?v=tgCFzoG_BJM
/// </summary>
[ExecuteInEditMode]
public class BezierCurve3PointLineRenderer : MonoBehaviour
{
@SiarheiPilat
SiarheiPilat / ScriptAutoRefreshControl.cs
Created January 15, 2020 15:38
Turns Auto Refresh option (script recompilation, domain reload) on and off.
using UnityEngine;
using UnityEditor;
public class ScriptAutoRefreshControl : MonoBehaviour
{
/// <summary>
/// Turns Auto Refresh option on and off (it is about script recompilation, domain reload).
/// Same as going to Edit -> Preferences -> General and changing Auto Refresh option.
/// </summary>
@SiarheiPilat
SiarheiPilat / PerformanceEnhancer.cs
Created April 29, 2020 07:56
Computes distances between vectors faster than Vector3.Distance() or Vector2.Distance()
using UnityEngine;
/// <summary>
/// Vector3.Distance(a,b) is the same as (a-b).magnitude
/// Since computing squared magnitudes is faster than Vector3.magnitude, (a - b).sqrMagnitude is more performant than Vector3.Distance
/// </summary>
public class PerformanceEnhancer : MonoBehaviour
{
public static float Distance(Vector3 a, Vector3 b)