Skip to content

Instantly share code, notes, and snippets.

View gilzoide's full-sized avatar

Gil Barbosa Reis gilzoide

View GitHub Profile
@gilzoide
gilzoide / BoundsCornerEnumerator.cs
Last active April 30, 2024 02:21
Non-alloc IEnumerable/IEnumerator for UnityEngine.Bounds 8 corners
// Usage: foreach (Vector3 corner in bounds.EnumerateCorners()) { ... }
using System.Collections;
using System.Collections.Generic;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine;
namespace Gilzoide.BoundsCornerEnumerator
{
public static class BoundsExtensions
{
@gilzoide
gilzoide / SpritePackingTagToAtlas.cs
Last active March 15, 2024 15:08
Converts legacy sprite packing tags to a 2D Sprite Atlas
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEditor.U2D;
using UnityEngine;
// How to use:
// 1. Select a texture that has a "Packing Tag" set
// 2. Open the context menu in the top-right corner of the inspector
@gilzoide
gilzoide / gcloud_secret_envvars.py
Created February 14, 2024 21:16
Python environment variables from Google Cloud Secret Manager
"""
Functionality to fetch environment variables using Google Cloud Secret Manager.
Environment variables with the GCLOUD_SECRET_ prefix will be filled with
secrets fetched from Google Cloud Secret Manager.
This way, you can use secrets for any environment variables without changing
any code, just the environment setup.
"""
import os
@gilzoide
gilzoide / EOS-na-Unity.md
Last active November 22, 2022 12:32
Notas sobre Epic Online Services na Unity

A integração com Unity se dá por meio do SDK C#, que pode ser baixado diretamente do portal da Epic.

Como fazer funcionar na Unity pra builds Android/iOS:

  • É necessário remover ou ignorar a pasta Samples, pois eles definem classes C# com nomes duplicados.
  • Se estiver usando a Unity num computador macOS, é necessário comentar a linha #define EOS_DYNAMIC_BINDINGS no arquivo SDK/Source/Generated/Bindings.cs, pois a biblioteca nativa do macOS não foi compilada com suporte a carregamento dinâmico. Como os bindings dinâmicos já foram desligados, não precisamos fazer o Hook dinâmico no editor no Windows como recomenda a documentação.
  • As bibliotecas xaudio2_9redist.dll são para Windows e precisam ser configuradas de acordo, para não serem consideradas nas builds Android e iOS e quebrá-las.
  • O framework nativo do iOS precisa da flag Add to embedded binaries marcada, ou a aplicação não inicializa corretamente
  • É necessário escolher somente uma das versões da biblioteca nativa para Android e apaga
@gilzoide
gilzoide / GradleAndroidPluginVersionSetter.cs
Created September 21, 2022 15:35
Unity Gradle Android plugin version setter
#if UNITY_ANDROID
using System.IO;
using System.Text.RegularExpressions;
using UnityEditor.Android;
public class GradleAndroidPluginVersionSetter : IPostGenerateGradleAndroidProject
{
public const string GradleAndroidPluginVersion = "3.4.3";
public int callbackOrder => 0;
@gilzoide
gilzoide / lua_string_replace.c
Last active September 7, 2021 14:03
A plain string replacement function for Lua with no magic characters
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
/// Performs plain substring replacement, with no characters in `pattern` or `replacement` being considered magic.
/// There is no support for `string.gsub`'s parameter `n` and second return in this version.
/// @function string.replace
/// @tparam string str
/// @tparam string pattern
/// @tparam string replacement
@gilzoide
gilzoide / clang_tu_from_ast.py
Last active February 7, 2024 21:17
Snippet for creating a clang TranslationUnit in python by calling clang as a subprocess instead of parsing with Index.parse
import subprocess
import tempfile
import clang.cindex as clang
def create_translation_unit_with_ast(source_file_path, clang_args=[], clang_exe='clang'):
"""
Create a `clang.TranslationUnit` for a source file by compiling it with clang as a
subprocess instead of using `clang.Index.parse`.
@gilzoide
gilzoide / hotreload.lua
Last active July 27, 2020 03:15
A module for detecting updated files in a LÖVE game
-- Detecting updated files for hot reloading in a LÖVE game
local hotreload = {}
-- Monitor the "src" and "assets" paths, can be changed to any existing folders in your project, separated by spaces
local monitor_path = "src assets"
-- External command for monitoring the filesystem
-- Needs fswatch available for execution in PATH (no errors will be thrown, but reload will not work)
-- https://github.com/emcrisostomo/fswatch
local fswatch_cmd = "fswatch --recursive --event Updated " .. monitor_path
@gilzoide
gilzoide / xor.lua
Last active December 16, 2023 12:33
Logical XOR in lua
-- Returns false if value is falsey (`nil` or `false`), returns true if value is truthy (everything else)
function toboolean(v)
return v ~= nil and v ~= false
end
-- Returns true if one value is falsey and the other is truthy, returns false otherwise
function xor(a, b)
return toboolean(a) ~= toboolean(b)
end
@gilzoide
gilzoide / pairs_not_numeric.lua
Last active June 22, 2020 13:36
A version of the `pairs` Lua function that ignores numeric keys
-- Usage: for k, v in kpairs(t) do ... end
local function knext(t, index)
local value
repeat
index, value = next(t, index)
until type(index) ~= 'number'
return index, value
end
function kpairs(t)
return knext, t, nil