当前位置: 首页>>代码示例>>C#>>正文


C# Skin.AddAttachment方法代码示例

本文整理汇总了C#中Skin.AddAttachment方法的典型用法代码示例。如果您正苦于以下问题:C# Skin.AddAttachment方法的具体用法?C# Skin.AddAttachment怎么用?C# Skin.AddAttachment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Skin的用法示例。


在下文中一共展示了Skin.AddAttachment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetRepackedSkin

		/// <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;
		}
开发者ID:EsotericSoftware,项目名称:spine-runtimes,代码行数:41,代码来源:AttachmentTools.cs

示例2: ReadSkeletonSkins

        private void ReadSkeletonSkins(SkeletonData skeletonData, JObject data, float scale)
        {
            foreach (JProperty skin in data["skins"])
            {
                var skeletonSkin = new Skin(skin.Name);

                foreach (JProperty slot in skin.Value)
                {
                    int slotIndex = skeletonData.FindSlotIndex(slot.Name);

                    foreach (JProperty attachment in slot.Value)
                    {
                        Attachment skeletonAttachment = ReadSkeletonAttachment(attachment.Name, attachment.Value, scale);
                        if (attachment != null)
                        {
                            skeletonSkin.AddAttachment(slotIndex, attachment.Name, skeletonAttachment);
                        }
                    }
                }

                skeletonData.AddSkin(skeletonSkin);
                if (skeletonSkin.Name.Equals("default"))
                {
                    skeletonData.DefaultSkin = skeletonSkin;
                }
            }
        }
开发者ID:Andrea,项目名称:spine-runtime-monogame,代码行数:27,代码来源:SkeletonJsonReader.cs

示例3: ReadSkeletonData

		public SkeletonData ReadSkeletonData (TextReader reader) {
			if (reader == null) throw new ArgumentNullException("reader cannot be null.");

			SkeletonData skeletonData = new SkeletonData();

			var root = Json.Deserialize(reader) as Dictionary<String, Object>;
			if (root == null) throw new Exception("Invalid JSON.");

			// Bones.
			foreach (Dictionary<String, Object> boneMap in (List<Object>)root["bones"]) {
				BoneData parent = null;
				if (boneMap.ContainsKey("parent")) {
					parent = skeletonData.FindBone((String)boneMap["parent"]);
					if (parent == null)
						throw new Exception("Parent bone not found: " + boneMap["parent"]);
				}
				BoneData boneData = new BoneData((String)boneMap["name"], parent);
				boneData.length = GetFloat(boneMap, "length", 0) * Scale;
				boneData.x = GetFloat(boneMap, "x", 0) * Scale;
				boneData.y = GetFloat(boneMap, "y", 0) * Scale;
				boneData.rotation = GetFloat(boneMap, "rotation", 0);
				boneData.scaleX = GetFloat(boneMap, "scaleX", 1);
				boneData.scaleY = GetFloat(boneMap, "scaleY", 1);
				boneData.inheritScale = GetBoolean(boneMap, "inheritScale", true);
				boneData.inheritRotation = GetBoolean(boneMap, "inheritRotation", true);
				skeletonData.AddBone(boneData);
			}

			// Slots.
			if (root.ContainsKey("slots")) {
				foreach (Dictionary<String, Object> slotMap in (List<Object>)root["slots"]) {
					String slotName = (String)slotMap["name"];
					String boneName = (String)slotMap["bone"];
					BoneData boneData = skeletonData.FindBone(boneName);
					if (boneData == null)
						throw new Exception("Slot bone not found: " + boneName);
					SlotData slotData = new SlotData(slotName, boneData);

					if (slotMap.ContainsKey("color")) {
						String color = (String)slotMap["color"];
						slotData.r = ToColor(color, 0);
						slotData.g = ToColor(color, 1);
						slotData.b = ToColor(color, 2);
						slotData.a = ToColor(color, 3);
					}

					if (slotMap.ContainsKey("attachment"))
						slotData.attachmentName = (String)slotMap["attachment"];

					if (slotMap.ContainsKey("additive"))
						slotData.additiveBlending = (bool)slotMap["additive"];

					skeletonData.AddSlot(slotData);
				}
			}

			// Skins.
			if (root.ContainsKey("skins")) {
				foreach (KeyValuePair<String, Object> entry in (Dictionary<String, Object>)root["skins"]) {
					Skin skin = new Skin(entry.Key);
					foreach (KeyValuePair<String, Object> slotEntry in (Dictionary<String, Object>)entry.Value) {
						int slotIndex = skeletonData.FindSlotIndex(slotEntry.Key);
						foreach (KeyValuePair<String, Object> attachmentEntry in ((Dictionary<String, Object>)slotEntry.Value)) {
							Attachment attachment = ReadAttachment(skin, attachmentEntry.Key, (Dictionary<String, Object>)attachmentEntry.Value);
							if (attachment != null) skin.AddAttachment(slotIndex, attachmentEntry.Key, attachment);
						}
					}
					skeletonData.AddSkin(skin);
					if (skin.name == "default")
						skeletonData.defaultSkin = skin;
				}
			}

			// Events.
			if (root.ContainsKey("events")) {
				foreach (KeyValuePair<String, Object> entry in (Dictionary<String, Object>)root["events"]) {
					var entryMap = (Dictionary<String, Object>)entry.Value;
					EventData eventData = new EventData(entry.Key);
					eventData.Int = GetInt(entryMap, "int", 0);
					eventData.Float = GetFloat(entryMap, "float", 0);
					eventData.String = GetString(entryMap, "string", null);
					skeletonData.AddEvent(eventData);
				}
			}

			// Animations.
			if (root.ContainsKey("animations")) {
				foreach (KeyValuePair<String, Object> entry in (Dictionary<String, Object>)root["animations"])
					ReadAnimation(entry.Key, (Dictionary<String, Object>)entry.Value, skeletonData);
			}

			skeletonData.bones.TrimExcess();
			skeletonData.slots.TrimExcess();
			skeletonData.skins.TrimExcess();
			skeletonData.animations.TrimExcess();
			return skeletonData;
		}
开发者ID:jrichter42,项目名称:TVR_DevelopmentRelease_v1.0,代码行数:97,代码来源:SkeletonJson.cs


注:本文中的Skin.AddAttachment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。