context: using UnityEngine;
  using System.Collections;
  using System.Collections.Generic;
  
  [System.Serializable]
  public class tk2dSpriteColliderIsland
  {
  	public bool connected = true;
  	public Vector2[] points;
  	
  	public bool IsValid()
  	{
  		if (connected)
  		{
  			return points.Length >= 3;
  		}
  		else
  		{
  			return points.Length >= 2;
  		}
  	}
  	
  	public void CopyFrom(tk2dSpriteColliderIsland src)
  	{
  		connected = src.connected;
  		
  		points = new Vector2[src.points.Length];
  		for (int i = 0; i < points.Length; ++i)
  			points[i] = src.points[i];		
  	}
  	
  	public bool CompareTo(tk2dSpriteColliderIsland src)
  	{
  		if (connected != src.connected) return false;
  		if (points.Length != src.points.Length) return false;
  		for (int i = 0; i < points.Length; ++i)
  			if (points[i] != src.points[i]) return false;
  		return true;
  	}
  }
  
  [System.Serializable]
  public class tk2dSpriteCollectionDefinition
  {
      public enum Anchor
      {
  		UpperLeft,
  		UpperCenter,
  		UpperRight,
  		MiddleLeft,
  		MiddleCenter,
  		MiddleRight,
  		LowerLeft,
  		LowerCenter,
  		LowerRight,
  		Custom
      }
  	
  	public enum Pad
  	{
  		Default,
  		BlackZeroAlpha,
  		Extend,
  		TileXY,
  	}
  	
  	public enum ColliderType
  	{
  		UserDefined,		// don't try to create or destroy anything
  		ForceNone,			// nothing will be created, if something exists, it will be destroyed
  		BoxTrimmed, 		// box, trimmed to cover visible region
  		BoxCustom, 			// box, with custom values provided by user
  		Polygon, 			// polygon, can be concave
  	}
  	
  	public enum PolygonColliderCap
  	{
  		None,
  		FrontAndBack,
  		Front,
  		Back,
  	}
  	
  	public enum ColliderColor
  	{
  		Default, // default unity color scheme
  		Red,
  		White,
  		Black
  	}
  	
  	public enum Source
  	{
  		Sprite,
  		SpriteSheet,
  		Font
  	}
  
  	public enum DiceFilter
  	{
  		Complete,
  		SolidOnly,
  		TransparentOnly,
  	}
  	
  	public string name = "";
  	
  	public bool disableTrimming = false;
      public bool additive = false;
      public Vector3 scale = new Vector3(1,1,1);
      
      public Texture2D texture = null;
  	
  	[System.NonSerialized]
  	public Texture2D thumbnailTexture;
  	
  	public int materialId = 0;
  	
  	public Anchor anchor = Anchor.MiddleCenter;
  	public float anchorX, anchorY;
      public Object overrideMesh;
  
      public bool doubleSidedSprite = false;
  	public bool customSpriteGeometry = false;
  	public tk2dSpriteColliderIsland[] geometryIslands = new tk2dSpriteColliderIsland[0];
  	
  	public bool dice = false;
  	public int diceUnitX = 64;
  	public int diceUnitY = 64;
  	public DiceFilter diceFilter = DiceFilter.Complete;
  
  	public Pad pad = Pad.Default;
  	public int extraPadding = 0; // default
  	
  	public Source source = Source.Sprite;
  	public bool fromSpriteSheet = false;
  	public bool hasSpriteSheetId = false;
  	public int spriteSheetId = 0;
  	public int spriteSheetX = 0, spriteSheetY = 0;
  	public bool extractRegion = false;
  	public int regionX, regionY, regionW, regionH;
  	public int regionId;
  	
  	public ColliderType colliderType = ColliderType.UserDefined;
  	public Vector2 boxColliderMin, boxColliderMax;
  	public tk2dSpriteColliderIsland[] polyColliderIslands;
  	public PolygonColliderCap polyColliderCap = PolygonColliderCap.FrontAndBack;
  	public bool colliderConvex = false;
  	public bool colliderSmoothSphereCollisions = false;
  	public ColliderColor colliderColor = ColliderColor.Default;
  
  	public List<tk2dSpriteDefinition.AttachPoint> attachPoints = new List<tk2dSpriteDefinition.AttachPoint>();
  
  	public void CopyFrom(tk2dSpriteCollectionDefinition src)
  	{
  		name = src.name;
  		
  		disableTrimming = src.disableTrimming;
  		additive = src.additive;
  		scale = src.scale;
  		texture = src.texture;
  		materialId = src.materialId;
  		anchor = src.anchor;
  		anchorX = src.anchorX;
  		anchorY = src.anchorY;
  		overrideMesh = src.overrideMesh;
  		
  		doubleSidedSprite = src.doubleSidedSprite;
  		customSpriteGeometry = src.customSpriteGeometry;
  		geometryIslands = src.geometryIslands;
  		
  		dice = src.dice;
  		diceUnitX = src.diceUnitX;
  		diceUnitY = src.diceUnitY;
  		diceFilter = src.diceFilter;
  		pad = src.pad;
  		
  		source = src.source;
  		fromSpriteSheet = src.fromSpriteSheet;
  		hasSpriteSheetId = src.hasSpriteSheetId;
  		spriteSheetX = src.spriteSheetX;
  		spriteSheetY = src.spriteSheetY;
  		spriteSheetId = src.spriteSheetId;
  		extractRegion = src.extractRegion;
  		regionX = src.regionX;
  		regionY = src.regionY;
  		regionW = src.regionW;
  		regionH = src.regionH;
  		regionId = src.regionId;
  		
  		colliderType = src.colliderType;
  		boxColliderMin = src.boxColliderMin;
  		boxColliderMax = src.boxColliderMax;
  		polyColliderCap = src.polyColliderCap;
  		
  		colliderColor = src.colliderColor;
  		colliderConvex = src.colliderConvex;
  		colliderSmoothSphereCollisions = src.colliderSmoothSphereCollisions;
  		
  		extraPadding = src.extraPadding;
  		
  		if (src.polyColliderIslands != null)
  		{
  			polyColliderIslands = new tk2dSpriteColliderIsland[src.polyColliderIslands.Length];
  			for (int i = 0; i < polyColliderIslands.Length; ++i)
  			{
  
gt: 				polyColliderIslands[i] = new tk2dSpriteColliderIsland();