Skip to content

Instantly share code, notes, and snippets.

@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 / DistanceApplier.cs
Created August 26, 2016 06:01
Formula for scaling an object according to how far it moves from an original point and viewpoint, in order to maintain its perceived size. In the form of a Unity MonoBehaviour. This is to achieve VR-friendly parallax for 2D games.
using UnityEngine;
/// <summary>
/// This script will push an object back to a target Z position and maintain its size to a given editor camera distance. This is to achieve parallax that is compatible with VR.</summary>
public class DistanceApplier : MonoBehaviour {
public float targetZ = 20;
// The applied scale will try to maintain the scale of the object assuming the original scale was defined when viewed with the camera at this z position.
const float BaseCameraZ = -10;
@pharan
pharan / ParallaxFaker2D.cs
Created August 26, 2016 05:50
Simplified (derived) formula for faking the parallax of an object given a camera position, in the form of a Unity component. This may not work for VR??
using UnityEngine;
public class ParallaxFaker2D : MonoBehaviour {
// The Transform of the camera to fake the parallax for.
public Transform cameraTransform;
// The world position to mimick the parallax of.
public Vector3 fakePosition;
// The Transform's target (actual) distance from the camera.
@pharan
pharan / ArraysMeshGenerator.cs
Created June 17, 2016 04:30
A version of Spine-Unity ArraysMeshGenerator.cs that can disallow degenerate triangles and extra verts.
/******************************************************************************
* 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 / LinkedMeshSample.cs
Last active June 21, 2016 14:24
[spine-unity] Sample code for how to dynamically create and image-swap a linked MeshAttachment.
/*****************************************************************************
* LinkedMeshSample code created by John Dy
* Full irrevocable rights and permissions granted to Esoteric Software
*****************************************************************************/
using UnityEngine;
using System.Collections;
using Spine;
using Spine.Unity;
public class LinkedMeshSample : MonoBehaviour {
@pharan
pharan / AnimationState.cs
Created June 6, 2016 21:43
A hyper-simplified version of Spine's AnimationState.cs
/******************************************************************************
* 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 / EventTimelineExtensions.cs
Last active May 23, 2016 07:46
spine-csharp EventTimelineExtensions
/******************************************************************************
* 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 / VertexHelperSpineMeshGenerator.cs
Created April 13, 2016 19:50
Sample ISimpleMeshGenerator implementation using Unity's VertexHelper. Very slow.
/******************************************************************************
* 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 / SimpleCommand.cpp
Created April 1, 2016 09:28
Sample for subclassing cocos2d::Node with basic rendering through a (batchable) TriangleCommand
#include "SimpleCommand.h"
USING_NS_CC;
using namespace std;
Scene* SimpleCommand::scene () {
Scene *scene = Scene::create();
scene->addChild(SimpleCommand::create());
return scene;
}
@pharan
pharan / AtlasAssetInspector.cs
Last active March 18, 2016 09:02
AtlasAssetInspector with BakeAll
/******************************************************************************
* 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