コード例 #1
0
		static AtlasPage GetPageFor (Texture texture, Shader shader) {
			if (atlasPageCache == null) atlasPageCache = new Dictionary<Texture, AtlasPage>();
			AtlasPage atlasPage;
			atlasPageCache.TryGetValue(texture, out atlasPage);
			if (atlasPage == null) {
				var newMaterial = new Material(shader);
				atlasPage = newMaterial.ToSpineAtlasPage();
				atlasPageCache[texture] = atlasPage;
			}
			return atlasPage;
		}
コード例 #2
0
		/// <summary>
		/// Creates and populates a duplicate skin with cloned attachments that are backed by a new packed texture atlas comprised of all the regions from the original skin.</summary>
		/// <remarks>No Spine.Atlas object is created so there is no way to find AtlasRegions except through the Attachments using them.</remarks>
		public static Skin GetRepackedSkin (this Skin o, string newName, Shader shader, out Material m, out Texture2D t, int maxAtlasSize = 1024, int padding = 2) {
			var skinAttachments = o.Attachments;
			var newSkin = new Skin(newName);

			var repackedAttachments = new List<Attachment>();
			var texturesToPack = new List<Texture2D>();
			foreach (var kvp in skinAttachments) {
				var newAttachment = kvp.Value.GetClone(true);
				if (IsRenderable(newAttachment)) {
					texturesToPack.Add(newAttachment.GetAtlasRegion().ToTexture());
					repackedAttachments.Add(newAttachment);
				}
				var key = kvp.Key;
				newSkin.AddAttachment(key.slotIndex, key.name, newAttachment);
			}

			var newTexture = new Texture2D(maxAtlasSize, maxAtlasSize);
			newTexture.name = newName;
			var rects = newTexture.PackTextures(texturesToPack.ToArray(), padding, maxAtlasSize);

			var newMaterial = new Material(shader);
			newMaterial.name = newName;
			newMaterial.mainTexture = newTexture;
			var page = newMaterial.ToSpineAtlasPage();
			page.name = newName;

			for (int i = 0, n = repackedAttachments.Count; i < n; i++) {
				var a = repackedAttachments[i];
				var r = rects[i];
				var oldRegion = a.GetAtlasRegion();
				var newRegion = UVRectToAtlasRegion(r, oldRegion.name, page, oldRegion.offsetX, oldRegion.offsetY, oldRegion.rotate);
				a.SetRegion(newRegion);
			}

			t = newTexture;
			m = newMaterial;
			return newSkin;
		}
コード例 #3
0
		/// <summary>
		/// Creates a Spine.AtlasRegion that uses a premultiplied alpha duplicate of the Sprite's texture data.</summary>
		public static AtlasRegion ToAtlasRegionPMAClone (this Sprite s, Shader shader) {
			var material = new Material(shader);
			var tex = s.ToTexture(false);
			tex.ApplyPMA(true);

			tex.name = s.name + "-pma-";
			material.name = tex.name + shader.name;

			material.mainTexture = tex;
			var page = material.ToSpineAtlasPage();

			var region = s.ToAtlasRegion(true);
			region.page = page;

			return region;
		}
コード例 #4
0
		/// <summary>
		/// Creates a Spine.AtlasRegion from a UnityEngine.Sprite. This creates a new AtlasPage object for every AtlasRegion you create. You can centralize Material control by creating a shared atlas page using Material.ToSpineAtlasPage and using the sprite.ToAtlasRegion(AtlasPage) overload.</summary>
		public static AtlasRegion ToAtlasRegion (this Sprite s, Material material) {
			var region = s.ToAtlasRegion();
			region.page = material.ToSpineAtlasPage();
			return region;
		}
コード例 #5
0
		/// <summary>
		/// Creates a RegionAttachment based on a sprite. This method creates a real, usable AtlasRegion. That AtlasRegion uses a new AtlasPage with the Material provided./// </summary>
		public static RegionAttachment ToRegionAttachment (this Sprite sprite, Material material) {
			return sprite.ToRegionAttachment(material.ToSpineAtlasPage());
		}