Skip to content

Instantly share code, notes, and snippets.

View jfranmora's full-sized avatar

JfranMora jfranmora

View GitHub Profile
@jfranmora
jfranmora / DebugDrawGameObjectMesh.cs
Last active February 21, 2017 13:23
Debug meshes
using UnityEngine;
public class DebugDrawGameObjectMesh : MonoBehaviour
{
[Header("Configuration")]
[Space]
public bool drawWireMesh = true;
public Color wireColor = new Color(0, 0, 0, .8f);
@jfranmora
jfranmora / AnimatorEventsGenerator.cs
Created June 26, 2018 20:47
Function to autogenerate a script with the events of an animator as Unity Events ^^ (Works for events with 0 arguments)
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;
public class AnimatorEventsGenerator
{
private const string ScriptTemplate = "// AUTOGENERATED CODE: {CLASSNAME}\n" +
"\nusing UnityEngine;" +
@jfranmora
jfranmora / StringTagExt.cs
Last active June 26, 2022 13:52
Extension class to use rich text in Unity Console. https://docs.unity3d.com/Manual/StyledText.html
public static class StringTagExt
{
public static string AddBoldTag(this string text)
{
return text.AddTag("b");
}
public static string AddItalicTag(this string text)
{
return text.AddTag("i");
@jfranmora
jfranmora / CompileBeforePlay.cs
Last active June 25, 2020 08:47
Editor extension, automatically triggers a compilation when entering play mode.
using UnityEditor;
namespace JfranMora
{
public static class CompileBeforePlay
{
[InitializeOnLoadMethod]
public static void Initialize()
{
if (EditorApplication.isPlaying) return;
@jfranmora
jfranmora / UIExtensions.cs
Created July 16, 2019 19:00
Extension for Unity.UI.Toggle to set isOn value without send callbacks
using System.Reflection;
using UnityEngine.UI;
public static class UIExtensions
{
private static readonly MethodInfo toggleMethod;
static UIExtensions()
{
toggleMethod = GetSetMethod(typeof(Toggle));
@jfranmora
jfranmora / RemoveMobileWarningWebGL.cs
Last active September 20, 2019 12:15
PostBuildAction to Remove Mobile Warning in WebGL builds
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
public class RemoveMobileWarningWebGL
{
private const string JS_EXTENSION = ".js";
[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget target, string targetPath)
using System.Collections;
using UnityEngine;
/// <summary>
/// GC friendly coroutine utilities
/// @JfranMora #UnityTips
/// </summary>
public static class CoroutineUtils
{
public static IEnumerator WaitForSeconds(float seconds)
@jfranmora
jfranmora / ReadOnlyAttribute.cs
Last active November 22, 2023 16:12
Custom property attribute to make ReadOnly variables in Unity Inspector
using UnityEngine;
public class ReadOnlyAttribute : PropertyAttribute
{
}
@jfranmora
jfranmora / EditorCoroutineRunner.cs
Last active June 25, 2020 08:51
Class that permits run coroutines manually, can be useful to run coroutines in Unity Editor.
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
public static class EditorCoroutineRunner
{
private static List<IEnumerator> _coroutineList = new List<IEnumerator>();
static EditorCoroutineRunner()
{
@jfranmora
jfranmora / IsNullOrEmptyExtensions.cs
Last active June 25, 2020 08:50
Extension to create a consistent way to check if null or empty with different types.
using System.Collections.Generic;
public static class IsNullOrEmptyExtensions
{
public static bool IsNullOrEmpty(this string str)
{
return string.IsNullOrEmpty(str);
}