public override void Initialize(GraphicsDevice gd) { _skeletonRenderer = new SkeletonRenderer(gd); _skeletonRenderer.PremultipliedAlpha = Props.UseAlpha; _effect = _skeletonRenderer.Effect as BasicEffect; _atlas = new Atlas(Info.AtlasFile, new XnaTextureLoader(gd, Info.PremultipliedAlpha)); SkeletonData skeletonData; if (System.IO.Path.GetExtension(Info.SpineFile) == ".skel") { SkeletonBinary binary = new SkeletonBinary(_atlas); binary.Scale = Info.Scale; skeletonData = binary.ReadSkeletonData(Info.SpineFile); } else { SkeletonJson json = new SkeletonJson(_atlas); json.Scale = Info.Scale; skeletonData = json.ReadSkeletonData(Info.SpineFile); } _skeleton = new Skeleton(skeletonData); _skeleton.X = 0; _skeleton.Y = 0; _skeleton.FlipX = Props.FlipX; _skeleton.FlipY = Props.FlipY; AnimationStateData stateData = new AnimationStateData(_skeleton.Data); _state = new AnimationState(stateData); string curSkin = _skeleton.Data.Skins.Items[0].Name; string curAnim = _skeleton.Data.Animations.Items[0].Name; _state.SetAnimation(0, curAnim, Props.IsLoop); // Return spine info Props.Skin = curSkin; Props.Anim = curAnim; Info.Version = skeletonData.Version; Info.OrgWidth = skeletonData.Width; Info.OrgHeight = skeletonData.Height; foreach (Animation ani in _state.Data.skeletonData.Animations) { Info.AnimNames.Add(ani.Name); } foreach (Skin sk in _state.Data.skeletonData.Skins) { Info.SkinNames.Add(sk.Name); } IsLoaded = true; }
public SkeletonData GetSkeletonData(bool quiet) { if (spriteCollection == null) { if (!quiet) { Debug.LogError("Sprite collection not set for skeleton data asset: " + name, this); } Reset(); return(null); } if (skeletonJSON == null) { if (!quiet) { Debug.LogError("Skeleton JSON file not set for skeleton data asset: " + name, this); } Reset(); 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) { 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); }
protected void LoadContent(GraphicsDevice gD) { skeletonRenderer = new SkeletonRenderer(gD); skeletonRenderer.PremultipliedAlpha = true; String name = "spineboy"; // "goblins"; Atlas atlas = new Atlas("data/" + name + ".atlas", new XnaTextureLoader(gD)); SkeletonJson json = new SkeletonJson(atlas); skeleton = new Skeleton(json.ReadSkeletonData("data/" + name + ".json")); if (name == "goblins") { skeleton.SetSkin("goblingirl"); } skeleton.SetSlotsToSetupPose(); // Without this the skin attachments won't be attached. See SetSkin. // Define mixing between animations. AnimationStateData stateData = new AnimationStateData(skeleton.Data); if (name == "spineboy") { stateData.SetMix("walk", "jump", 0.2f); stateData.SetMix("jump", "walk", 0.4f); } state = new AnimationState(stateData); if (false) { // Event handling for all animations. state.Start += Start; state.End += End; state.Complete += Complete; state.Event += Event; state.SetAnimation(0, "drawOrder", true); } else { state.SetAnimation(0, "walk", false); TrackEntry entry = state.AddAnimation(0, "jump", false, 0); entry.End += new EventHandler <StartEndArgs>(End); // Event handling for queued animations. state.AddAnimation(0, "walk", true, 0); } skeleton.X = 320; skeleton.Y = 440; skeleton.UpdateWorldTransform(); headSlot = skeleton.FindSlot("head"); }
public void LoadContent(ContentManager contentManager) { skeletonRenderer = new SkeletonRenderer(App.graphicsDevice); skeletonRenderer.PremultipliedAlpha = App.GV.Alpha; atlas = new Atlas(App.GV.SelectFile, new XnaTextureLoader(App.graphicsDevice)); if (Common.IsBinaryData(App.GV.SelectFile)) { binary = new SkeletonBinary(atlas); binary.Scale = App.GV.Scale; skeletonData = binary.ReadSkeletonData(Common.GetSkelPath(App.GV.SelectFile)); } else { json = new SkeletonJson(atlas); json.Scale = App.GV.Scale; skeletonData = json.ReadSkeletonData(Common.GetJsonPath(App.GV.SelectFile)); } skeleton = new Skeleton(skeletonData); if (App.isNew) { App.GV.PosX = Convert.ToSingle(App.GV.FrameWidth / 2f); App.GV.PosY = Convert.ToSingle((skeleton.Data.Height + App.GV.FrameHeight) / 2f); } App.GV.FileHash = skeleton.Data.Hash; stateData = new AnimationStateData(skeleton.Data); state = new AnimationState(stateData); App.GV.AnimeList = state.Data.skeletonData.Animations.Select(x => x.Name).ToList(); App.GV.SkinList = state.Data.skeletonData.Skins.Select(x => x.Name).ToList(); if (App.GV.SelectAnimeName != "") { state.SetAnimation(0, App.GV.SelectAnimeName, App.GV.IsLoop); } else { state.SetAnimation(0, state.Data.skeletonData.animations.Items[0].name, App.GV.IsLoop); } if (App.isNew) { MainWindow.SetCBAnimeName(); } App.isNew = false; }
public void SetSkeletonData(SkeletonData data) { this.skeletonData = data; 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]); } }
public void LoadContent(ContentManager contentManager) { skeletonRenderer = new SkeletonRenderer(App.graphicsDevice); skeletonRenderer.PremultipliedAlpha = App.globalValues.Alpha; atlas = new Atlas(App.globalValues.SelectAtlasFile, new XnaTextureLoader(App.graphicsDevice)); if (Common.IsBinaryData(App.globalValues.SelectSpineFile)) { binary = new SkeletonBinary(atlas); binary.Scale = App.globalValues.Scale; skeletonData = binary.ReadSkeletonData(App.globalValues.SelectSpineFile); } else { json = new SkeletonJson(atlas); json.Scale = App.globalValues.Scale; skeletonData = json.ReadSkeletonData(App.globalValues.SelectSpineFile); } App.globalValues.SpineVersion = skeletonData.Version; skeleton = new Skeleton(skeletonData); Common.SetInitLocation(skeleton.Data.Height); App.globalValues.FileHash = skeleton.Data.Hash; stateData = new AnimationStateData(skeleton.Data); state = new AnimationState(stateData); App.globalValues.AnimeList = state.Data.skeletonData.Animations.Select(x => x.Name).ToList(); App.globalValues.SkinList = state.Data.skeletonData.Skins.Select(x => x.Name).ToList(); if (App.globalValues.SelectAnimeName != "") { state.SetAnimation(0, App.globalValues.SelectAnimeName, App.globalValues.IsLoop); } else { state.SetAnimation(0, state.Data.skeletonData.animations.Items[0].name, App.globalValues.IsLoop); } if (App.isNew) { MainWindow.SetCBAnimeName(); } App.isNew = false; }
public override void Fire() { animInProgress = true; AnimationStateData stateData = new AnimationStateData(rockAnim.skeletonDataAsset.GetSkeletonData(false)); Spine.AnimationState newState = new Spine.AnimationState(stateData); newState.SetAnimation(0, rockDescendAnim, false); newState.AddAnimation(0, rockFinishedAnim, true, 0); rockAnim.state = newState; rockAnim.timeScale = rockDescendSpeedMultiplier; rockAnim.state.Complete += OnAnimEnd; deltaYPerSecond = gateTransform.lossyScale.y / duration; audioSource.Play(); Invoke("AudioEnd", duration - 1); }
public SpineObject(GraphicsDevice Graphics, string filename, float scale, Vector2 pos, string headSlot = "head") { skeletonRenderer = new SkeletonMeshRenderer(Graphics); skeletonRenderer.PremultipliedAlpha = true; Atlas atlas = new Atlas("Content/" + filename + ".atlas", new XnaTextureLoader(Graphics)); SkeletonData skeletonData; SkeletonJson json = new SkeletonJson(atlas); json.Scale = scale; skeletonData = json.ReadSkeletonData("Content/" + filename + ".json"); skeleton = new Skeleton(skeletonData); AnimationStateData stateData = new AnimationStateData(skeleton.Data); state = new AnimationState(stateData); this.pos = pos; this.headSlot = skeleton.FindSlot(headSlot); }
public virtual void Load(Atlas atlas, string animName) { SkeletonData skeletonData; SkeletonJson json = new SkeletonJson(atlas); json.Scale = 1.0f; skeletonData = json.ReadSkeletonData(animName + ".json"); Skeleton = new Skeleton(skeletonData); AnimStateData = new AnimationStateData(Skeleton.Data); AnimState = new AnimationState(AnimStateData); Skeleton.X = Position.X; Skeleton.Y = Position.Y; Skeleton.UpdateWorldTransform(); }
private void Setup(bool reload = false) { if (SkeletonData == null || reload) { SkeletonData = _skeletonJson.ReadSkeletonData(); SkeletonData.Name = "skeleton"; } if (Skeleton == null || reload) { Skeleton = new Skeleton(SkeletonData); } if (AnimationState == null || reload) { _animationStateData = new AnimationStateData(Skeleton.Data); AnimationState = new AnimationState(_animationStateData); } }
public override void Load(Atlas atlas, string animName) { SkeletonData skeletonData; SkeletonJson json = new SkeletonJson(atlas); json.Scale = 1.0f; skeletonData = json.ReadSkeletonData(animName + ".json"); Skeleton = new Skeleton(skeletonData); AnimStateData = new AnimationStateData(Skeleton.Data); AnimStateData.SetMix("idle", "run", 0.1f); AnimStateData.SetMix("run", "idle", 0.1f); AnimState = new AnimationState(AnimStateData); AnimState.SetAnimation(0, "idle", true); Skeleton.X = Position.X; Skeleton.Y = Position.Y; Skeleton.UpdateWorldTransform(); }
/// <summary> /// Performs further custom initialization for this instance. /// </summary> /// <remarks> /// By default this method does nothing. /// </remarks> protected override void Initialize() { base.Initialize(); SkeletonJson json = new SkeletonJson(this.SkeletalData.Atlas); this.Skeleton = new Skeleton(json.ReadSkeletonData(this.animationPath)); if (string.IsNullOrEmpty(this.currentSkin)) { this.Skeleton.SetSkin(this.Skeleton.Data.DefaultSkin); } else { this.Skeleton.SetSkin(this.currentSkin); } AnimationStateData stateData = new AnimationStateData(this.Skeleton.Data); this.state = new AnimationState(stateData); this.state.End += this.OnEndAnimation; }
public Animation2D(string AnimationFile) { skeletonRenderer = new SkeletonRenderer(true); String name = AnimationFile; Atlas atlas = new Atlas("Data/" + name + ".atlas", new GLImpTextureLoader()); SkeletonJson json = new SkeletonJson(atlas); skeleton = new Skeleton(json.ReadSkeletonData("Data/" + name + ".json")); skeleton.SetSlotsToSetupPose(); // Define mixing between animations. stateData = new AnimationStateData(skeleton.Data); state = new AnimationState(stateData); skeleton.X = 0; skeleton.Y = 0.1f; skeleton.UpdateWorldTransform(); drawtime = new Stopwatch(); drawtime.Start(); }
public void LoadContent(ContentLoader content) { SkeletonBounds = new SkeletonBounds(); var Loader = Entity.World.Get <SpineTextureLoader>(); Skeleton = Loader.Load(Image); var NormalsImage = Image + "_normals.png"; if (System.IO.File.Exists(content.RootDirectory + "\\" + NormalsImage)) { NormalMap = content.Load <Texture2D>(NormalsImage); } UpdateSkeletonEffect(); SetSkin(Data.Skin); AnimationStateData = AnimationStateData ?? new AnimationStateData(Skeleton.Data); AnimationMixFn?.Invoke(AnimationStateData); if (AnimationState == null) { AnimationState = new AnimationState(AnimationStateData); AnimationState.Complete += AnimationComplete; AnimationState.Event += AnimationState_Event; } if (!string.IsNullOrEmpty(AnimationName)) { AnimationState.SetAnimation(0, AnimationName, true); AnimationState.Update(AnimationTime); AnimationState.Apply(Skeleton); } AnimationState.End += AnimationState_End; }
public object Clone() { SpineAnimation clone = (SpineAnimation)this.MemberwiseClone(); SkeletonData skeletonData; SkeletonJson json = new SkeletonJson(atlas); skeletonData = json.ReadSkeletonData(this.filesName + ".json"); this.skeleton = new Skeleton(skeletonData); clone.skeleton = new Skeleton(skeletonData); AnimationStateData animationStateData = new AnimationStateData(skeleton.Data); clone.animationState = new AnimationState(animationStateData); clone.animationState.SetAnimation(0, this.animationName, true); clone.Position = Vector2.Zero; clone.skeleton.UpdateWorldTransform(); return(clone); }
// build the sprite and slots with the skeleton data private void BuildSkeleton(SkeletonData skeletonData) { skeleton = new Skeleton(skeletonData); skeleton.UpdateWorldTransform(); // check if there are multiple skins loaded if (skeleton.Data.Skins.Count > 0) { // load the first skin as default SetSkin(skeleton.Data.Skins[0].Name); } // build all the child sprites in the container, add them based on the slot draw order and create using the default slot/attachment for (int i = 0; i < skeleton.DrawOrder.Count; i++) { GSpineSlot slot = new GSpineSlot(skeleton.DrawOrder[i]); slots.Add(slot); AddChild(slot); } AnimationStateData animationStateData = new AnimationStateData(skeleton.Data); animation = new Spine.AnimationState(animationStateData); }
public SkeletonData GetSkeletonData(bool quiet) { if (atlasAssets == null) { atlasAssets = new AtlasAsset[0]; if (!quiet) { Debug.LogError("Atlas not set for SkeletonData asset: " + name, this); } Reset(); return(null); } if (skeletonJSON == null) { if (!quiet) { Debug.LogError("Skeleton JSON file not set for SkeletonData asset: " + name, this); } Reset(); return(null); } #if !SPINE_TK2D if (atlasAssets.Length == 0) { Reset(); return(null); } #else if (atlasAssets.Length == 0 && spriteCollection == null) { Reset(); return(null); } #endif Atlas[] atlasArr = new Atlas[atlasAssets.Length]; for (int i = 0; i < atlasAssets.Length; i++) { if (atlasAssets[i] == null) { Reset(); return(null); } atlasArr[i] = atlasAssets[i].GetAtlas(); if (atlasArr[i] == null) { Reset(); return(null); } } if (skeletonData != null) { return(skeletonData); } AttachmentLoader attachmentLoader; float skeletonDataScale; #if !SPINE_TK2D attachmentLoader = new AtlasAttachmentLoader(atlasArr); skeletonDataScale = scale; #else if (spriteCollection != null) { attachmentLoader = new Spine.Unity.TK2D.SpriteCollectionAttachmentLoader(spriteCollection); skeletonDataScale = (1.0f / (spriteCollection.invOrthoSize * spriteCollection.halfTargetHeight) * scale); } else { if (atlasArr.Length == 0) { Reset(); if (!quiet) { Debug.LogError("Atlas not set for SkeletonData asset: " + name, this); } return(null); } attachmentLoader = new AtlasAttachmentLoader(atlasArr); skeletonDataScale = scale; } #endif try { //var stopwatch = new System.Diagnostics.Stopwatch(); if (skeletonJSON.name.ToLower().Contains(".skel")) { var input = new MemoryStream(skeletonJSON.bytes); var binary = new SkeletonBinary(attachmentLoader); binary.Scale = skeletonDataScale; //stopwatch.Start(); skeletonData = binary.ReadSkeletonData(input); } else { var input = new StringReader(skeletonJSON.text); var json = new SkeletonJson(attachmentLoader); json.Scale = skeletonDataScale; //stopwatch.Start(); skeletonData = json.ReadSkeletonData(input); } //stopwatch.Stop(); //Debug.Log(stopwatch.Elapsed); } 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); FillStateData(); return(skeletonData); }
public void Reset() { skeletonData = null; stateData = null; }
internal void InitializeWithData(SkeletonData sd) { this.skeletonData = sd; this.stateData = new AnimationStateData(skeletonData); FillStateData(); }
/// <summary>Clears the loaded SkeletonData and AnimationStateData. Use this to force a reload for the next time GetSkeletonData is called.</summary> public void Clear() { skeletonData = null; stateData = null; }
public Pack LoadSkeleton(string jsonFile, string atlasFile, string animation, string skin, float scale, float x, float y) { Atlas atlas = new Atlas(assetsFolder + atlasFile + ".atlas", new LoveTextureLoader()); var json = new SkeletonJson(atlas); json.Scale = scale; var skeletonData = json.ReadSkeletonData(assetsFolder + jsonFile + ".json"); var skeleton = new Skeleton(skeletonData); skeleton.X = x; skeleton.Y = y; skeleton.ScaleY = -1; if (skin != null) { skeleton.SetSkin(skin); } skeleton.SetToSetupPose(); var stateData = new AnimationStateData(skeletonData); var state = new AnimationState(stateData); state.SetAnimation(0, animation, true); if (jsonFile == "spineboy-ess") { stateData.SetMix("walk", "jump", 0.5f); stateData.SetMix("jump", "run", 0.5f); state.AddAnimation(0, "jump", false, 3); state.AddAnimation(0, "run", true, 0); } if (jsonFile == "raptor-pro") { swirl.CenterY = -200; //skeleton.VertexEffect = swirl; } if (jsonFile == "mix-and-match-pro") { // Create a new skin, by mixing and matching other skins // that fit together. Items making up the girl are individual // skins. Using the skin API, a new skin is created which is // a combination of all these individual item skins. var lskin = new Skin("mix-and-match"); lskin.AddSkin(skeletonData.FindSkin("skin-base")); lskin.AddSkin(skeletonData.FindSkin("nose/short")); lskin.AddSkin(skeletonData.FindSkin("eyelids/girly")); lskin.AddSkin(skeletonData.FindSkin("eyes/violet")); lskin.AddSkin(skeletonData.FindSkin("hair/brown")); lskin.AddSkin(skeletonData.FindSkin("clothes/hoodie-orange")); lskin.AddSkin(skeletonData.FindSkin("legs/pants-jeans")); lskin.AddSkin(skeletonData.FindSkin("accessories/bag")); lskin.AddSkin(skeletonData.FindSkin("accessories/hat-red-yellow")); skeleton.SetSkin(lskin); } // set some event callbacks state.Start += (entry) => Console.WriteLine(entry.TrackIndex + " start: " + entry.Animation.Name); state.Interrupt += (entry) => Console.WriteLine(entry.TrackIndex + " interrupt: " + entry.Animation.Name); state.End += (entry) => Console.WriteLine(entry.TrackIndex + " end: " + entry.Animation.Name); state.Complete += (entry) => Console.WriteLine(entry.TrackIndex + " complete: " + entry.Animation.Name); state.Dispose += (entry) => Console.WriteLine(entry.TrackIndex + " dispose: " + entry.Animation.Name); state.Event += (entry, e) => Console.WriteLine( entry.TrackIndex + " event: " + entry.Animation.Name + ", " + e.Data.Name + ", " + e.Int + ", " + e.Float + ", '" + e.String + "'" + ", " + e.Volume + ", " + e.Balance ); state.Update(0.5f); state.Apply(skeleton); return(new Pack(skeleton, state)); }
/// <summary> /// Refresh the animation /// </summary> private void RefreshAnimation() { if (this.SkeletalData.Atlas == null) { return; } if (this.Skeleton != null) { this.Skeleton = null; } if (this.State != null) { this.state.Event -= this.OnEventAnimation; this.state.End -= this.OnEndAnimation; this.state = null; } try { if (!string.IsNullOrEmpty(this.animationPath)) { using (var fileStream = WaveServices.Storage.OpenContentFile(this.animationPath)) { SkeletonData skeletonData = null; var pathExtension = Path.GetExtension(this.animationPath.ToLowerInvariant()); if (pathExtension == ".skel") { SkeletonBinary binary = new SkeletonBinary(this.SkeletalData.Atlas); skeletonData = binary.ReadSkeletonData(fileStream); } else { using (var streamReader = new StreamReader(fileStream)) { SkeletonJson json = new SkeletonJson(this.SkeletalData.Atlas); skeletonData = json.ReadSkeletonData(streamReader); } } this.Skeleton = new Skeleton(skeletonData); } if (string.IsNullOrEmpty(this.currentAnimation) || !this.AnimationNames.Any(animation => animation == this.currentAnimation)) { this.currentAnimation = string.Empty; } if (string.IsNullOrEmpty(this.currentSkin) || !this.SkinNames.Any(skin => skin == this.currentSkin)) { this.currentSkin = this.Skeleton.Data.DefaultSkin.Name; } this.Skeleton.SetSkin(this.currentSkin); if (this.OnAnimationRefresh != null) { this.OnAnimationRefresh(this, EventArgs.Empty); } AnimationStateData stateData = new AnimationStateData(this.Skeleton.Data); this.state = new AnimationState(stateData); this.state.Event += this.OnEventAnimation; this.state.End += this.OnEndAnimation; this.Update(TimeSpan.Zero); } } catch (Exception e) { Debug.WriteLine("The atlas file is not valid: " + e.Message); this.Skeleton = null; this.state = null; } }
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 && skeletonBinary == null) { if (!quiet) { Debug.LogError("Skeleton 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); } if (skeletonBinary != null) { SkeletonBin binary = new SkeletonBin(atlas); try { skeletonData = binary.LoadSkeletonBinary(skeletonBinary.bytes); }catch (Exception ex) { Debug.LogError(name + "\n" + ex.Message + "\n" + ex.StackTrace, this); return(null); } } else { SkeletonJson json = new SkeletonJson(atlas); json.Scale = scale; try { skeletonData = json.ReadSkeletonData(new StringReader(skeletonJSON.text)); } 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); }
public void LoadContent(ContentManager contentManager) { skeletonRenderer = new SkeletonRenderer(App.graphicsDevice); skeletonRenderer.PremultipliedAlpha = App.globalValues.Alpha; atlas = new Atlas(App.globalValues.SelectAtlasFile, new XnaTextureLoader(App.graphicsDevice)); if (Common.IsBinaryData(App.globalValues.SelectSpineFile)) { binary = new SkeletonBinary(atlas); binary.Scale = App.globalValues.Scale; skeletonData = binary.ReadSkeletonData(App.globalValues.SelectSpineFile); } else { json = new SkeletonJson(atlas); json.Scale = App.globalValues.Scale; skeletonData = json.ReadSkeletonData(App.globalValues.SelectSpineFile); } App.globalValues.SpineVersion = skeletonData.Version; skeleton = new Skeleton(skeletonData); Common.SetInitLocation(skeleton.Data.Height); App.globalValues.FileHash = skeleton.Data.Hash; stateData = new AnimationStateData(skeleton.Data); state = new AnimationState(stateData); List <string> AnimationNames = new List <string>(); listAnimation = state.Data.skeletonData.Animations; foreach (Animation An in listAnimation) { AnimationNames.Add(An.name); } App.globalValues.AnimeList = AnimationNames; List <string> SkinNames = new List <string>(); listSkin = state.Data.skeletonData.Skins; foreach (Skin Sk in listSkin) { SkinNames.Add(Sk.name); } App.globalValues.SkinList = SkinNames; if (App.globalValues.SelectAnimeName != "") { state.SetAnimation(0, App.globalValues.SelectAnimeName, App.globalValues.IsLoop); } else { state.SetAnimation(0, state.Data.skeletonData.animations.Items[0].name, App.globalValues.IsLoop); } if (App.isNew) { App.globalValues.PosX = (float)App.canvasWidth / 2; App.globalValues.PosY = (float)App.canvasHeight / 2; MainWindow.SetCBAnimeName(); } App.isNew = false; }
protected override void LoadContent() { // Two color tint effect, comment line 80 to disable var spineEffect = Content.Load <Effect>("Content\\SpineEffect"); spineEffect.Parameters["World"].SetValue(Matrix.Identity); spineEffect.Parameters["View"].SetValue(Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 1.0f), Vector3.Zero, Vector3.Up)); skeletonRenderer = new SkeletonRenderer(GraphicsDevice); skeletonRenderer.PremultipliedAlpha = false; skeletonRenderer.Effect = spineEffect; // String name = "spineboy-ess"; // String name = "goblins-pro"; // String name = "raptor-pro"; // String name = "tank-pro"; String name = "raptor-pro"; String atlasName = name.Replace("-pro", "").Replace("-ess", ""); bool binaryData = false; Atlas atlas = new Atlas(assetsFolder + atlasName + ".atlas", new XnaTextureLoader(GraphicsDevice)); float scale = 1; if (name == "spineboy-ess") { scale = 0.6f; } if (name == "raptor-pro") { scale = 0.5f; } if (name == "tank-pro") { scale = 0.3f; } if (name == "coin-pro") { scale = 1; } SkeletonData skeletonData; if (binaryData) { SkeletonBinary binary = new SkeletonBinary(atlas); binary.Scale = scale; skeletonData = binary.ReadSkeletonData(assetsFolder + name + ".skel"); } else { SkeletonJson json = new SkeletonJson(atlas); json.Scale = scale; skeletonData = json.ReadSkeletonData(assetsFolder + name + ".json"); } skeleton = new Skeleton(skeletonData); if (name == "goblins-pro") { skeleton.SetSkin("goblin"); } // Define mixing between animations. AnimationStateData stateData = new AnimationStateData(skeleton.Data); state = new AnimationState(stateData); if (name == "spineboy-ess") { stateData.SetMix("run", "jump", 0.2f); stateData.SetMix("jump", "run", 0.4f); // Event handling for all animations. state.Start += Start; state.End += End; state.Complete += Complete; state.Event += Event; state.SetAnimation(0, "walk", false); TrackEntry entry = state.AddAnimation(0, "jump", false, 0); entry.End += End; // Event handling for queued animations. state.AddAnimation(0, "run", true, 0); } else if (name == "raptor-pro") { state.SetAnimation(0, "walk", true); state.AddAnimation(1, "gun-grab", false, 2); } else if (name == "coin-pro") { state.SetAnimation(0, "rotate", true); } else if (name == "tank-pro") { state.SetAnimation(0, "drive", true); } else { state.SetAnimation(0, "walk", true); } skeleton.X = 400 + (name == "tank-pro" ? 300 : 0); skeleton.Y = GraphicsDevice.Viewport.Height; skeleton.UpdateWorldTransform(); headSlot = skeleton.FindSlot("head"); }
private void LoadContent(ContentManager contentManager) { skeletonRenderer = new SkeletonMeshRenderer(_graphicsDevice); skeletonRenderer.PremultipliedAlpha = App.GV.Alpha; atlas = new Atlas(App.GV.SelectFile, new XnaTextureLoader(_graphicsDevice)); if (Common.IsBinaryData(App.GV.SelectFile)) { binary = new SkeletonBinary(atlas); binary.Scale = App.GV.Scale; skeletonData = binary.ReadSkeletonData(Common.GetSkelPath(App.GV.SelectFile)); } else { json = new SkeletonJson(atlas); json.Scale = App.GV.Scale; skeletonData = json.ReadSkeletonData(Common.GetJsonPath(App.GV.SelectFile)); } skeleton = new Skeleton(skeletonData); if (isNew) { App.GV.PosX = skeleton.Data.Width; App.GV.PosY = skeleton.Data.Height; } App.GV.FileHash = skeleton.Data.Hash; stateData = new AnimationStateData(skeleton.Data); state = new AnimationState(stateData); if (isRecoding) { state.Start += State_Start; state.Complete += State_Complete; } List <string> AnimationNames = new List <string>(); LA = state.Data.skeletonData.Animations; foreach (Animation An in LA) { AnimationNames.Add(An.name); } App.GV.AnimeList = AnimationNames; List <string> SkinNames = new List <string>(); LS = state.Data.skeletonData.Skins; foreach (Skin Sk in LS) { SkinNames.Add(Sk.name); } App.GV.SkinList = SkinNames; if (App.GV.SelectAnimeName != "") { state.SetAnimation(0, App.GV.SelectAnimeName, App.GV.IsLoop); } else { state.SetAnimation(0, state.Data.skeletonData.animations.Items[0].name, App.GV.IsLoop); } if (isNew) { MainWindow.SetCBAnimeName(); } isNew = false; }
public void Clear() { this.skeletonData = null; this.stateData = null; }
/// <summary> /// Load spine related assets and contents /// </summary> protected override void LoadContent() { // Font spriteBatch = new SpriteBatch(GraphicsDevice); // Spine spineAnimationItem.LoadResources(graphicsDeviceMgr.GraphicsDevice); // load spine resources (this must happen after window is loaded) this.skeleton = new Skeleton(spineAnimationItem.SkeletonData); skeletonRenderer = new SkeletonMeshRenderer(GraphicsDevice); skeletonRenderer.PremultipliedAlpha = spineAnimationItem.PremultipliedAlpha; // Skin foreach (Skin skin in spineAnimationItem.SkeletonData.Skins) { this.skeleton.SetSkin(skin.Name); // just set the first skin break; } // Define mixing between animations. AnimationStateData stateData = new AnimationStateData(skeleton.Data); state = new AnimationState(stateData); int i = 0; foreach (Animation animation in spineAnimationItem.SkeletonData.Animations) { state.SetAnimation(i++, animation.Name, true); } /*if (name == "spineboy") * { * stateData.SetMix("run", "jump", 0.2f); * stateData.SetMix("jump", "run", 0.4f); * * // Event handling for all animations. * state.Start += Start; * state.End += End; * state.Complete += Complete; * state.Event += Event; * * state.SetAnimation(0, "test", false); * TrackEntry entry = state.AddAnimation(0, "jump", false, 0); * entry.End += End; // Event handling for queued animations. * state.AddAnimation(0, "run", true, 0); * } * else if (name == "raptor") * { * state.SetAnimation(0, "walk", true); * state.SetAnimation(1, "empty", false); * state.AddAnimation(1, "gungrab", false, 2); * } * else * { * state.SetAnimation(0, "walk", true); * }*/ skeleton.X = 800; skeleton.Y = 600; skeleton.UpdateWorldTransform(); }
public SkeletonData GetSkeletonData(bool quiet) { if (atlasAssets == null) { atlasAssets = new AtlasAsset[0]; if (!quiet) { Debug.LogError("Atlas not set for SkeletonData asset: " + name, this); } Reset(); return(null); } if (skeletonJSON == null) { if (!quiet) { Debug.LogError("Skeleton JSON file not set for SkeletonData asset: " + name, this); } Reset(); return(null); } #if !SPINE_TK2D if (atlasAssets.Length == 0) { Reset(); return(null); } #else if (atlasAssets.Length == 0 && spriteCollection == null) { Reset(); return(null); } #endif Atlas[] atlasArr = new Atlas[atlasAssets.Length]; for (int i = 0; i < atlasAssets.Length; i++) { if (atlasAssets[i] == null) { Reset(); return(null); } atlasArr[i] = atlasAssets[i].GetAtlas(); if (atlasArr[i] == null) { Reset(); return(null); } } if (skeletonData != null) { return(skeletonData); } #if UNITY_EDITOR || !RELEASE var stopwatch = System.Diagnostics.Stopwatch.StartNew(); bool isBinary = false; #endif AttachmentLoader attachmentLoader; float skeletonDataScale; #if !SPINE_TK2D attachmentLoader = new AtlasAttachmentLoader(atlasArr); skeletonDataScale = scale; #else if (spriteCollection != null) { attachmentLoader = new SpriteCollectionAttachmentLoader(spriteCollection); skeletonDataScale = (1.0f / (spriteCollection.invOrthoSize * spriteCollection.halfTargetHeight) * scale) * 100f; } else { if (atlasArr.Length == 0) { Reset(); if (!quiet) { Debug.LogError("Atlas not set for SkeletonData asset: " + name, this); } return(null); } attachmentLoader = new AtlasAttachmentLoader(atlasArr); skeletonDataScale = scale; } #endif try { if (skeletonJSON.name.ToLower().Contains(".skel")) { #if UNITY_EDITOR || !RELEASE isBinary = true; #endif var input = new MemoryStream(skeletonJSON.bytes); var binary = new SkeletonBinary(attachmentLoader); binary.Scale = skeletonDataScale; skeletonData = binary.ReadSkeletonData(input); } else { // tsteil - added this error Debug.LogError("Spine animation using json text, it should use binary! " + name); var input = new StringReader(skeletonJSON.text); var json = new SkeletonJson(attachmentLoader); json.Scale = skeletonDataScale; skeletonData = json.ReadSkeletonData(input); } } 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); FillStateData(); #if UNITY_EDITOR || !RELEASE // tsteil - added some perf tracking stopwatch.Stop(); if (isBinary == false) { Debug.LogWarning(string.Format("Spine SkeletonDataAsset: {0} ({2}) created in {1:N4} seconds.", name, stopwatch.Elapsed.TotalSeconds, isBinary ? "binary" : "text")); } #endif return(skeletonData); }
public SkeletonData GetSkeletonData(bool quiet) { if (atlasAssets == null) { atlasAssets = new AtlasAsset[0]; if (!quiet) { Debug.LogError("Atlas not set for SkeletonData asset: " + name, this); } Reset(); return(null); } if (skeletonJSON == null) { if (!quiet) { Debug.LogError("Skeleton JSON file not set for SkeletonData asset: " + name, this); } Reset(); return(null); } if (atlasAssets.Length == 0) { Reset(); return(null); } Atlas[] atlasArr = new Atlas[atlasAssets.Length]; for (int i = 0; i < atlasAssets.Length; i++) { if (atlasAssets[i] == null) { Reset(); return(null); } atlasArr[i] = atlasAssets[i].GetAtlas(); if (atlasArr[i] == null) { Reset(); return(null); } } if (skeletonData != null) { return(skeletonData); } SkeletonJson json = new SkeletonJson(atlasArr); json.Scale = scale; try { skeletonData = json.ReadSkeletonData(new StringReader(skeletonJSON.text)); } 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); }