本文整理汇总了C#中Spine.SkeletonData类的典型用法代码示例。如果您正苦于以下问题:C# SkeletonData类的具体用法?C# SkeletonData怎么用?C# SkeletonData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SkeletonData类属于Spine命名空间,在下文中一共展示了SkeletonData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Skeleton
public Skeleton (SkeletonData data) {
if (data == null) throw new ArgumentNullException("data cannot be null.");
this.data = data;
bones = new ExposedList<Bone>(data.bones.Count);
foreach (BoneData boneData in data.bones) {
Bone parent = boneData.parent == null ? null : bones.Items[data.bones.IndexOf(boneData.parent)];
Bone bone = new Bone(boneData, this, parent);
if (parent != null) parent.children.Add(bone);
bones.Add(bone);
}
slots = new ExposedList<Slot>(data.slots.Count);
drawOrder = new ExposedList<Slot>(data.slots.Count);
foreach (SlotData slotData in data.slots) {
Bone bone = bones.Items[data.bones.IndexOf(slotData.boneData)];
Slot slot = new Slot(slotData, bone);
slots.Add(slot);
drawOrder.Add(slot);
}
ikConstraints = new ExposedList<IkConstraint>(data.ikConstraints.Count);
foreach (IkConstraintData ikConstraintData in data.ikConstraints)
ikConstraints.Add(new IkConstraint(ikConstraintData, this));
transformConstraints = new ExposedList<TransformConstraint>(data.transformConstraints.Count);
foreach (TransformConstraintData transformConstraintData in data.transformConstraints)
transformConstraints.Add(new TransformConstraint(transformConstraintData, this));
UpdateCache();
UpdateWorldTransform();
}
示例2: AnimationPlayer
public AnimationPlayer(SkeletonData skeletonData)
{
this.skeletonData = skeletonData;
skeleton = new Skeleton(skeletonData);
skeleton.SetSlotsToSetupPose();
animationDataPool = new ObjectPool<AnimationData>(() => new AnimationData(), 10);
}
示例3: OnEnable
void OnEnable () {
SpineEditorUtilities.ConfirmInitialization();
try {
atlasAssets = serializedObject.FindProperty("atlasAssets");
atlasAssets.isExpanded = true;
skeletonJSON = serializedObject.FindProperty("skeletonJSON");
scale = serializedObject.FindProperty("scale");
fromAnimation = serializedObject.FindProperty("fromAnimation");
toAnimation = serializedObject.FindProperty("toAnimation");
duration = serializedObject.FindProperty("duration");
defaultMix = serializedObject.FindProperty("defaultMix");
#if SPINE_SKELETON_ANIMATOR
controller = serializedObject.FindProperty("controller");
#endif
#if SPINE_TK2D
spriteCollection = serializedObject.FindProperty("spriteCollection");
#endif
m_skeletonDataAsset = (SkeletonDataAsset)target;
m_skeletonDataAssetGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_skeletonDataAsset));
EditorApplication.update += Update;
} catch {
// TODO: WARNING: empty catch block supresses errors.
}
m_skeletonData = m_skeletonDataAsset.GetSkeletonData(true);
showBaking = EditorPrefs.GetBool("SkeletonDataAssetInspector_showUnity", false);
RepopulateWarnings();
}
示例4: OnEnable
void OnEnable () {
SpineEditorUtilities.ConfirmInitialization();
try {
atlasAssets = serializedObject.FindProperty("atlasAssets");
skeletonJSON = serializedObject.FindProperty("skeletonJSON");
scale = serializedObject.FindProperty("scale");
fromAnimation = serializedObject.FindProperty("fromAnimation");
toAnimation = serializedObject.FindProperty("toAnimation");
duration = serializedObject.FindProperty("duration");
defaultMix = serializedObject.FindProperty("defaultMix");
controller = serializedObject.FindProperty("controller");
#if SPINE_TK2D
spriteCollection = serializedObject.FindProperty("spriteCollection");
#endif
m_skeletonDataAsset = (SkeletonDataAsset)target;
m_skeletonDataAssetGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_skeletonDataAsset));
EditorApplication.update += Update;
} catch {
}
m_skeletonData = m_skeletonDataAsset.GetSkeletonData(true);
showUnity = EditorPrefs.GetBool("SkeletonDataAssetInspector_showUnity", true);
RepopulateWarnings();
}
示例5: MakeSkeletonAndAnimationData
/*
*/
private void MakeSkeletonAndAnimationData()
{
if(sprites == null) {
Debug.LogWarning("Sprite collection not set for skeleton data asset: " + name,this);
return;
}
if(skeletonJSON == null) {
Debug.LogWarning("Skeleton JSON file not set for skeleton data asset: " + name,this);
return;
}
SkeletonJson json = new SkeletonJson(new tk2dSpineAttachmentLoader(sprites.spriteCollection));
json.Scale = scale;
try {
skeletonData = json.ReadSkeletonData(new StringReader(skeletonJSON.text));
} catch (Exception ex) {
Debug.Log("Error reading skeleton JSON file for skeleton data asset: " + name + "\n" + ex.Message + "\n" + ex.StackTrace,this);
return;
}
stateData = new AnimationStateData(skeletonData);
for(int i = 0, n = fromAnimation.Length; i < n; i++) {
if(fromAnimation[i].Length == 0 || toAnimation[i].Length == 0) continue;
stateData.SetMix(fromAnimation[i],toAnimation[i],duration[i]);
}
}
示例6: Skeleton
public Skeleton (SkeletonData data) {
if (data == null) throw new ArgumentNullException("data cannot be null.");
this.data = data;
bones = new List<Bone>(data.bones.Count);
foreach (BoneData boneData in data.bones) {
Bone parent = boneData.parent == null ? null : bones[data.bones.IndexOf(boneData.parent)];
bones.Add(new Bone(boneData, this, parent));
}
slots = new List<Slot>(data.slots.Count);
drawOrder = new List<Slot>(data.slots.Count);
foreach (SlotData slotData in data.slots) {
Bone bone = bones[data.bones.IndexOf(slotData.boneData)];
Slot slot = new Slot(slotData, bone);
slots.Add(slot);
drawOrder.Add(slot);
}
ikConstraints = new List<IkConstraint>(data.ikConstraints.Count);
foreach (IkConstraintData ikConstraintData in data.ikConstraints)
ikConstraints.Add(new IkConstraint(ikConstraintData, this));
UpdateCache();
}
示例7: OnEnable
void OnEnable () {
SpineEditorUtilities.ConfirmInitialization();
atlasAssets = serializedObject.FindProperty("atlasAssets");
skeletonJSON = serializedObject.FindProperty("skeletonJSON");
scale = serializedObject.FindProperty("scale");
fromAnimation = serializedObject.FindProperty("fromAnimation");
toAnimation = serializedObject.FindProperty("toAnimation");
duration = serializedObject.FindProperty("duration");
defaultMix = serializedObject.FindProperty("defaultMix");
#if SPINE_SKELETON_ANIMATOR
controller = serializedObject.FindProperty("controller");
#endif
#if SPINE_TK2D
atlasAssets.isExpanded = false;
spriteCollection = serializedObject.FindProperty("spriteCollection");
#else
atlasAssets.isExpanded = true;
#endif
#if SPINE_BAKING
isBakingExpanded = EditorPrefs.GetBool(ShowBakingPrefsKey, false);
#endif
m_skeletonDataAsset = (SkeletonDataAsset)target;
m_skeletonDataAssetGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_skeletonDataAsset));
EditorApplication.update += EditorUpdate;
m_skeletonData = m_skeletonDataAsset.GetSkeletonData(false);
RepopulateWarnings();
}
示例8: Skeleton
public Skeleton(SkeletonData data)
{
if (data == null) throw new ArgumentNullException("data cannot be null.");
Data = data;
Bones = new List<Bone>(Data.Bones.Count);
foreach (BoneData boneData in Data.Bones) {
Bone parent = boneData.Parent == null ? null : Bones[Data.Bones.IndexOf(boneData.Parent)];
Bones.Add(new Bone(boneData, parent));
}
Slots = new List<Slot>(Data.Slots.Count);
DrawOrder = new List<Slot>(Data.Slots.Count);
foreach (SlotData slotData in Data.Slots) {
Bone bone = Bones[Data.Bones.IndexOf(slotData.BoneData)];
Slot slot = new Slot(slotData, this, bone);
Slots.Add(slot);
DrawOrder.Add(slot);
}
R = 1;
G = 1;
B = 1;
A = 1;
}
示例9: LoadContent
protected override void LoadContent()
{
Effect spriteBatchEffect = Content.Load<Effect>("SpriteBatchEffect");
spriteBatch = new SpriteBatchEx(GraphicsDevice, spriteBatchEffect);
Bone.yDown = true;
skeletonData = Content.Load<SkeletonData>("spineboy/spineboy");
skeleton = new Skeleton(skeletonData);
skeleton.SetSlotsToSetupPose();
AnimationStateData stateData = new AnimationStateData(skeleton.Data);
animationState = new AnimationState(stateData);
animationState.SetAnimation(0, "walk", true);
skeleton.UpdateWorldTransform();
}
示例10: GetSkeletonData
public SkeletonData GetSkeletonData (bool quiet) {
if (atlasAsset == null) {
if (!quiet)
Debug.LogError("Atlas not set for SkeletonData asset: " + name, this);
Reset();
return null;
}
// if (skeletonJSON == null) {
if (string.IsNullOrEmpty(skeletonJsonStr)) {
if (!quiet)
Debug.LogError("Skeleton JSON file not set for SkeletonData asset: " + name, this);
Reset();
return null;
}
Atlas atlas = atlasAsset.GetAtlas();
if (atlas == null) {
Reset();
return null;
}
if (skeletonData != null)
return skeletonData;
SkeletonJson json = new SkeletonJson(atlas);
json.Scale = scale;
try {
// skeletonData = json.ReadSkeletonData(new StringReader(skeletonJSON.text));
skeletonData = json.ReadSkeletonData(new StringReader(skeletonJsonStr));
}
catch (Exception ex)
{
if (!quiet)
Debug.LogError("Error reading skeleton JSON file for SkeletonData asset: " + name + "\n" + ex.Message + "\n" + ex.StackTrace, this);
return null;
}
stateData = new AnimationStateData(skeletonData);
stateData.DefaultMix = defaultMix;
for (int i = 0, n = fromAnimation.Length; i < n; i++) {
if (fromAnimation[i].Length == 0 || toAnimation[i].Length == 0) continue;
stateData.SetMix(fromAnimation[i], toAnimation[i], duration[i]);
}
return skeletonData;
}
示例11: GetSkeletonData
public SkeletonData GetSkeletonData(bool quiet)
{
if (atlasAsset == null) {
if (!quiet)
Debug.LogWarning("Atlas not set for skeleton data asset: " + name, this);
Clear();
return null;
}
if (skeletonJSON == null) {
if (!quiet)
Debug.LogWarning("Skeleton JSON file not set for skeleton data asset: " + name, this);
Clear();
return null;
}
Atlas atlas = atlasAsset.GetAtlas();
if (atlas == null) {
Clear();
return null;
}
if (skeletonData != null)
return skeletonData;
SkeletonJson json = new SkeletonJson(atlas);
json.Scale = scale;
try {
skeletonData = json.ReadSkeletonData(new StringReader(skeletonJSON.text));
} catch (Exception) {
if (!quiet)
Debug.LogException(new Exception("Error reading skeleton JSON file for skeleton data asset: " + name), this);
return null;
}
stateData = new AnimationStateData(skeletonData);
for (int i = 0, n = fromAnimation.Length; i < n; i++)
stateData.SetMix(fromAnimation[i], toAnimation[i], duration[i]);
return skeletonData;
}
示例12: GetSkeletonData
public SkeletonData GetSkeletonData (bool quiet) {
if (spriteCollection == null) {
if (!quiet)
Debug.LogWarning("Sprite collection not set for skeleton data asset: " + name, this);
Clear();
return null;
}
if (skeletonJSON == null) {
if (!quiet)
Debug.LogWarning("Skeleton JSON file not set for skeleton data asset: " + name, this);
Clear();
return null;
}
if (skeletonData != null)
return skeletonData;
SkeletonJson json = new SkeletonJson(new SpriteCollectionAttachmentLoader(spriteCollection));
json.Scale = 1.0f / (spriteCollection.invOrthoSize * spriteCollection.halfTargetHeight) * scale;
try {
skeletonData = json.ReadSkeletonData(new StringReader(skeletonJSON.text));
} catch (Exception ex) {
Debug.Log("Error reading skeleton JSON file for skeleton data asset: " + name + "\n" +
ex.Message + "\n" + ex.StackTrace, this);
return null;
}
stateData = new AnimationStateData(skeletonData);
for (int i = 0, n = fromAnimation.Length; i < n; i++) {
if (fromAnimation[i].Length == 0 || toAnimation[i].Length == 0)
continue;
stateData.SetMix(fromAnimation[i], toAnimation[i], duration[i]);
}
return skeletonData;
}
示例13: readAnimation
private void readAnimation(String name, Dictionary<String, Object> map, SkeletonData skeletonData)
{
var timelines = new List<Timeline>();
float duration = 0;
var bonesMap = (Dictionary<String, Object>)map["bones"];
foreach (KeyValuePair<String, Object> entry in bonesMap) {
String boneName = entry.Key;
int boneIndex = skeletonData.FindBoneIndex(boneName);
if (boneIndex == -1)
throw new Exception("Bone not found: " + boneName);
Dictionary<String, Object> timelineMap = (Dictionary<String, Object>)entry.Value;
foreach (KeyValuePair<String, Object> timelineEntry in timelineMap) {
List<Object> values = (List<Object>)timelineEntry.Value;
String timelineName = (String)timelineEntry.Key;
if (timelineName.Equals(TIMELINE_ROTATE)) {
RotateTimeline timeline = new RotateTimeline(values.Count);
timeline.BoneIndex = boneIndex;
int frameIndex = 0;
foreach (Dictionary<String, Object> valueMap in values) {
float time = (float)valueMap["time"];
timeline.SetFrame(frameIndex, time, (float)valueMap["angle"]);
readCurve(timeline, frameIndex, valueMap);
frameIndex++;
}
timelines.Add(timeline);
duration = Math.Max(duration, timeline.Frames[timeline.FrameCount * 2 - 2]);
} else if (timelineName.Equals(TIMELINE_TRANSLATE) || timelineName.Equals(TIMELINE_SCALE)) {
TranslateTimeline timeline;
float timelineScale = 1;
if (timelineName.Equals(TIMELINE_SCALE))
timeline = new ScaleTimeline(values.Count);
else {
timeline = new TranslateTimeline(values.Count);
timelineScale = Scale;
}
timeline.BoneIndex = boneIndex;
int frameIndex = 0;
foreach (Dictionary<String, Object> valueMap in values) {
float time = (float)valueMap["time"];
float x = valueMap.ContainsKey("x") ? (float)valueMap["x"] : 0;
float y = valueMap.ContainsKey("y") ? (float)valueMap["y"] : 0;
timeline.SetFrame(frameIndex, time, (float)x * timelineScale, (float)y * timelineScale);
readCurve(timeline, frameIndex, valueMap);
frameIndex++;
}
timelines.Add(timeline);
duration = Math.Max(duration, timeline.Frames[timeline.FrameCount * 3 - 3]);
} else
throw new Exception("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")");
}
}
if (map.ContainsKey("slots")) {
Dictionary<String, Object> slotsMap = (Dictionary<String, Object>)map["slots"];
foreach (KeyValuePair<String, Object> entry in slotsMap) {
String slotName = entry.Key;
int slotIndex = skeletonData.FindSlotIndex(slotName);
Dictionary<String, Object> timelineMap = (Dictionary<String, Object>)entry.Value;
foreach (KeyValuePair<String, Object> timelineEntry in timelineMap) {
List<Object> values = (List<Object>)timelineEntry.Value;
String timelineName = (String)timelineEntry.Key;
if (timelineName.Equals(TIMELINE_COLOR)) {
ColorTimeline timeline = new ColorTimeline(values.Count);
timeline.SlotIndex = slotIndex;
int frameIndex = 0;
foreach (Dictionary<String, Object> valueMap in values) {
float time = (float)valueMap["time"];
String c = (String)valueMap["color"];
timeline.setFrame(frameIndex, time, toColor(c, 0), toColor(c, 1), toColor(c, 2), toColor(c, 3));
readCurve(timeline, frameIndex, valueMap);
frameIndex++;
}
timelines.Add(timeline);
duration = Math.Max(duration, timeline.Frames[timeline.FrameCount * 5 - 5]);
} else if (timelineName.Equals(TIMELINE_ATTACHMENT)) {
AttachmentTimeline timeline = new AttachmentTimeline(values.Count);
timeline.SlotIndex = slotIndex;
int frameIndex = 0;
foreach (Dictionary<String, Object> valueMap in values) {
float time = (float)valueMap["time"];
timeline.setFrame(frameIndex++, time, (String)valueMap["name"]);
}
timelines.Add(timeline);
duration = Math.Max(duration, timeline.Frames[timeline.FrameCount - 1]);
} else
throw new Exception("Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")");
}
}
}
//.........这里部分代码省略.........
示例14: CCSkeletonAnimation
public CCSkeletonAnimation(SkeletonData skeletonData)
: base(skeletonData,false)
{
this.initializer();
}
示例15: ReadSkeletonData
public SkeletonData ReadSkeletonData (TextReader reader) {
if (reader == null) throw new ArgumentNullException("reader", "reader cannot be null.");
var scale = this.Scale;
var skeletonData = new SkeletonData();
var root = Json.Deserialize(reader) as Dictionary<String, Object>;
if (root == null) throw new Exception("Invalid JSON.");
// Skeleton.
if (root.ContainsKey("skeleton")) {
var skeletonMap = (Dictionary<String, Object>)root["skeleton"];
skeletonData.hash = (String)skeletonMap["hash"];
skeletonData.version = (String)skeletonMap["spine"];
skeletonData.width = GetFloat(skeletonMap, "width", 0);
skeletonData.height = GetFloat(skeletonMap, "height", 0);
skeletonData.fps = GetFloat(skeletonMap, "fps", 0);
skeletonData.imagesPath = GetString(skeletonMap, "images", null);
}
// 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"]);
}
var data = new BoneData(skeletonData.Bones.Count, (String)boneMap["name"], parent);
data.length = GetFloat(boneMap, "length", 0) * scale;
data.x = GetFloat(boneMap, "x", 0) * scale;
data.y = GetFloat(boneMap, "y", 0) * scale;
data.rotation = GetFloat(boneMap, "rotation", 0);
data.scaleX = GetFloat(boneMap, "scaleX", 1);
data.scaleY = GetFloat(boneMap, "scaleY", 1);
data.shearX = GetFloat(boneMap, "shearX", 0);
data.shearY = GetFloat(boneMap, "shearY", 0);
string tm = GetString(boneMap, "transform", TransformMode.Normal.ToString());
data.transformMode = (TransformMode)Enum.Parse(typeof(TransformMode), tm, true);
skeletonData.bones.Add(data);
}
// 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 data = new SlotData(skeletonData.Slots.Count, slotName, boneData);
if (slotMap.ContainsKey("color")) {
var color = (String)slotMap["color"];
data.r = ToColor(color, 0);
data.g = ToColor(color, 1);
data.b = ToColor(color, 2);
data.a = ToColor(color, 3);
}
data.attachmentName = GetString(slotMap, "attachment", null);
if (slotMap.ContainsKey("blend"))
data.blendMode = (BlendMode)Enum.Parse(typeof(BlendMode), (String)slotMap["blend"], false);
else
data.blendMode = BlendMode.normal;
skeletonData.slots.Add(data);
}
}
// IK constraints.
if (root.ContainsKey("ik")) {
foreach (Dictionary<String, Object> constraintMap in (List<Object>)root["ik"]) {
IkConstraintData data = new IkConstraintData((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("IK constraint bone not found: " + boneName);
data.bones.Add(bone);
}
String targetName = (String)constraintMap["target"];
data.target = skeletonData.FindBone(targetName);
if (data.target == null) throw new Exception("Target bone not found: " + targetName);
data.bendDirection = GetBoolean(constraintMap, "bendPositive", true) ? 1 : -1;
data.mix = GetFloat(constraintMap, "mix", 1);
skeletonData.ikConstraints.Add(data);
}
}
// Transform constraints.
if (root.ContainsKey("transform")) {
foreach (Dictionary<String, Object> constraintMap in (List<Object>)root["transform"]) {
TransformConstraintData data = new TransformConstraintData((String)constraintMap["name"]);
data.order = GetInt(constraintMap, "order", 0);
foreach (String boneName in (List<Object>)constraintMap["bones"]) {
//.........这里部分代码省略.........