Skip to content

Instantly share code, notes, and snippets.

View daltonbr's full-sized avatar
🎮
Brighton - UK

Dalton Lima daltonbr

🎮
Brighton - UK
View GitHub Profile
@daltonbr
daltonbr / InventoryItemDisplay.cs
Last active December 13, 2017 03:28
A basic structure of a Delegate in C#
public class InventoryItemDisplay
{
public delegate void InventoryItemDisplayDelegate(InventoryItem item); // the signature of this delegate <void> <param item>
public static event InventoryItemDisplayDelegate onClick; // the event
public void Click()
{
Debug.Log("Clicked " + item.displayName);
if (onClick != null) // Important null check - if no one subscribes to this event, then it crashes.
{
@daltonbr
daltonbr / Input.cs
Last active October 14, 2018 00:42
A decoupled Input system from Unity / C#
using System;
using UnityEngine;
public class Input : MonoBehaviour
{
public float Horizontal { get; private set; }
public float Vertical { get; private set; }
public bool FireWeapons { get; private set; }
public event Action OnFire = delegate { };
@daltonbr
daltonbr / AttackProcessor.cs
Created October 14, 2018 01:17
SOLID Code - Interface Segregation Principle
public class AttackProcessor
{
public void ProcessMelee(IHaveStats attacker, IHaveHealth target)
{
int amount = CalculateAttackAmount(attacker);
ProcessAttack(target, amount);
}
public void CalculateAttackAmount(IHaveStats attacker)
{
@daltonbr
daltonbr / AiInput.cs
Created October 14, 2018 02:57
SOLID Principles - Dependency Injection (not dependency inversion)
using UnityEngine;
public class AiInput : IShipInput
{
public float Rotation { get; private set;}
public float Thrust { get; private set;}
public void ReadInput()
{
Rotation = Random.Range(-1f, 1f);
@daltonbr
daltonbr / osxswitchplatform.bash
Created January 22, 2019 09:12
A bash script to switch Unity builds, this one is for OSX
#!/bin/bash
# https://bonusxp.com/2014/09/fast-platform-switching-in-unity3d/
# $ brew install pidof
# $ chmod +x osxswitchplatform.bash
# ./osxswitchplatform ios
# ./osxswitchplatform android
# Make sure Unity isn't running while we switch directories out from under it.
if [ "$(pidof Unity)" ]; then
@daltonbr
daltonbr / shell.sh
Last active November 6, 2020 04:27
CLI 'youtube-dl' examples, how to easily download youtube videos
# brew install youtube-dl (on mac)
# https://github.com/rg3/youtube-dl
# alias
alias cd..="cd .."
alias sync="adb push --sync ~/Movies/*.mp4 mnt/sdcard/Movies/"
alias yt="youtube-dl -o '~/Movies/[%(release_date)s]-[%(id)s].%(title)s.%(ext)s' --restrict-filenames"
alias ytplaylist="youtube-dl -o '~/Movies/%(uploader)s/%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s'"
alias mp3="youtube-dl --extract-audio --format bestaudio --audio-format mp3 --prefer-ffmpeg --audio-quality 160K --output '%(title)s.%(ext)s'"
@daltonbr
daltonbr / PageInspector.cs
Created March 12, 2019 10:55
A quick snippet of a Unity Custom Editor
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
[CustomEditor(typeof(Page))]
public class PageInspector : Editor {
public Material wordMat = null;
@daltonbr
daltonbr / myFavoriteShell.sh
Last active September 5, 2019 09:46
Go Development - script for OSX
# Go development
export GOPATH="${HOME}/.go"
export GOROOT="$(brew --prefix golang)/libexec"
export PATH="$PATH:${GOPATH}/bin:${GOROOT}/bin"
test -d "${GOPATH}" || mkdir "${GOPATH}"
test -d "${GOPATH}/src/github.com" || mkdir -p "${GOPATH}/src/github.com"
# Then finally install go, with Homebrew.
# brew install go
@daltonbr
daltonbr / wav_to_mp3.sh
Created November 4, 2019 11:38
ffmpeg converting media
ffmpeg -i input.wav -vn -ar 44100 -ac 2 -b:a 192k output.mp3
# Explanation of the used arguments in this example:
# -i - input file
# -vn - Disable video, to make sure no video (including album cover image) is included if the source would be a video file
# -ar - Set the audio sampling frequency. For output streams it is set by default to the frequency of the corresponding input stream. For input streams this option only makes sense for audio grabbing devices and raw demuxers and is mapped to the corresponding demuxer options.
# -ac - Set the number of audio channels. For output streams it is set by default to the number of input audio channels. For input streams this option only makes sense for audio grabbing devices and raw demuxers and is mapped to the corresponding demuxer options. So used here to make sure it is stereo (2 channels)
# -b:a - Converts the audio bitrate to be exact 192kbit per second
@daltonbr
daltonbr / ffmpeg.sh
Last active September 11, 2020 08:07
A few snippets for ffmpeg - Rescaling, trimming, converting & making gif's and popcorn 🍿
# Simple Image/video rescaling
ffmpeg -i input.avi -vf scale=320:240 output.avi
ffmpeg -i input.jpg -vf scale=320:240 output_320x240.png
# Keeping the Aspect Ratio
# If we'd like to keep the aspect ratio, we need to specify only one component, either width or height,
# and set the other component to -1.
ffmpeg -i input.jpg -vf scale=320:-1 output_320.png