• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Spine.Skin类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Skin类属于Spine命名空间,在下文中一共展示了Skin类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: NewAttachment

 public Attachment NewAttachment(Skin skin, AttachmentType type, String name)
 {
     switch (type) {
     case AttachmentType.region:
         AtlasRegion region = atlas.FindRegion(name);
         if (region == null) throw new Exception("Region not found in atlas: " + name + " (" + type + ")");
         RegionAttachment attachment = new RegionAttachment(name);
         attachment.Region = region;
         return attachment;
     }
     throw new Exception("Unknown attachment type: " + type);
 }
开发者ID:jaquadro,项目名称:Amphibian,代码行数:12,代码来源:AtlasAttachmentLoader.cs


示例2: NewRegionAttachment

		public RegionAttachment NewRegionAttachment (Skin skin, String name, String path) {
			AtlasRegion region = atlas.FindRegion(path);
			if (region == null) throw new Exception("Region not found in atlas: " + path + " (region attachment: " + name + ")");
			RegionAttachment attachment = new RegionAttachment(name);
			attachment.RendererObject = region;
			attachment.SetUVs(region.u, region.v, region.u2, region.v2, region.rotate);
			attachment.regionOffsetX = region.offsetX;
			attachment.regionOffsetY = region.offsetY;
			attachment.regionWidth = region.width;
			attachment.regionHeight = region.height;
			attachment.regionOriginalWidth = region.originalWidth;
			attachment.regionOriginalHeight = region.originalHeight;
			return attachment;
		}
开发者ID:460189852,项目名称:cocos-sharp-samples,代码行数:14,代码来源:AtlasAttachmentLoader.cs


示例3: Start

		void Start () {
			skeletonRenderer = GetComponent<SkeletonRenderer>();
			Skeleton skeleton = skeletonRenderer.skeleton;

			customSkin = new Skin("CustomSkin");

			foreach (var pair in skinItems) {
				var attachment = SpineAttachment.GetAttachment(pair.sourceAttachmentPath, skinSource);
				customSkin.AddAttachment(skeleton.FindSlotIndex(pair.targetSlot), pair.targetAttachment, attachment);
			}

			// The custom skin does not need to be added to the skeleton data for it to work.
			// But it's useful for your script to keep a reference to it.
			skeleton.SetSkin(customSkin);
		}
开发者ID:SirFelolis,项目名称:Snot-Ninja,代码行数:15,代码来源:CustomSkin.cs


示例4: NewSkinnedMeshAttachment

		public SkinnedMeshAttachment NewSkinnedMeshAttachment (Skin skin, String name, String path) {
			AtlasRegion region = atlas.FindRegion(path);
			if (region == null) throw new Exception("Region not found in atlas: " + path + " (skinned mesh attachment: " + name + ")");
			SkinnedMeshAttachment attachment = new SkinnedMeshAttachment(name);
			attachment.RendererObject = region;
			attachment.RegionU = region.u;
			attachment.RegionV = region.v;
			attachment.RegionU2 = region.u2;
			attachment.RegionV2 = region.v2;
			attachment.RegionRotate = region.rotate;
			attachment.regionOffsetX = region.offsetX;
			attachment.regionOffsetY = region.offsetY;
			attachment.regionWidth = region.width;
			attachment.regionHeight = region.height;
			attachment.regionOriginalWidth = region.originalWidth;
			attachment.regionOriginalHeight = region.originalHeight;
			return attachment;
		}
开发者ID:460189852,项目名称:cocos-sharp-samples,代码行数:18,代码来源:AtlasAttachmentLoader.cs


示例5: NewAttachment

 public Attachment NewAttachment(Skin skin, AttachmentType type, String name)
 {
     switch (type) {
     case AttachmentType.region:
         AtlasRegion region = atlas.FindRegion(name);
         if (region == null) throw new Exception("Region not found in atlas: " + name + " (" + type + ")");
         RegionAttachment attachment = new RegionAttachment(name);
         attachment.RendererObject = region.page.rendererObject;
         attachment.SetUVs(region.u, region.v, region.u2, region.v2, region.rotate);
         attachment.RegionOffsetX = region.offsetX;
         attachment.RegionOffsetY = region.offsetY;
         attachment.RegionWidth = region.width;
         attachment.RegionHeight = region.height;
         attachment.RegionOriginalWidth = region.originalWidth;
         attachment.RegionOriginalHeight = region.originalHeight;
         return attachment;
     }
     throw new Exception("Unknown attachment type: " + type);
 }
开发者ID:kamaliang,项目名称:spine-runtimes,代码行数:19,代码来源:AtlasAttachmentLoader.cs


示例6: ReadSkeletonData


//.........这里部分代码省略.........
					data.shearMix = GetFloat(constraintMap, "shearMix", 1);

					skeletonData.transformConstraints.Add(data);
				}
			}

			// Path constraints.
			if(root.ContainsKey("path")) {
				foreach (Dictionary<String, Object> constraintMap in (List<Object>)root["path"]) {
					PathConstraintData data = new PathConstraintData((String)constraintMap["name"]);
					data.order = GetInt(constraintMap, "order", 0);

					foreach (String boneName in (List<Object>)constraintMap["bones"]) {
						BoneData bone = skeletonData.FindBone(boneName);
						if (bone == null) throw new Exception("Path bone not found: " + boneName);
						data.bones.Add(bone);
					}

					String targetName = (String)constraintMap["target"];
					data.target = skeletonData.FindSlot(targetName);
					if (data.target == null) throw new Exception("Target slot not found: " + targetName);

					data.positionMode = (PositionMode)Enum.Parse(typeof(PositionMode), GetString(constraintMap, "positionMode", "percent"), true);
					data.spacingMode = (SpacingMode)Enum.Parse(typeof(SpacingMode), GetString(constraintMap, "spacingMode", "length"), true);
					data.rotateMode = (RotateMode)Enum.Parse(typeof(RotateMode), GetString(constraintMap, "rotateMode", "tangent"), true);
					data.offsetRotation = GetFloat(constraintMap, "rotation", 0);
					data.position = GetFloat(constraintMap, "position", 0);
					if (data.positionMode == PositionMode.Fixed) data.position *= scale;
					data.spacing = GetFloat(constraintMap, "spacing", 0);
					if (data.spacingMode == SpacingMode.Length || data.spacingMode == SpacingMode.Fixed) data.spacing *= scale;
					data.rotateMix = GetFloat(constraintMap, "rotateMix", 1);
					data.translateMix = GetFloat(constraintMap, "translateMix", 1);

					skeletonData.pathConstraints.Add(data);
				}
			}

			// Skins.
			if (root.ContainsKey("skins")) {
					foreach (KeyValuePair<String, Object> skinMap in (Dictionary<String, Object>)root["skins"]) {
					var skin = new Skin(skinMap.Key);
					foreach (KeyValuePair<String, Object> slotEntry in (Dictionary<String, Object>)skinMap.Value) {
						int slotIndex = skeletonData.FindSlotIndex(slotEntry.Key);
						foreach (KeyValuePair<String, Object> entry in ((Dictionary<String, Object>)slotEntry.Value)) {
							try {
								Attachment attachment = ReadAttachment((Dictionary<String, Object>)entry.Value, skin, slotIndex, entry.Key);
								if (attachment != null) skin.AddAttachment(slotIndex, entry.Key, attachment);
							} catch (Exception e) {
								throw new Exception("Error reading attachment: " + entry.Key + ", skin: " + skin, e);
							}
						} 
					}
					skeletonData.skins.Add(skin);
					if (skin.name == "default") skeletonData.defaultSkin = skin;
				}
			}

			// Linked meshes.
			for (int i = 0, n = linkedMeshes.Count; i < n; i++) {
				LinkedMesh linkedMesh = linkedMeshes[i];
				Skin skin = linkedMesh.skin == null ? skeletonData.defaultSkin : skeletonData.FindSkin(linkedMesh.skin);
				if (skin == null) throw new Exception("Slot not found: " + linkedMesh.skin);
				Attachment parent = skin.GetAttachment(linkedMesh.slotIndex, linkedMesh.parent);
				if (parent == null) throw new Exception("Parent mesh not found: " + linkedMesh.parent);
				linkedMesh.mesh.ParentMesh = (MeshAttachment)parent;
				linkedMesh.mesh.UpdateUVs();
			}
			linkedMeshes.Clear();

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

			// Animations.
			if (root.ContainsKey("animations")) {
				foreach (KeyValuePair<String, Object> entry in (Dictionary<String, Object>)root["animations"]) {
					try {
						ReadAnimation((Dictionary<String, Object>)entry.Value, entry.Key, skeletonData);
					} catch (Exception e) {
						throw new Exception("Error reading animation: " + entry.Key, e);
					}
				}   
			}

			skeletonData.bones.TrimExcess();
			skeletonData.slots.TrimExcess();
			skeletonData.skins.TrimExcess();
			skeletonData.events.TrimExcess();
			skeletonData.animations.TrimExcess();
			skeletonData.ikConstraints.TrimExcess();
			return skeletonData;
		}
开发者ID:EsotericSoftware,项目名称:spine-runtimes,代码行数:101,代码来源:SkeletonJson.cs


示例7: ReadAttachment

		private Attachment ReadAttachment (Dictionary<String, Object> map, Skin skin, int slotIndex, String name) {
			var scale = this.Scale;
			name = GetString(map, "name", name);

			var typeName = GetString(map, "type", "region");
			if (typeName == "skinnedmesh") typeName = "weightedmesh";
			if (typeName == "weightedmesh") typeName = "mesh";
			if (typeName == "weightedlinkedmesh") typeName = "linkedmesh";
			var type = (AttachmentType)Enum.Parse(typeof(AttachmentType), typeName, true);

			String path = GetString(map, "path", name);

			switch (type) {
			case AttachmentType.Region:
				RegionAttachment region = attachmentLoader.NewRegionAttachment(skin, name, path);
				if (region == null) return null;
				region.Path = path;
				region.x = GetFloat(map, "x", 0) * scale;
				region.y = GetFloat(map, "y", 0) * scale;
				region.scaleX = GetFloat(map, "scaleX", 1);
				region.scaleY = GetFloat(map, "scaleY", 1);
				region.rotation = GetFloat(map, "rotation", 0);
				region.width = GetFloat(map, "width", 32) * scale;
				region.height = GetFloat(map, "height", 32) * scale;
				region.UpdateOffset();

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

				region.UpdateOffset();
				return region;
			case AttachmentType.Boundingbox:
				BoundingBoxAttachment box = attachmentLoader.NewBoundingBoxAttachment(skin, name);
				if (box == null) return null;
				ReadVertices(map, box, GetInt(map, "vertexCount", 0) << 1);
				return box;
			case AttachmentType.Mesh:
			case AttachmentType.Linkedmesh: {
					MeshAttachment mesh = attachmentLoader.NewMeshAttachment(skin, name, path);
					if (mesh == null) return null;
					mesh.Path = path;

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

					mesh.Width = GetFloat(map, "width", 0) * scale;
					mesh.Height = GetFloat(map, "height", 0) * scale;

					String parent = GetString(map, "parent", null);
					if (parent != null) {
						mesh.InheritDeform = GetBoolean(map, "deform", true);
						linkedMeshes.Add(new LinkedMesh(mesh, GetString(map, "skin", null), slotIndex, parent));
						return mesh;
					}

					float[] uvs = GetFloatArray(map, "uvs", 1);
					ReadVertices(map, mesh, uvs.Length);
					mesh.triangles = GetIntArray(map, "triangles");
					mesh.regionUVs = uvs;
					mesh.UpdateUVs();

					if (map.ContainsKey("hull")) mesh.HullLength = GetInt(map, "hull", 0) * 2;
					if (map.ContainsKey("edges")) mesh.Edges = GetIntArray(map, "edges");
					return mesh;
				}
			case AttachmentType.Path: {
					PathAttachment pathAttachment = attachmentLoader.NewPathAttachment(skin, name);
					if (pathAttachment == null) return null;
					pathAttachment.closed = GetBoolean(map, "closed", false);
					pathAttachment.constantSpeed = GetBoolean(map, "constantSpeed", true);

					int vertexCount = GetInt(map, "vertexCount", 0);
					ReadVertices(map, pathAttachment, vertexCount << 1);

					// potential BOZO see Java impl
					pathAttachment.lengths = GetFloatArray(map, "lengths", scale);
					return pathAttachment;
				}
			}
			return null;
		}
开发者ID:EsotericSoftware,项目名称:spine-runtimes,代码行数:91,代码来源:SkeletonJson.cs


示例8: 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:jaimeBokoko,项目名称:spine-runtimes,代码行数:97,代码来源:SkeletonJson.cs


示例9: ReadAttachment

		private Attachment ReadAttachment (Skin skin, String name, Dictionary<String, Object> map) {
			if (map.ContainsKey("name"))
				name = (String)map["name"];

			AttachmentType type = AttachmentType.region;
			if (map.ContainsKey("type"))
				type = (AttachmentType)Enum.Parse(typeof(AttachmentType), (String)map["type"], false);
			Attachment attachment = attachmentLoader.NewAttachment(skin, type, name);

			RegionAttachment regionAttachment = attachment as RegionAttachment;
			if (regionAttachment != null) {
				regionAttachment.x = GetFloat(map, "x", 0) * Scale;
				regionAttachment.y = GetFloat(map, "y", 0) * Scale;
				regionAttachment.scaleX = GetFloat(map, "scaleX", 1);
				regionAttachment.scaleY = GetFloat(map, "scaleY", 1);
				regionAttachment.rotation = GetFloat(map, "rotation", 0);
				regionAttachment.width = GetFloat(map, "width", 32) * Scale;
				regionAttachment.height = GetFloat(map, "height", 32) * Scale;
				regionAttachment.UpdateOffset();
			}

			BoundingBoxAttachment boundingBox = attachment as BoundingBoxAttachment;
			if (boundingBox != null) {
				List<Object> values = (List<Object>)map["vertices"];
				float[] vertices = new float[values.Count];
				for (int i = 0, n = values.Count; i < n; i++)
					vertices[i] = (float)values[i];
				boundingBox.Vertices = vertices;
			}

			return attachment;
		}
开发者ID:jaimeBokoko,项目名称:spine-runtimes,代码行数:32,代码来源:SkeletonJson.cs


示例10: NewPathAttachment

		public PathAttachment NewPathAttachment (Skin skin, String name) {
			return new PathAttachment (name);
		}
开发者ID:X-Ray-Jin,项目名称:spine-runtimes,代码行数:3,代码来源:AtlasAttachmentLoader.cs


示例11: InstantiateSkeletonAnimation

		public static SkeletonAnimation InstantiateSkeletonAnimation (SkeletonDataAsset skeletonDataAsset, Skin skin = null, bool destroyInvalid = true) {
			SkeletonData data = skeletonDataAsset.GetSkeletonData(true);

			if (data == null) {
				for (int i = 0; i < skeletonDataAsset.atlasAssets.Length; i++) {
					string reloadAtlasPath = AssetDatabase.GetAssetPath(skeletonDataAsset.atlasAssets[i]);
					skeletonDataAsset.atlasAssets[i] = (AtlasAsset)AssetDatabase.LoadAssetAtPath(reloadAtlasPath, typeof(AtlasAsset));
				}
				data = skeletonDataAsset.GetSkeletonData(false);
			}

			if (data == null) {
				Debug.LogWarning("InstantiateSkeletonAnimation tried to instantiate a skeleton from an invalid SkeletonDataAsset.");
				return null;
			}

			if (skin == null) skin = data.DefaultSkin;
			if (skin == null) skin = data.Skins.Items[0];

			string spineGameObjectName = string.Format("Spine GameObject ({0})", skeletonDataAsset.name.Replace("_SkeletonData", ""));
			GameObject go = new GameObject(spineGameObjectName, typeof(MeshFilter), typeof(MeshRenderer), typeof(SkeletonAnimation));
			SkeletonAnimation newSkeletonAnimation = go.GetComponent<SkeletonAnimation>();
			newSkeletonAnimation.skeletonDataAsset = skeletonDataAsset;

			{
				bool requiresNormals = false;
				foreach (AtlasAsset atlasAsset in skeletonDataAsset.atlasAssets) {
					foreach (Material m in atlasAsset.materials) {
						if (m.shader.name.Contains("Lit")) {
							requiresNormals = true;
							break;
						}
					}
				}
				newSkeletonAnimation.calculateNormals = requiresNormals;
			}

			try {
				newSkeletonAnimation.Initialize(false);
			} catch (System.Exception e) {
				if (destroyInvalid) {
					Debug.LogWarning("Editor-instantiated SkeletonAnimation threw an Exception. Destroying GameObject to prevent orphaned GameObject.");
					GameObject.DestroyImmediate(go);
				}
				throw e;
			}

			newSkeletonAnimation.skeleton.SetSkin(skin);
			newSkeletonAnimation.initialSkinName = skin.Name;

			newSkeletonAnimation.skeleton.Update(1);
			newSkeletonAnimation.state.Update(1);
			newSkeletonAnimation.state.Apply(newSkeletonAnimation.skeleton);
			newSkeletonAnimation.skeleton.UpdateWorldTransform();

			return newSkeletonAnimation;
		}
开发者ID:X-Ray-Jin,项目名称:spine-runtimes,代码行数:57,代码来源:SpineEditorUtilities.cs


示例12: NewMeshAttachment

		public MeshAttachment NewMeshAttachment (Skin skin, string name, string path) {
			//MITCH : Left todo: Unity 5 only
			return null;
		}
开发者ID:Colorwen,项目名称:spine-runtimes,代码行数:4,代码来源:SpriteAttacher.cs


示例13: NewBoundingBoxAttachment

		public BoundingBoxAttachment NewBoundingBoxAttachment (Skin skin, String name) {
			return new BoundingBoxAttachment(name);
		}
开发者ID:460189852,项目名称:cocos-sharp-samples,代码行数:3,代码来源:AtlasAttachmentLoader.cs


示例14: SortPathConstraintAttachment

		private void SortPathConstraintAttachment (Skin skin, int slotIndex, Bone slotBone) {
			foreach (var entry in skin.Attachments)
				if (entry.Key.slotIndex == slotIndex) SortPathConstraintAttachment(entry.Value, slotBone);
		}
开发者ID:EsotericSoftware,项目名称:spine-runtimes,代码行数:4,代码来源:Skeleton.cs


示例15: NewRegionAttachment

		public RegionAttachment NewRegionAttachment (Skin skin, string name, string path) {
			RegionAttachment attachment = new RegionAttachment(name);

			Texture2D tex = sprite.texture;
			int instanceId = tex.GetInstanceID();
			AtlasRegion atlasRegion;

			// Check cache first
			if (atlasTable.ContainsKey(instanceId)) {
				atlasRegion = atlasTable[instanceId];
			} else {
				// Setup new material.
				var material = new Material(shader);
				if (sprite.packed)
					material.name = "Unity Packed Sprite Material";
				else
					material.name = sprite.name + " Sprite Material";
				material.mainTexture = tex;

				// Create faux-region to play nice with SkeletonRenderer.
				atlasRegion = new AtlasRegion();
				AtlasPage page = new AtlasPage();
				page.rendererObject = material;
				atlasRegion.page = page;

				// Cache it.
				atlasTable[instanceId] = atlasRegion;
			}

			Rect texRect = sprite.textureRect;

			//normalize rect to UV space of packed atlas
			texRect.x = Mathf.InverseLerp(0, tex.width, texRect.x);
			texRect.y = Mathf.InverseLerp(0, tex.height, texRect.y);
			texRect.width = Mathf.InverseLerp(0, tex.width, texRect.width);
			texRect.height = Mathf.InverseLerp(0, tex.height, texRect.height);

			Bounds bounds = sprite.bounds;
			Vector3 size = bounds.size;

			//MITCH: left todo: make sure this rotation thing actually works
			bool rotated = false;
			if (sprite.packed)
				rotated = sprite.packingRotation == SpritePackingRotation.Any;

			attachment.SetUVs(texRect.xMin, texRect.yMax, texRect.xMax, texRect.yMin, rotated);
			attachment.RendererObject = atlasRegion;
			attachment.SetColor(Color.white);
			attachment.ScaleX = 1;
			attachment.ScaleY = 1;
			attachment.RegionOffsetX = sprite.rect.width * (0.5f - InverseLerp(bounds.min.x, bounds.max.x, 0)) / sprite.pixelsPerUnit;
			attachment.RegionOffsetY = sprite.rect.height * (0.5f - InverseLerp(bounds.min.y, bounds.max.y, 0)) / sprite.pixelsPerUnit;
			attachment.Width = size.x;
			attachment.Height = size.y;
			attachment.RegionWidth = size.x;
			attachment.RegionHeight = size.y;
			attachment.RegionOriginalWidth = size.x;
			attachment.RegionOriginalHeight = size.y;
			attachment.UpdateOffset();

			return attachment;
		}
开发者ID:Colorwen,项目名称:spine-runtimes,代码行数:62,代码来源:SpriteAttacher.cs


示例16: InstantiateSkeletonGraphic

		public static SkeletonGraphic InstantiateSkeletonGraphic (SkeletonDataAsset skeletonDataAsset, Skin skin = null) {
			string spineGameObjectName = string.Format("SkeletonGraphic ({0})", skeletonDataAsset.name.Replace("_SkeletonData", ""));
			var go = NewSkeletonGraphicGameObject(spineGameObjectName);
			var graphic = go.GetComponent<SkeletonGraphic>();
			graphic.skeletonDataAsset = skeletonDataAsset;

			SkeletonData data = skeletonDataAsset.GetSkeletonData(true);

			if (data == null) {
				for (int i = 0; i < skeletonDataAsset.atlasAssets.Length; i++) {
					string reloadAtlasPath = AssetDatabase.GetAssetPath(skeletonDataAsset.atlasAssets[i]);
					skeletonDataAsset.atlasAssets[i] = (AtlasAsset)AssetDatabase.LoadAssetAtPath(reloadAtlasPath, typeof(AtlasAsset));
				}

				data = skeletonDataAsset.GetSkeletonData(true);
			}

			if (skin == null)
				skin = data.DefaultSkin;

			if (skin == null)
				skin = data.Skins.Items[0];

			graphic.Initialize(false);
			graphic.Skeleton.SetSkin(skin);
			graphic.initialSkinName = skin.Name;
			graphic.Skeleton.UpdateWorldTransform();
			graphic.UpdateMesh();

			return graphic;
		}
开发者ID:EsotericSoftware,项目名称:spine-runtimes,代码行数:31,代码来源:SkeletonGraphicInspector.cs


示例17: NewMeshAttachment

			public MeshAttachment NewMeshAttachment (Skin skin, string name, string path) {
				requirementList.Add(path);
				return new MeshAttachment(name);
			}
开发者ID:X-Ray-Jin,项目名称:spine-runtimes,代码行数:4,代码来源:SpineEditorUtilities.cs


示例18: InstantiateSkeletonAnimator

		public static SkeletonAnimator InstantiateSkeletonAnimator (SkeletonDataAsset skeletonDataAsset, Skin skin = null) {
			string spineGameObjectName = string.Format("Spine Mecanim GameObject ({0})", skeletonDataAsset.name.Replace("_SkeletonData", ""));
			GameObject go = new GameObject(spineGameObjectName, typeof(MeshFilter), typeof(MeshRenderer), typeof(Animator), typeof(SkeletonAnimator));

			if (skeletonDataAsset.controller == null) {
				SkeletonBaker.GenerateMecanimAnimationClips(skeletonDataAsset);
			}

			go.GetComponent<Animator>().runtimeAnimatorController = skeletonDataAsset.controller;

			SkeletonAnimator anim = go.GetComponent<SkeletonAnimator>();
			anim.skeletonDataAsset = skeletonDataAsset;

			bool requiresNormals = false;

			foreach (AtlasAsset atlasAsset in anim.skeletonDataAsset.atlasAssets) {
				foreach (Material m in atlasAsset.materials) {
					if (m.shader.name.Contains("Lit")) {
						requiresNormals = true;
						break;
					}
				}
			}

			anim.calculateNormals = requiresNormals;

			SkeletonData data = skeletonDataAsset.GetSkeletonData(true);

			if (data == null) {
				for (int i = 0; i < skeletonDataAsset.atlasAssets.Length; i++) {
					string reloadAtlasPath = AssetDatabase.GetAssetPath(skeletonDataAsset.atlasAssets[i]);
					skeletonDataAsset.atlasAssets[i] = (AtlasAsset)AssetDatabase.LoadAssetAtPath(reloadAtlasPath, typeof(AtlasAsset));
				}

				data = skeletonDataAsset.GetSkeletonData(true);
			}

			if (skin == null)
				skin = data.DefaultSkin;

			if (skin == null)
				skin = data.Skins.Items[0];

			anim.Initialize(false);

			anim.skeleton.SetSkin(skin);
			anim.initialSkinName = skin.Name;

			anim.skeleton.Update(1);
			anim.skeleton.UpdateWorldTransform();
			anim.LateUpdate();

			return anim;
		}
开发者ID:X-Ray-Jin,项目名称:spine-runtimes,代码行数:54,代码来源:SpineEditorUtilities.cs


示例19: ReadAttachment

		private Attachment ReadAttachment (Stream input, Skin skin, int slotIndex, String attachmentName, bool nonessential) {
			float scale = Scale;

			String name = ReadString(input);
			if (name == null) name = attachmentName;

			AttachmentType type = (AttachmentType)input.ReadByte();
			switch (type) {
			case AttachmentType.Region: {
					String path = ReadString(input);
					float rotation = ReadFloat(input);		
					float x = ReadFloat(input);
					float y = ReadFloat(input);
					float scaleX = ReadFloat(input);
					float scaleY = ReadFloat(input);
					float width = ReadFloat(input);
					float height = ReadFloat(input);
					int color = ReadInt(input);

					if (path == null) path = name;
					RegionAttachment region = attachmentLoader.NewRegionAttachment(skin, name, path);
					if (region == null) return null;
					region.Path = path;
					region.x = x * scale;
					region.y = y * scale;
					region.scaleX = scaleX;
					region.scaleY = scaleY;
					region.rotation = rotation;
					region.width = width * scale;
					region.height = height * scale;
					region.r = ((color & 0xff000000) >> 24) / 255f;
					region.g = ((color & 0x00ff0000) >> 16) / 255f;
					region.b = ((color & 0x0000ff00) >> 8) / 255f;
					region.a = ((color & 0x000000ff)) / 255f;
					region.UpdateOffset();
					return region;
				}
			case AttachmentType.Boundingbox: {
					int vertexCount = ReadVarint(input, true);
					Vertices vertices = ReadVertices(input, vertexCount);
					if (nonessential) ReadInt(input); //int color = nonessential ? ReadInt(input) : 0; // Avoid unused local warning.
					
					BoundingBoxAttachment box = attachmentLoader.NewBoundingBoxAttachment(skin, name);
					if (box == null) return null;
					box.worldVerticesLength = vertexCount << 1;
					box.vertices = vertices.vertices;
					box.bones = vertices.bones;                    
					return box;
				}
			case AttachmentType.Mesh: {
					String path = ReadString(input);
					int color = ReadInt(input);
					int vertexCount = ReadVarint(input, true);					
					float[] uvs = ReadFloatArray(input, vertexCount << 1, 1);
					int[] triangles = ReadShortArray(input);
					Vertices vertices = ReadVertices(input, vertexCount);
					int hullLength = ReadVarint(input, true);
					int[] edges = null;
					float width = 0, height = 0;
					if (nonessential) {
						edges = ReadShortArray(input);
						width = ReadFloat(input);
						height = ReadFloat(input);
					}

					if (path == null) path = name;
					MeshAttachment mesh = attachmentLoader.NewMeshAttachment(skin, name, path);
					if (mesh == null) return null;
					mesh.Path = path;
					mesh.r = ((color & 0xff000000) >> 24) / 255f;
					mesh.g = ((color & 0x00ff0000) >> 16) / 255f;
					mesh.b = ((color & 0x0000ff00) >> 8) / 255f;
					mesh.a = ((color & 0x000000ff)) / 255f;
					mesh.bones = vertices.bones;
					mesh.vertices = vertices.vertices;
					mesh.WorldVerticesLength = vertexCount << 1;
					mesh.triangles = triangles;
					mesh.regionUVs = uvs;
					mesh.UpdateUVs();
					mesh.HullLength = hullLength << 1;
					if (nonessential) {
						mesh.Edges = edges;
						mesh.Width = width * scale;
						mesh.Height = height * scale;
					}
					return mesh;
				}
			case AttachmentType.Linkedmesh: {
					String path = ReadString(input);
					int color = ReadInt(input);
					String skinName = ReadString(input);
					String parent = ReadString(input);
					bool inheritDeform = ReadBoolean(input);
					float width = 0, height = 0;
					if (nonessential) {
						width = ReadFloat(input);
						height = ReadFloat(input);
					}

					if (path == null) path = name;
//.........这里部分代码省略.........
开发者ID:EsotericSoftware,项目名称:spine-runtimes,代码行数:101,代码来源:SkeletonBinary.cs


示例20: 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);
                skeletonData.AddBone(boneData);
            }

            // Slots.
            if (root.ContainsKey("slots")) {
                var slots = (List<Object>)root["slots"];
                foreach (Dictionary<String, Object> slotMap in (List<Object>)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"];

                    skeletonData.AddSlot(slotData);
                }
            }

            // Skins.
            if (root.ContainsKey("skins")) {
                Dictionary<String, Object> skinMap = (Dictionary<String, Object>)root["skins"];
                foreach (KeyValuePair<String, Object> entry in skinMap) {
                    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);
                            skin.AddAttachment(slotIndex, attachmentEntry.Key, attachment);
                        }
                    }
                    skeletonData.AddSkin(skin);
                    if (skin.Name == "default")
                        skeletonData.DefaultSkin = skin;
                }
            }

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

            skeletonData.Bones.TrimExcess();
            skeletonData.Slots.TrimExcess();
            skeletonData.Skins.TrimExcess();
            skeletonData.Animations.TrimExcess();
            return skeletonData;
        }
开发者ID:H4ch1k0,项目名称:spine-runtimes,代码行数:84,代码来源:SkeletonJson.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Entities.Cart类代码示例发布时间:2022-05-26
下一篇:
C# Spine.SkeletonData类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap