Skip to content

Instantly share code, notes, and snippets.

@pharan
pharan / PaintBrush.cs
Created November 11, 2017 00:08
Unity PaintBrush MonoBehaviour class based on https://pastebin.com/rMx1PVXi
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PaintBrush : MonoBehaviour
{
public int resolution = 512;
Texture2D whiteMap;
public float brushSize;
public Texture2D brushTexture;
@pharan
pharan / AnimationTools.cs
Last active June 6, 2018 17:37
Preview of the spine-unity AnimationTools static class module.
/******************************************************************************
* Spine Runtimes Software License v2.5
*
* Copyright (c) 2013-2018, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable, and
* non-transferable license to use, install, execute, and perform the Spine
* Runtimes software and derivative works solely for personal or internal
* use. Without the written permission of Esoteric Software (see Section 2 of
@pharan
pharan / SpineMeshUVResizeCalculator.cs
Last active August 30, 2018 09:53
How to calculate how much to trim unused space on backing image for a Spine mesh, and output new UVs that map to the trimmed image.
using System;
public static class SpineMeshUVResizeCalculator {
public struct MeshUVData {
public float[] uvs;
public float imageWidth;
public float imageHeight;
public float trimLeft;
public float trimRight;
@pharan
pharan / BlendModeMaterialsAsset.cs
Last active September 16, 2018 07:50
Initial implementation of slot blend mode processing on the attachment level for Spine-Unity.
/******************************************************************************
* Spine Runtimes Software License v2.5
*
* Copyright (c) 2013-2016, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable, and
* non-transferable license to use, install, execute, and perform the Spine
* Runtimes software and derivative works solely for personal or internal
* use. Without the written permission of Esoteric Software (see Section 2 of
@pharan
pharan / AnimationState.cs
Last active September 16, 2018 07:53
Mix-compatible Resetting AnimationState for Spine-C#
/******************************************************************************
* Spine Runtimes Software License
* Version 2.3
*
* Copyright (c) 2013-2015, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable and
* non-transferable license to use, install, execute and perform the Spine
* Runtimes Software (the "Software") and derivative works solely for personal
@pharan
pharan / SpineRootMotion.cs
Last active October 12, 2018 11:07
Experimental Spine.Unity.Modules.SpineRootMotion for SkeletonAnimation
/******************************************************************************
* Spine Runtimes Software License v2.5
*
* Copyright (c) 2013-2016, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable, and
* non-transferable license to use, install, execute, and perform the Spine
* Runtimes software and derivative works solely for personal or internal
* use. Without the written permission of Esoteric Software (see Section 2 of
@pharan
pharan / Atlas.cs
Last active November 9, 2018 21:47
NumberStyle-specified version of the Atlas.cs Spine atlas loader.
/******************************************************************************
* Spine Runtimes Software License v2.5
*
* Copyright (c) 2013-2016, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable, and
* non-transferable license to use, install, execute, and perform the Spine
* Runtimes software and derivative works solely for personal or internal
* use. Without the written permission of Esoteric Software (see Section 2 of
@pharan
pharan / RuntimeAssets.cs
Last active March 30, 2019 02:36
Sample code for creating runtime Spine ScriptableObjects.
using UnityEngine;
using System.Collections.Generic;
namespace Spine.Unity {
public static class RuntimeAssets {
public static AtlasAsset CreateAtlasAsset (TextAsset atlasText, Material[] materials, bool initialize) {
AtlasAsset atlasAsset = ScriptableObject.CreateInstance<AtlasAsset>();
atlasAsset.Reset();
atlasAsset.atlasFile = atlasText;
@pharan
pharan / Spine-SkeletonSpriteMaskable.shader
Last active August 4, 2020 10:45
A version of Spine/Skeleton shader that can be drawn within a Unity 2017 SpriteMask.
Shader "Spine/Skeleton SpriteMaskable" {
Properties {
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
[NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {}
_StencilRef ("Stencil Reference", Float) = 1.0
_StencilComp ("Stencil Compare", Float) = 4.0 // For float values, see https://docs.unity3d.com/Manual/SL-Stencil.html under "Comparison Function" heading
}
SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
@pharan
pharan / SkeletonAutoreset.cs
Last active August 11, 2020 22:20
An autoresetting script for Spine-Unity that prevents animations from inheriting changes from previously played animations, by resetting the skeleton back to its setup pose before playing a new animation.
using UnityEngine;
using System.Collections;
public class SkeletonAutoreset : MonoBehaviour {
void Start () {
var skeletonAnimation = GetComponent<SkeletonAnimation>();
if (skeletonAnimation == null) {
Debug.Log("SkeletonAutoreset uses GetComponent and needs to be attached on the same GameObject as the SkeletonAnimation component.");
return;