protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);

            String name = "spineboy";             // "goblins";

            Atlas        atlas = new Atlas("data/" + name + ".atlas", new XnaTextureLoader(GraphicsDevice));
            SkeletonJson json  = new SkeletonJson(atlas);

            skeleton = new Skeleton(json.ReadSkeletonData("data/" + name + ".json"));
            if (name == "goblins")
            {
                skeleton.SetSkin("goblingirl");
            }
            skeleton.SetSlotsToBindPose();             // 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);
            state.SetAnimation("walk", false);
            state.AddAnimation("jump", false);
            state.AddAnimation("walk", true);

            skeleton.RootBone.X = 320;
            skeleton.RootBone.Y = 440;
            skeleton.UpdateWorldTransform();
        }
Ejemplo n.º 2
0
 public RawSpineData(string pSkeletonDataPath, string pSkeletonName)
 {
     skeletonRenderer = new SkeletonRenderer(EngineSettings.Graphics.GraphicsDevice);
       skeletonRenderer.PremultipliedAlpha = SpineSettings.PremultipliedAlphaRendering;
       atlas = new Atlas(pSkeletonDataPath + pSkeletonName + ".atlas", new XnaTextureLoader(EngineSettings.Graphics.GraphicsDevice));
       json = new SkeletonJson(atlas);
 }
Ejemplo n.º 3
0
    void OnCurLoadFinish()
    {//先临时验证一下代码构造spine动画,两个atlas的设计问题较多,必须要休整一下播放组件
        GameObject curObj = new GameObject();

        curObj.name = "spine-cur";
        SkeletonAnimationCL ani = curObj.AddComponent <SkeletonAnimationCL>();
        //AtlasAsset assAtlas = new AtlasAsset();
        //assAtlas.materials = new Material[1];
        //assAtlas.materials[0] = new Material(Shader.Find("Spine/Skeleton"));
        //assAtlas.materials[0].mainTexture = curAtlasTex;
        Dictionary <string, Texture2D> texs = new Dictionary <string, Texture2D>();

        texs["cur.png"] = curAtlasTex;
        var atlas = new Spine.Atlas(new System.IO.StringReader(curAtlas), "", new TextureLoad(texs));

        atlas.FlipV();
        //assAtlas.SetAtlas(atlas);

        Spine.SkeletonJson sjson = new Spine.SkeletonJson(atlas);
        sjson.Scale = 1.0f / 64.0f;
        var data = sjson.ReadSkeletonData(new System.IO.StringReader(curSK));

        ani.skeleton = new Spine.Skeleton(data);
        ani.Reset();
        ani.state.SetAnimation(0, "idle", true);
    }
    /*
     */
    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]);
        }
    }
Ejemplo n.º 5
0
        public Animation(string AnimationFile)
        {
            skeletonRenderer = new SkeletonRenderer();

            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);
            //state.SetAnimation("idle", true);

            skeleton.X = 0;
            skeleton.Y = 0.1f;
            skeleton.UpdateWorldTransform();

            drawtime = new Stopwatch();
            drawtime.Start();

            Program.MiddleDrawQueue += Draw;
        }
Ejemplo n.º 6
0
        public SpineData(string pSkeletonName, SpineDataSettings pSettings)
        {
			Initialize();
			settings = pSettings;
			atlas = new Atlas(EngineSettings.DefaultPathSpine + "\\" + pSkeletonName + ".atlas", new XnaTextureLoader(EngineSettings.Graphics.GraphicsDevice));
            json = new SkeletonJson(atlas);
        }
Ejemplo n.º 7
0
        public TankScreen(Example game) : base(game)
        {
            // Instantiate and configure the two color tinting effect and
            // assign it to the skeleton renderer
            var twoColorTintEffect = game.Content.Load <Effect>("Content\\SpineEffect");

            twoColorTintEffect.Parameters["World"].SetValue(Matrix.Identity);
            twoColorTintEffect.Parameters["View"].SetValue(Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 1.0f), Vector3.Zero, Vector3.Up));
            skeletonRenderer.Effect = twoColorTintEffect;

            // The remaining code loads the atlas and skeleton data as in the raptor screen
            atlas = new Atlas("data/tank.atlas", new XnaTextureLoader(game.GraphicsDevice));
            SkeletonJson json = new SkeletonJson(atlas);

            json.Scale = 0.25f;
            SkeletonData skeletonData = json.ReadSkeletonData("data/tank-pro.json");

            skeleton = new Skeleton(skeletonData);
            AnimationStateData stateData = new AnimationStateData(skeleton.Data);

            state = new AnimationState(stateData);

            skeleton.X = game.GraphicsDevice.Viewport.Width / 2 + 200;
            skeleton.Y = game.GraphicsDevice.Viewport.Height;

            state.SetAnimation(0, "shoot", true);
        }
Ejemplo n.º 8
0
		private Skeleton CreateSkeleton(string atlasName, string skeletonName)
		{
			var atlasData = ContentLoader.Load<AtlasData>(atlasName);
			atlas = new Atlas(atlasData.TextReader, "Content", MaterialLoader);
			var skeletonJson = new SkeletonJson(atlas);
			var spineSkeletonData = ContentLoader.Load<SpineSkeletonData>(skeletonName);
			SkeletonData = skeletonJson.ReadSkeletonData(spineSkeletonData.TextReader);
			return new Skeleton(SkeletonData);
		}
Ejemplo n.º 9
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonMeshRenderer(GraphicsDevice);
            skeletonRenderer.PremultipliedAlpha = true;

            // String name = "spineboy";
            String name = "goblins-ffd";

            Atlas        atlas = new Atlas(assetsFolder + name + ".atlas", new XnaTextureLoader(GraphicsDevice));
            SkeletonJson json  = new SkeletonJson(atlas);

            if (name == "spineboy")
            {
                json.Scale = 0.6f;
            }
            skeleton = new Skeleton(json.ReadSkeletonData(assetsFolder + name + ".json"));
            if (name == "goblins-ffd")
            {
                skeleton.SetSkin("goblin");
            }

            // Define mixing between animations.
            AnimationStateData stateData = new AnimationStateData(skeleton.Data);

            state = new AnimationState(stateData);

            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
            {
                state.SetAnimation(0, "walk", true);
            }

            skeleton.X = 400;
            skeleton.Y = 590;
            skeleton.UpdateWorldTransform();

            headSlot = skeleton.FindSlot("head");
        }
Ejemplo n.º 10
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);
            skeletonRenderer.PremultipliedAlpha = true;

            String name = "spineboy";             // "goblins";

            Atlas        atlas = new Atlas("data/" + name + ".atlas", new XnaTextureLoader(GraphicsDevice));
            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 (true)
            {
                // 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 += End;                 // Event handling for queued animations.
                state.AddAnimation(0, "walk", true, 0);
            }

            skeleton.X = 320;
            skeleton.Y = 440;
            skeleton.UpdateWorldTransform();

            headSlot = skeleton.FindSlot("head");
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            this.skeletonRenderer = new SkeletonRegionRenderer(GraphicsDevice);

            var atlas = new Atlas(@"Assets\crab.atlas", new XnaTextureLoader(GraphicsDevice));
            var json = new SkeletonJson(atlas);

            this.skeleton = new Skeleton(json.ReadSkeletonData(@"Assets\skeleton.json"));
            this.animation = this.skeleton.Data.FindAnimation("Walk");

            this.skeleton.X = 750;
            this.skeleton.Y = 700;
        }
Ejemplo n.º 12
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);

            Atlas        atlas = new Atlas("data/goblins.atlas", new XnaTextureLoader(GraphicsDevice));
            SkeletonJson json  = new SkeletonJson(atlas);

            skeleton = new Skeleton(json.ReadSkeletonData("data/goblins.json"));
            skeleton.SetSkin("goblingirl");
            skeleton.SetSlotsToBindPose();             // Without this the skin attachments won't be attached. See SetSkin.
            animation = skeleton.Data.FindAnimation("walk");

            skeleton.RootBone.X = 320;
            skeleton.RootBone.Y = 440;
            skeleton.UpdateWorldTransform();
        }
Ejemplo n.º 13
0
        public SpinePlayer(string atlasPath, string jsonPath)
        {
            Name = jsonPath;

            _skeletonRenderer = new SkeletonRenderer(Render.Device);

            var atlas = new Atlas(atlasPath, new XnaTextureLoader(Render.Device));
            var json = new SkeletonJson(atlas);

            Skeleton = new Skeleton(json.ReadSkeletonData(jsonPath));
            Skeleton.SetSlotsToSetupPose(); // Without this the skin attachments won't be attached. See SetSkin.

            var stateData = new AnimationStateData(Skeleton.Data);
            State = new AnimationState(stateData);
            IsVisible = true;
        }
Ejemplo n.º 14
0
	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;
	}
Ejemplo n.º 15
0
		protected override void LoadContent () {
			skeletonRenderer = new SkeletonMeshRenderer(GraphicsDevice);
			skeletonRenderer.PremultipliedAlpha = true;

			// String name = "spineboy";
			// String name = "goblins-ffd";
			String name = "raptor";

			Atlas atlas = new Atlas(assetsFolder + name + ".atlas", new XnaTextureLoader(GraphicsDevice));
			SkeletonJson json = new SkeletonJson(atlas);
			if (name == "spineboy") json.Scale = 0.6f;
			if (name == "raptor") json.Scale = 0.5f;
			skeleton = new Skeleton(json.ReadSkeletonData(assetsFolder + name + ".json"));
			if (name == "goblins-ffd") skeleton.SetSkin("goblin");

			// Define mixing between animations.
			AnimationStateData stateData = new AnimationStateData(skeleton.Data);
			state = new AnimationState(stateData);

			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 = 400;
			skeleton.Y = 590;
			skeleton.UpdateWorldTransform();

			headSlot = skeleton.FindSlot("head");
		}
Ejemplo n.º 16
0
        protected override SkeletonData Read(ContentReader input, SkeletonData existingInstance)
        {
            string atlasAssetName   = input.ReadString();
            string skeletonDataName = input.ReadString();
            string skeletonJsonText = input.ReadString();

            Atlas        atlas        = input.ContentManager.Load <Atlas>(atlasAssetName);
            SkeletonJson skeletonJson = new SkeletonJson(atlas);

            SkeletonData skeletonData;

            using (TextReader textReader = new StringReader(skeletonJsonText))
            {
                skeletonData = skeletonJson.ReadSkeletonData(textReader);
            }

            skeletonData.Name = skeletonDataName;
            return(skeletonData);
        }
Ejemplo n.º 17
0
        public Avatar(string AnimationFile)
        {
            SkeletonRenderer = new SkeletonRenderer(Vector3.UnitY, Vector3.UnitZ);

            String name = AnimationFile;

            Atlas atlas = new Atlas(name + ".atlas", new OpenTKTextureLoader());
            SkeletonJson json = new SkeletonJson(atlas);
            Skeleton = new Skeleton(json.ReadSkeletonData(name + ".json"));
            Skeleton.SetSlotsToSetupPose();

            // Define mixing between animations.
            StateData = new AnimationStateData(Skeleton.Data);
            State = new AnimationState(StateData);

            Skeleton.X = 0;
            Skeleton.Y = 0;
            Skeleton.UpdateWorldTransform();
        }
Ejemplo n.º 18
0
    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;
    }
Ejemplo n.º 19
0
	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;
	}
Ejemplo n.º 20
0
    // this actually loads the spine json file into a skeletondata object, then adds it to the dictionary
    public static void LoadSpine(string name, string jsonPath)
    {
        if(!DoesContainSkeleton(name)){

            TextAsset dataAsset = Resources.Load(jsonPath + Futile.resourceSuffix, typeof(TextAsset)) as TextAsset;
            if(dataAsset == null){
                Debug.Log("Could not load Skeleton, file " + jsonPath + Futile.resourceSuffix + " not found.");
                return;
            }

            SkeletonJson json = new SkeletonJson(_attachmentLoader);
            TextReader reader = new StringReader(dataAsset.text);
            SkeletonData skeletonData = json.ReadSkeletonData(reader);

            if(skeletonData != null){
                _skeletons.Add(name, skeletonData);
            }else{
                Debug.Log("Could not load Skeleton Data");
            }
        }else{
            Debug.Log("Skeleton already exists for name [" + name + "]");
        }
    }
Ejemplo n.º 21
0
        public RaptorScreen(Example game) : base(game)
        {
            // Load the texture atlas
            atlas = new Atlas("data/raptor.atlas", new XnaTextureLoader(game.GraphicsDevice));

            // Load the .json file using a scale of 0.5
            SkeletonJson json = new SkeletonJson(atlas);

            json.Scale = 0.5f;
            SkeletonData skeletonData = json.ReadSkeletonData("data/raptor-pro.json");

            // Create the skeleton and animation state
            skeleton = new Skeleton(skeletonData);
            AnimationStateData stateData = new AnimationStateData(skeleton.Data);

            state = new AnimationState(stateData);

            // Center within the viewport
            skeleton.X = game.GraphicsDevice.Viewport.Width / 2;
            skeleton.Y = game.GraphicsDevice.Viewport.Height;

            // Set the "walk" animation on track one and let it loop forever
            state.SetAnimation(0, "walk", true);
        }
Ejemplo n.º 22
0
        public MixAndMatchScreen(Example game) : base(game)
        {
            atlas = new Atlas("data/mix-and-match.atlas", new XnaTextureLoader(game.GraphicsDevice));

            SkeletonJson json = new SkeletonJson(atlas);

            json.Scale = 0.5f;
            SkeletonData skeletonData = json.ReadSkeletonData("data/mix-and-match-pro.json");

            skeleton = new Skeleton(skeletonData);
            AnimationStateData stateData = new AnimationStateData(skeleton.Data);

            state = new AnimationState(stateData);

            skeleton.X = game.GraphicsDevice.Viewport.Width / 2;
            skeleton.Y = game.GraphicsDevice.Viewport.Height;

            state.SetAnimation(0, "dance", true);

            // 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 mixAndMatchSkin = new Spine.Skin("custom-girl");

            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("skin-base"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("nose/short"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("eyelids/girly"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("eyes/violet"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("hair/brown"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("clothes/hoodie-orange"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("legs/pants-jeans"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("accessories/bag"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("accessories/hat-red-yellow"));
            skeleton.SetSkin(mixAndMatchSkin);
        }
Ejemplo n.º 23
0
        private SpatialTypeRecord Load(GraphicsDevice device, string contentPath)
        {
            SpatialTypeRecord record = new SpatialTypeRecord();

            using (Stream contentStream = TitleContainer.OpenStream(contentPath)) {
                using (XmlReader reader = XmlReader.Create(contentStream)) {
                    XmlSkeletonDefElement xmldef = new XmlSkeletonDefElement();
                    xmldef.ReadXml(reader);

                    Atlas atlas = new Atlas(xmldef.Atlas.Source, new XnaTextureLoader(device));
                    SkeletonJson json = new SkeletonJson(atlas);

                    record.Data = json.ReadSkeletonData(xmldef.Skeleton.Source);
                    record.DefaultAnimationMap = xmldef.BuildDefaultAnimationMap();
                    record.DirectedAnimationMap = xmldef.BuildDirectedAnimationMap();
                    record.ActivityMap = xmldef.BuildActivityMap();
                    record.DefaultAnimation = xmldef.ActivityMap.DefaultAnimation;
                }
            }

            _registered[contentPath] = record;
            return record;
        }
Ejemplo n.º 24
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);

            Texture2D texture = Util.LoadTexture(GraphicsDevice, "data/goblins.png");
            Atlas atlas = new Atlas("data/goblins.atlas", texture, texture.Width, texture.Height);
            SkeletonJson json = new SkeletonJson(atlas);
            skeleton = new Skeleton(json.ReadSkeletonData("data/goblins.json"));
            skeleton.SetSkin("goblingirl");
            skeleton.SetSlotsToBindPose(); // Without this the skin attachments won't be attached. See SetSkin.
            animation = skeleton.Data.FindAnimation("walk");

            skeleton.RootBone.X = 320;
            skeleton.RootBone.Y = 440;
            skeleton.UpdateWorldTransform();
        }
Ejemplo n.º 25
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);
            Atlas atlas = new Atlas(GraphicsDevice, "data/spineboy.atlas");
            SkeletonJson json = new SkeletonJson(atlas);
            skeleton = new Skeleton(json.readSkeletonData("spineboy", File.ReadAllText("data/spineboy.json")));
            animation = skeleton.Data.FindAnimation("walk");

            skeleton.RootBone.X = 320;
            skeleton.RootBone.Y = 440;
            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 (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);
        FillStateData();

        return skeletonData;
    }
Ejemplo n.º 27
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonMeshRenderer(GraphicsDevice);
            skeletonRenderer.PremultipliedAlpha = true;

            // String name = "spineboy";
            // String name = "goblins-mesh";
            // String name = "raptor";
            String name = "tank";
            // String name = "star";
            bool binaryData = true;

            Atlas atlas = new Atlas(assetsFolder + name + ".atlas", new XnaTextureLoader(GraphicsDevice));

            float scale = 1;

            if (name == "spineboy")
            {
                scale = 0.6f;
            }
            if (name == "raptor")
            {
                scale = 0.5f;
            }
            if (name == "tank")
            {
                scale = 0.3f;
            }

            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-mesh")
            {
                skeleton.SetSkin("goblin");
            }

            // Define mixing between animations.
            AnimationStateData stateData = new AnimationStateData(skeleton.Data);

            state = new AnimationState(stateData);

            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.AddAnimation(1, "gungrab", false, 2);
            }
            else if (name == "star")
            {
                // no animation in star
            }
            else if (name == "tank")
            {
                state.SetAnimation(0, "drive", true);
            }
            else
            {
                state.SetAnimation(0, "walk", true);
            }

            skeleton.X = 400 + (name == "tank" ? 300: 0);
            skeleton.Y = 580;
            skeleton.UpdateWorldTransform();

            headSlot = skeleton.FindSlot("head");
        }
Ejemplo n.º 28
0
        public void LoadContent(ContentManager content, GraphicsDevice graphicsDevice)
        {
            blankTex = content.Load<Texture2D>("Textures/Blank");

            skeletonRenderer = new SkeletonRenderer(graphicsDevice);

            Atlas atlas = new Atlas(graphicsDevice, System.IO.Path.Combine(content.RootDirectory, "spineboy.atlas"));
            SkeletonJson json = new SkeletonJson(atlas);
            json.Scale = 0.5f;
            skeleton = new Skeleton(json.readSkeletonData("spineboy", File.ReadAllText(System.IO.Path.Combine(content.RootDirectory, "spineboy.json"))));
            skeleton.SetSkin("default");
            skeleton.SetSlotsToBindPose();
            walkAnimation = skeleton.Data.FindAnimation("walk");
            jumpAnimation = skeleton.Data.FindAnimation("jump");
            crawlAnimation = skeleton.Data.FindAnimation("crawl");
            fallAnimation = skeleton.Data.FindAnimation("fall");
            grabAnimation = skeleton.Data.FindAnimation("grab");
            climbAnimation = skeleton.Data.FindAnimation("climb");

            skeleton.RootBone.X = Position.X;
            skeleton.RootBone.Y = Position.Y;
            skeleton.UpdateWorldTransform();
        }
Ejemplo n.º 29
0
 /// <summary>
 /// List aus Skeleton Files mit möglichen FadingSettings.
 /// </summary>
 /// <param name="pDefaultFading">Fading mit dem die Settings am Anfang gefüllt werden.</param>
 public List<SpineData.AnimationMix> GetAnimationMixes(string pSkeletonName, float pDefaultFading)
 {
     List<SpineData.AnimationMix> TmpAnimationMixes = new List<SpineData.AnimationMix>();
     List<Animation> TmpAnimationList = new SkeletonJson(new Atlas(EngineSettings.DefaultPathSpine + "\\" + pSkeletonName + ".atlas", new XnaTextureLoader(EngineSettings.Graphics.GraphicsDevice))).ReadSkeletonData(EngineSettings.DefaultPathSpine + "\\" + pSkeletonName + ".json").Animations;
     foreach (Animation a in TmpAnimationList)
     {
         foreach (Animation b in TmpAnimationList)
         {
             if (b.Name != a.Name)
                 TmpAnimationMixes.Add(new SpineData.AnimationMix(a.Name, b.Name, pDefaultFading));
         }
     }
     return TmpAnimationMixes;
 }
Ejemplo n.º 30
0
        protected override void LoadContent()
        {
            // Two color tint effect, comment line 80 to disable
            var spineEffect = Content.Load <Effect>("spine-xna-example-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;

            skeletonDebugRenderer = new SkeletonDebugRenderer(GraphicsDevice);
            skeletonDebugRenderer.DisableAll();
            skeletonDebugRenderer.DrawClipping = true;

            // String name = "spineboy-ess";
            // String name = "goblins-pro";
            // String name = "raptor-pro";
            // String name = "tank-pro";
            String name      = "coin-pro";
            String atlasName = name.Replace("-pro", "").Replace("-ess", "");

            if (name == "goblins-pro")
            {
                atlasName = "goblins-mesh";
            }
            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")
            {
                skeleton.SetAttachment("head-bb", "head");

                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, "run", true);
                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, "animation", true);
            }
            else if (name == "tank-pro")
            {
                skeleton.X += 300;
                state.SetAnimation(0, "drive", true);
            }
            else
            {
                state.SetAnimation(0, "walk", true);
            }

            skeleton.X += 400;
            skeleton.Y += GraphicsDevice.Viewport.Height;
            skeleton.UpdateWorldTransform();

            headSlot = skeleton.FindSlot("head");
        }
Ejemplo n.º 31
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);

            String name = "spineboy"; // "goblins";

            Atlas atlas = new Atlas("data/" + name + ".atlas", new XnaTextureLoader(GraphicsDevice));
            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 (true) {
                // Event handling for all animations.
                state.Start += new EventHandler(Start);
                state.End += new EventHandler(End);
                state.Complete += new EventHandler<CompleteArgs>(Complete);
                state.Event += new EventHandler<EventTriggeredArgs>(Event);

                state.SetAnimation("drawOrder", true);
            } else {
                state.SetAnimation("walk", false);
                QueueEntry entry = state.AddAnimation("jump", false);
                entry.End += new EventHandler(End); // Event handling for queued animations.
                state.AddAnimation("walk", true);
            }

            skeleton.X = 320;
            skeleton.Y = 440;
            skeleton.UpdateWorldTransform();

            headSlot = skeleton.FindSlot("head");
        }
		internal static SkeletonData ReadSkeletonData (string text, AttachmentLoader attachmentLoader, float scale) {
			var input = new StringReader(text);
			var json = new SkeletonJson(attachmentLoader) {
				Scale = scale
			};
			return json.ReadSkeletonData(input);
		}
Ejemplo n.º 33
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);

            String name = "spineboy"; // "goblins";

            Atlas atlas = new Atlas("data/" + name + ".atlas", new XnaTextureLoader(GraphicsDevice));
            SkeletonJson json = new SkeletonJson(atlas);
            skeleton = new Skeleton(json.ReadSkeletonData("data/" + name + ".json"));
            if (name == "goblins") skeleton.SetSkin("goblingirl");
            skeleton.SetSlotsToBindPose(); // 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);
            state.SetAnimation("walk", false);
            state.AddAnimation("jump", false);
            state.AddAnimation("walk", true);

            skeleton.RootBone.X = 320;
            skeleton.RootBone.Y = 440;
            skeleton.UpdateWorldTransform();
        }
Ejemplo n.º 34
0
        public CCSkeleton(string skeletonDataFile, string atlasFile, float scale = 0)
        {

            Initialize();

            using (StreamReader atlasStream = new StreamReader(CCFileUtils.GetFileStream(atlasFile)))
            {
                atlas = new Atlas(atlasStream, "", new CocosSharpTextureLoader());
            }

            SkeletonJson json = new SkeletonJson(atlas);

            json.Scale = scale == 0 ? (1 / Director.ContentScaleFactor) : scale;

            using (StreamReader skeletonDataStream = new StreamReader(CCFileUtils.GetFileStream(skeletonDataFile)))
            {
                SkeletonData skeletonData = json.ReadSkeletonData(skeletonDataStream);
                skeletonData.Name = skeletonDataFile;
                SetSkeletonData(skeletonData, true);
            }
        }
Ejemplo n.º 35
0
        public CCSkeleton(string skeletonDataFile, Atlas atlas, float scale = 0)
        {
            var json = new SkeletonJson(atlas);
			json.Scale = scale == 0 ? (1 / Director.ContentScaleFactor) : scale;
            SkeletonData skeletonData = json.ReadSkeletonData(skeletonDataFile);
            SetSkeletonData(skeletonData, true);
        }
Ejemplo n.º 36
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);

            Atlas atlas = new Atlas("data/goblins.atlas", new XnaTextureLoader(GraphicsDevice));
            SkeletonJson json = new SkeletonJson(atlas);
            skeleton = new Skeleton(json.ReadSkeletonData("data/goblins.json"));
            skeleton.SetSkin("goblingirl");
            skeleton.SetSlotsToBindPose(); // Without this the skin attachments won't be attached. See SetSkin.
            skeleton.SetAttachment("left hand item", "spear");
            animation = skeleton.Data.FindAnimation("walk");

            skeleton.RootBone.X = 320;
            skeleton.RootBone.Y = 440;
            skeleton.UpdateWorldTransform();
        }
Ejemplo n.º 37
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);
            Atlas atlas = new Atlas(GraphicsDevice, "data/goblins.atlas");
            SkeletonJson json = new SkeletonJson(atlas);
            skeleton = new Skeleton(json.readSkeletonData("goblins", File.ReadAllText("data/goblins.json")));
            skeleton.SetSkin("goblingirl");
            skeleton.SetSlotsToBindPose();
            animation = skeleton.Data.FindAnimation("walk");

            skeleton.RootBone.X = 320;
            skeleton.RootBone.Y = 440;
            skeleton.UpdateWorldTransform();
        }
Ejemplo n.º 38
0
        protected override void LoadContent()
        {
            skeletonRenderer = new SkeletonRenderer(GraphicsDevice);

            this.atlas = new Atlas("Content/crab.atlas", new XnaTextureLoader(GraphicsDevice));

            SkeletonJson json = new SkeletonJson(atlas);
            this.skeleton = new Skeleton(json.ReadSkeletonData("Content/crab-skeleton.json"));
            this.animationWalk = skeleton.Data.FindAnimation ("WalkLeft");
            this.animationJump = skeleton.Data.FindAnimation ("Jump");

            this.skeleton.SetSlotsToSetupPose(); // Without this the skin attachments won't be attached. See SetSkin.

            this.animation = 0;
            this.SetSkeletonStartPosition ();

            // used for debugging - draw the bones
            this.lineTexture = new Texture2D(GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            this.lineTexture.SetData(new[]{Color.White});
            this.textureMaps.Add(lineTexture);

            base.LoadContent ();
        }
Ejemplo n.º 39
0
        public void LoadContent(ContentManager content, GraphicsDevice graphicsDevice)
        {
            blankTex = content.Load<Texture2D>("blank");

            skeletonRenderer = new SkeletonRenderer(graphicsDevice);
            Atlas atlas = new Atlas(graphicsDevice, Path.Combine(content.RootDirectory, "spinegirl.atlas"));
            SkeletonJson json = new SkeletonJson(atlas);
            skeleton = new Skeleton(json.readSkeletonData("spinegirl", File.ReadAllText(Path.Combine(content.RootDirectory, "spinegirl.json"))));
            skeleton.SetSkin("default");
            skeleton.SetSlotsToBindPose();
            Animations.Add("walk", skeleton.Data.FindAnimation("walk"));
            Animations.Add("jump", skeleton.Data.FindAnimation("jump"));
            Animations.Add("crawl", skeleton.Data.FindAnimation("crawl"));
            Animations.Add("fall", skeleton.Data.FindAnimation("fall"));
            Animations.Add("grab", skeleton.Data.FindAnimation("grab"));
            Animations.Add("climb", skeleton.Data.FindAnimation("climb"));
            Animations.Add("turnvalve", skeleton.Data.FindAnimation("turnvalve"));

            skeleton.RootBone.X = Position.X;
            skeleton.RootBone.Y = Position.Y;
            skeleton.RootBone.ScaleX = Scale;
            skeleton.RootBone.ScaleY = Scale;

            skeleton.UpdateWorldTransform();
        }
Ejemplo n.º 40
0
        protected override void LoadContent()
        {
            // Two color tint effect, comment line 76 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 = true;
            skeletonRenderer.Effect             = spineEffect;

            // String name = "spineboy";
            // String name = "goblins-mesh";
            // String name = "raptor";
            // String name = "tank";
            // String name = "coin";
            String name       = "TwoColorTest";
            bool   binaryData = true;

            Atlas atlas = new Atlas(assetsFolder + name + ".atlas", new XnaTextureLoader(GraphicsDevice));

            float scale = 1;

            if (name == "spineboy")
            {
                scale = 0.6f;
            }
            if (name == "raptor")
            {
                scale = 0.5f;
            }
            if (name == "tank")
            {
                scale = 0.3f;
            }
            if (name == "TwoColorTest")
            {
                scale = 0.5f;
            }

            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-mesh")
            {
                skeleton.SetSkin("goblin");
            }

            // Define mixing between animations.
            AnimationStateData stateData = new AnimationStateData(skeleton.Data);

            state = new AnimationState(stateData);

            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.AddAnimation(1, "gungrab", false, 2);
            }
            else if (name == "coin")
            {
                state.SetAnimation(0, "rotate", true);
            }
            else if (name == "tank")
            {
                state.SetAnimation(0, "drive", true);
            }
            else if (name == "TwoColorTest")
            {
                state.SetAnimation(0, "animation", true);
            }
            else
            {
                state.SetAnimation(0, "walk", true);
            }

            skeleton.X = 400 + (name == "tank" ? 300: 0);
            skeleton.Y = 580 + (name == "TwoColorTest" ? -300 : 0);
            skeleton.UpdateWorldTransform();

            headSlot = skeleton.FindSlot("head");
        }
Ejemplo n.º 41
0
        protected override void LoadContent()
        {
            bool   useNormalmapShader = false;
            Effect spineEffect;

            if (!useNormalmapShader)
            {
                // Two color tint effect. Note that you can also use the default BasicEffect instead.
                spineEffect = Content.Load <Effect>("spine-xna-example-content\\SpineEffect");
            }
            else
            {
                spineEffect = Content.Load <Effect>("spine-xna-example-content\\SpineEffectNormalmap");
                spineEffect.Parameters["Light0_Direction"].SetValue(new Vector3(-0.5265408f, 0.5735765f, -0.6275069f));
                spineEffect.Parameters["Light0_Diffuse"].SetValue(new Vector3(1, 0.9607844f, 0.8078432f));
                spineEffect.Parameters["Light0_Specular"].SetValue(new Vector3(1, 0.9607844f, 0.8078432f));
                spineEffect.Parameters["Light0_SpecularExponent"].SetValue(2.0f);
            }
            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;

            skeletonDebugRenderer = new SkeletonDebugRenderer(GraphicsDevice);
            skeletonDebugRenderer.DisableAll();
            skeletonDebugRenderer.DrawClipping = true;

            // String name = "spineboy-pro";
            String name = "raptor-pro";

            // String name = "tank-pro";
            //String name = "coin-pro";
            if (useNormalmapShader)
            {
                name = "raptor-pro";                 // we only have normalmaps for raptor
            }
            String atlasName = name.Replace("-pro", "").Replace("-ess", "");

            bool binaryData = false;

            Atlas atlas;

            if (!useNormalmapShader)
            {
                atlas = new Atlas(assetsFolder + atlasName + ".atlas", new XnaTextureLoader(GraphicsDevice));
            }
            else
            {
                atlas = new Atlas(assetsFolder + atlasName + ".atlas", new XnaTextureLoader(GraphicsDevice,
                                                                                            loadMultipleTextureLayers: true, textureSuffixes: new string[] { "", "_normals" }));
            }
            float scale = 1;

            if (name == "spineboy-pro")
            {
                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-pro")
            {
                skeleton.SetAttachment("head-bb", "head");

                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, "run", true);
                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, "animation", true);
            }
            else if (name == "tank-pro")
            {
                skeleton.X += 300;
                state.SetAnimation(0, "drive", true);
            }
            else
            {
                state.SetAnimation(0, "walk", true);
            }

            skeleton.X += 400;
            skeleton.Y += GraphicsDevice.Viewport.Height;
            skeleton.UpdateWorldTransform();

            headSlot = skeleton.FindSlot("head");
        }
Ejemplo n.º 42
0
    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 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;
    }
Ejemplo n.º 43
0
    void OnCurLoadFinish()
    {
        //先临时验证一下代码构造spine动画,两个atlas的设计问题较多,必须要休整一下播放组件
        GameObject curObj=new GameObject();
        curObj.name="spine-cur";
        SkeletonAnimationCL ani = curObj.AddComponent<SkeletonAnimationCL>();
        //AtlasAsset assAtlas = new AtlasAsset();
        //assAtlas.materials = new Material[1];
        //assAtlas.materials[0] = new Material(Shader.Find("Spine/Skeleton"));
        //assAtlas.materials[0].mainTexture = curAtlasTex;
        Dictionary<string, Texture2D> texs = new Dictionary<string, Texture2D>();
        texs["cur.png"] = curAtlasTex;
        var atlas = new Spine.Atlas(new System.IO.StringReader(curAtlas), "", new TextureLoad(texs));
        atlas.FlipV();
        //assAtlas.SetAtlas(atlas);

        Spine.SkeletonJson sjson = new Spine.SkeletonJson(atlas);
        sjson.Scale = 1.0f/64.0f;
        var data=sjson.ReadSkeletonData(new System.IO.StringReader(curSK));

        ani.skeleton = new Spine.Skeleton(data);
        ani.Reset();
        ani.state.SetAnimation(0, "idle", true);
    }