本文整理汇总了C#中Spine.Skin.AddAttachment方法的典型用法代码示例。如果您正苦于以下问题:C# Skin.AddAttachment方法的具体用法?C# Skin.AddAttachment怎么用?C# Skin.AddAttachment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Spine.Skin
的用法示例。
在下文中一共展示了Skin.AddAttachment方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
void Start () {
skeletonRenderer = GetComponent<SkeletonRenderer>();
Skeleton skeleton = skeletonRenderer.skeleton;
customSkin = new Skin("CustomSkin");
foreach (var pair in skinning) {
var attachment = SpineAttachment.GetAttachment(pair.sourceAttachment, skinSource);
customSkin.AddAttachment(skeleton.FindSlotIndex(pair.targetSlot), pair.targetAttachment, attachment);
}
skeleton.SetSkin(customSkin);
}
示例2: 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);
}
示例3: ReadSkeletonData
//.........这里部分代码省略.........
ikConstraintData.mix = GetFloat(ikMap, "mix", 1);
skeletonData.ikConstraints.Add(ikConstraintData);
}
}
// Transform constraints.
if (root.ContainsKey("transform")) {
foreach (Dictionary<String, Object> transformMap in (List<Object>)root["ik"]) {
TransformConstraintData transformConstraintData = new TransformConstraintData((String)transformMap["name"]);
String boneName = (String)transformMap["bone"];
transformConstraintData.target = skeletonData.FindBone(boneName);
if (transformConstraintData.target == null) throw new Exception("Bone not found: " + boneName);
String targetName = (String)transformMap["target"];
transformConstraintData.target = skeletonData.FindBone(targetName);
if (transformConstraintData.target == null) throw new Exception("Target bone not found: " + targetName);
transformConstraintData.translateMix = GetFloat(transformMap, "mix", 1);
transformConstraintData.x = GetFloat(transformMap, "x", 0);
transformConstraintData.y = GetFloat(transformMap, "y", 0);
skeletonData.transformConstraints.Add(transformConstraintData);
}
}
// Slots.
if (root.ContainsKey("slots")) {
foreach (Dictionary<String, Object> slotMap in (List<Object>)root["slots"]) {
var slotName = (String)slotMap["name"];
var boneName = (String)slotMap["bone"];
BoneData boneData = skeletonData.FindBone(boneName);
if (boneData == null)
throw new Exception("Slot bone not found: " + boneName);
var slotData = new SlotData(slotName, boneData);
if (slotMap.ContainsKey("color")) {
var 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("blend"))
slotData.blendMode = (BlendMode)Enum.Parse(typeof(BlendMode), (String)slotMap["blend"], false);
else
slotData.blendMode = BlendMode.normal;
skeletonData.slots.Add(slotData);
}
}
// Skins.
if (root.ContainsKey("skins")) {
foreach (KeyValuePair<String, Object> entry in (Dictionary<String, Object>)root["skins"]) {
var 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.skins.Add(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;
var eventData = new EventData(entry.Key);
eventData.Int = GetInt(entryMap, "int", 0);
eventData.Float = GetFloat(entryMap, "float", 0);
eventData.String = GetString(entryMap, "string", null);
skeletonData.events.Add(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.events.TrimExcess();
skeletonData.animations.TrimExcess();
skeletonData.ikConstraints.TrimExcess();
return skeletonData;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: ReadSkin
/** @return May be null. */
private Skin ReadSkin (Stream input, String skinName, bool nonessential) {
int slotCount = ReadInt(input, true);
if (slotCount == 0) return null;
Skin skin = new Skin(skinName);
for (int i = 0; i < slotCount; i++) {
int slotIndex = ReadInt(input, true);
for (int ii = 0, nn = ReadInt(input, true); ii < nn; ii++) {
String name = ReadString(input);
skin.AddAttachment(slotIndex, name, ReadAttachment(input, skin, name, nonessential));
}
}
return skin;
}