Skip to content

Instantly share code, notes, and snippets.

View luispedrofonseca's full-sized avatar

Luis Fonseca luispedrofonseca

View GitHub Profile
@luispedrofonseca
luispedrofonseca / PixelArtShader.shader
Created September 4, 2019 16:51
Modern pixel art solution
// https://colececil.io/blog/2017/scaling-pixel-art-without-destroying-it/
Shader "Custom/PixelArtShader"
{
Properties
{
_MainTex("Texture", 2D) = "" {}
}
SubShader
@luispedrofonseca
luispedrofonseca / OnClickAnimation
Last active June 27, 2019 15:50
PG ESAD - Script to simplify the process of triggering an animation by clicking an object
using UnityEngine;
using UnityEngine.EventSystems;
public class OnClickAnimation : MonoBehaviour, IPointerClickHandler
{
public Animator MyAnimator;
public string TriggerName = "idle";
private void Reset()
{
@luispedrofonseca
luispedrofonseca / RectUtils.cs
Created October 8, 2016 19:07
Unity Custom Rect Editor
using UnityEngine;
using UnityEditor;
public class RectUtils
{
public static Rect ResizeRect(Rect rect, Handles.DrawCapFunction capFunc, Color capCol, Color fillCol, float capSize, float snap)
{
Vector2 halfRectSize = new Vector2(rect.size.x * 0.5f, rect.size.y * 0.5f);
Vector3[] rectangleCorners =
@luispedrofonseca
luispedrofonseca / affinity-sort-files.sh
Created December 9, 2014 18:27
Bash script to sort files exported from Affinity Designer into size folders
#!/bin/bash
# Creates folders to sort files exported by Affinity Designer
mkdir -p images
mkdir -p images/2x
mkdir -p images/3x
for file in ./*2x.png
do
if [ -f "$file" ]
then
@luispedrofonseca
luispedrofonseca / .gitignore
Created December 8, 2014 15:38
Unity GIT Ignore template
# =============== #
# Unity generated #
# =============== #
Temp/
Obj/
UnityGenerated/
Library/
Assets/AssetStoreTools*
# ===================================== #
@luispedrofonseca
luispedrofonseca / iOSIcons.sh
Created December 8, 2014 15:37
Create the iOS icons needed by Unity
#!/bin/bash
f=$(pwd)
sips --resampleWidth 57 "${f}/${1}" --out "${f}/57x57.png"
sips --resampleWidth 72 "${f}/${1}" --out "${f}/72x72.png"
sips --resampleWidth 76 "${f}/${1}" --out "${f}/76x76.png"
sips --resampleWidth 114 "${f}/${1}" --out "${f}/114x114.png"
sips --resampleWidth 120 "${f}/${1}" --out "${f}/120x120.png"
sips --resampleWidth 144 "${f}/${1}" --out "${f}/144x144.png"
sips --resampleWidth 152 "${f}/${1}" --out "${f}/152x152.png"
using UnityEngine;
using System.Collections;
public class ShareButton : MonoBehaviour
{
Texture2D _texture;
RenderTexture _renderTexture;
void OnGUI()
{
using UnityEngine;
using System.Runtime.InteropServices;
public class InstagramShare
{
static string imagePath = Application.temporaryCachePath + "/temp.png";
static bool HasHandshook = false;
[DllImport("__Internal")]
NSURL *appURL = [NSURL URLWithString:@"instagram://app"];
if([[UIApplication sharedApplication] canOpenURL:appURL])
{
// Image
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
// Post
[UIImageJPEGRepresentation(image, 1.0) writeToFile:[self photoFilePath] atomically:YES];
NSURL *fileURL = [NSURL fileURLWithPath:[self photoFilePath]];
#import "InstagramShare.h"
void _handshake()
{
[[InstagramShare sharedInstance] handshake];
}
void _postToInstagram(const char * message, const char * imagePath)
{
NSString *m = [NSString stringWithUTF8String:message];