本文整理汇总了C#中Spine.Skin类的典型用法代码示例。如果您正苦于以下问题:C# Skin类的具体用法?C# Skin怎么用?C# Skin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Skin类属于Spine命名空间,在下文中一共展示了Skin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例10: NewPathAttachment
public PathAttachment NewPathAttachment (Skin skin, String name) {
return new PathAttachment (name);
}
示例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;
}
示例12: NewMeshAttachment
public MeshAttachment NewMeshAttachment (Skin skin, string name, string path) {
//MITCH : Left todo: Unity 5 only
return null;
}
示例13: NewBoundingBoxAttachment
public BoundingBoxAttachment NewBoundingBoxAttachment (Skin skin, String name) {
return new BoundingBoxAttachment(name);
}
示例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);
}
示例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;
}