Skip to content

Instantly share code, notes, and snippets.

@dvdfu
dvdfu / ButtonUI.cs
Created June 15, 2022 15:01
UI Button for Unity with better responsiveness
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class ButtonUI : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerExitHandler {
public UnityEvent onPressEvent = new UnityEvent();
[SerializeField] Button button;
Shader "Custom/Ring" {
Properties {
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
SubShader {
Tags {
"RenderType" = "Transparent"
"Queue" = "Transparent"
}
Blend SrcAlpha OneMinusSrcAlpha
@dvdfu
dvdfu / LerpHSV.cs
Created July 21, 2020 16:13
Interpolate between two HSV colors (Unity)
public static Color LerpHSV(Color a, Color b, float x) {
Vector3 ah = RGB2HSV(a);
Vector3 bh = RGB2HSV(b);
return new Vector3(
Mathf.LerpAngle(ah.x, bh.x, x),
Mathf.Lerp(ah.y, bh.y, x),
Mathf.Lerp(ah.z, bh.z, x)
);
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// An effect that causes a sprite to be squished vertically or horizontally
// e.g. player on jumping, enemies on hit
public class Squishable : MonoBehaviour {
[SerializeField] [Range(0, 1)] float squishAmount = 0.5f;
[SerializeField] [Range(0, 1)] float squishDuration = 0.1f;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tween {
public delegate void OnUpdate(float progress);
public delegate void OnFinish();
MonoBehaviour mb;
OnFinish onFinish;
local Oscillator = {}
Oscillator.__index = Oscillator
function Oscillator.new(period)
assert(period > 0)
return setmetatable({
period = period or 1,
time = 0
}, Oscillator)
end
local Class = require 'modules.middleclass.middleclass'
local Stateful = require 'modules.stateful.stateful'
local Timer = require 'modules.hump.timer'
local Const = require 'src.const'
local Screen = Class('Screen')
Screen:include(Stateful)
local Iris = Screen:addState('Iris')
local Overlay = Screen:addState('Overlay')
local Class = require 'modules.middleclass.middleclass'
local Timer = require 'modules.hump.timer'
local Vector = require 'modules.hump.vector'
local Const = require 'src.const'
local Util = require 'src.util'
local Camera = Class('Camera')
function Camera:initialize(settings)
settings = settings or {}
local Class = require 'modules.middleclass.middleclass'
local Timer = require 'modules.hump.timer'
local Event = Class('Event')
function Event:initialize(time, callbacks)
assert(time and callbacks)
self.timer = Timer.new()
self.timer:after(time, function()
self.dead = true
@dvdfu
dvdfu / run.sh
Last active April 16, 2017 23:20
Packer script
cp -r ../gemini/res/img/ .
love . img sprites
mv /home/david/.local/share/love/packer/sprites.png ../gemini/res/atlas/
mv /home/david/.local/share/love/packer/sprites.lua ../gemini/res/atlas/
rm -r img/
cp -r ../gemini/res/img/* .
"/Applications/love.app/Contents/MacOS/love" . objects objects
mv "/Users/davidfu/Library/Application Support/LOVE/packer/*" ../gemini/res/atlas/
rm -r backgrounds