Esempio n. 1
0
    static int SetSkin(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2 && TypeChecker.CheckTypes <Spine.Skin>(L, 2))
            {
                Spine.Skeleton obj  = (Spine.Skeleton)ToLua.CheckObject <Spine.Skeleton>(L, 1);
                Spine.Skin     arg0 = (Spine.Skin)ToLua.ToObject(L, 2);
                obj.SetSkin(arg0);
                return(0);
            }
            else if (count == 2 && TypeChecker.CheckTypes <string>(L, 2))
            {
                Spine.Skeleton obj  = (Spine.Skeleton)ToLua.CheckObject <Spine.Skeleton>(L, 1);
                string         arg0 = ToLua.ToString(L, 2);
                obj.SetSkin(arg0);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: Spine.Skeleton.SetSkin"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Esempio n. 2
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;
        }
Esempio n. 3
0
		public void Update (Skeleton skeleton, bool updateAabb) {
			ExposedList<BoundingBoxAttachment> boundingBoxes = BoundingBoxes;
			ExposedList<Polygon> polygons = Polygons;
			ExposedList<Slot> slots = skeleton.slots;
			int slotCount = slots.Count;

			boundingBoxes.Clear();
			for (int i = 0, n = polygons.Count; i < n; i++)
				polygonPool.Add(polygons.Items[i]);
			polygons.Clear();

			for (int i = 0; i < slotCount; i++) {
				Slot slot = slots.Items[i];
				BoundingBoxAttachment boundingBox = slot.attachment as BoundingBoxAttachment;
				if (boundingBox == null) continue;
				boundingBoxes.Add(boundingBox);

				Polygon polygon = null;
				int poolCount = polygonPool.Count;
				if (poolCount > 0) {
					polygon = polygonPool.Items[poolCount - 1];
					polygonPool.RemoveAt(poolCount - 1);
				} else
					polygon = new Polygon();
				polygons.Add(polygon);

				int count = boundingBox.Vertices.Length;
				polygon.Count = count;
				if (polygon.Vertices.Length < count) polygon.Vertices = new float[count];
				boundingBox.ComputeWorldVertices(slot, polygon.Vertices);
			}

			if (updateAabb) aabbCompute();
		}
Esempio n. 4
0
    static int GetAttachment(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes <int, string>(L, 2))
            {
                Spine.Skeleton   obj  = (Spine.Skeleton)ToLua.CheckObject <Spine.Skeleton>(L, 1);
                int              arg0 = (int)LuaDLL.lua_tonumber(L, 2);
                string           arg1 = ToLua.ToString(L, 3);
                Spine.Attachment o    = obj.GetAttachment(arg0, arg1);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes <string, string>(L, 2))
            {
                Spine.Skeleton   obj  = (Spine.Skeleton)ToLua.CheckObject <Spine.Skeleton>(L, 1);
                string           arg0 = ToLua.ToString(L, 2);
                string           arg1 = ToLua.ToString(L, 3);
                Spine.Attachment o    = obj.GetAttachment(arg0, arg1);
                ToLua.PushObject(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: Spine.Skeleton.GetAttachment"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Esempio n. 5
0
 public void Initialize(bool overwrite)
 {
     if ((!this.IsValid || overwrite) && (this.skeletonDataAsset != null))
     {
         Spine.SkeletonData skeletonData = this.skeletonDataAsset.GetSkeletonData(false);
         if ((skeletonData != null) && ((this.skeletonDataAsset.atlasAssets.Length > 0) && (this.skeletonDataAsset.atlasAssets[0].materials.Length > 0)))
         {
             this.state = new Spine.AnimationState(this.skeletonDataAsset.GetAnimationStateData());
             if (this.state == null)
             {
                 this.Clear();
             }
             else
             {
                 Spine.Skeleton skeleton = new Spine.Skeleton(skeletonData)
                 {
                     flipX = this.initialFlipX,
                     flipY = this.initialFlipY
                 };
                 this.skeleton    = skeleton;
                 this.meshBuffers = new DoubleBuffered <MeshRendererBuffers.SmartMesh>();
                 base.get_canvasRenderer().SetTexture(this.get_mainTexture());
                 if (!string.IsNullOrEmpty(this.initialSkinName))
                 {
                     this.skeleton.SetSkin(this.initialSkinName);
                 }
                 if (!string.IsNullOrEmpty(this.startingAnimation))
                 {
                     this.state.SetAnimation(0, this.startingAnimation, this.startingLoop);
                     this.Update(0f);
                 }
             }
         }
     }
 }
 public AnimationPlayer(SkeletonData skeletonData)
 {
     this.skeletonData = skeletonData;
     skeleton = new Skeleton(skeletonData);
     skeleton.SetSlotsToSetupPose();
     animationDataPool = new ObjectPool<AnimationData>(() => new AnimationData(), 10);
 }
Esempio n. 7
0
    void Awake()
    {
        // Setting up the references.
        skeletonAnimation = GetComponent <SkeletonAnimator>();
        frontCheck        = transform.Find("frontCheck").transform;
        groundcheck       = transform.Find("groundcheck").transform;
        //score = GameObject.Find("Score").GetComponent<Score>();
        faceright  = !faceright;
        sign      *= -1;
        skeleton   = skeletonAnimation.Skeleton;
        bone       = skeletonAnimation.Skeleton.FindBone(boneName);
        anim       = GetComponent <Animator>();
        GunposBone = this.gameObject.transform.GetChild(3);
        bulletBone = this.gameObject.transform.GetChild(4);
        weapon1    = this.gameObject.transform.GetChild(1).gameObject;


        line = Instantiate(lockLiser);

        //父物体设为闪电对象
        line.transform.parent = transform;

        //设为非激活
        line.SetActive(false);
    }
Esempio n. 8
0
    // Use this for initialization
    void Start()
    {
        //randomize character's walking speed
        walkingSpeed = Random.Range(0.01f, 0.03f);

        //assign character skin from skinType
        skeletonAnimation = GetComponent <SkeletonAnimation>();
        skeleton          = skeletonAnimation.Skeleton;
        skeleton.SetSkin(((SkinType)Random.Range(0, 20)).ToString());
        //get reference to map
        mapRef = GameObject.Find("Map").GetComponent <Map>();
        // this stores where in current route-- when you start not yet at first stop, at spawn position
        currentStop = -1;
        // determines sprite animation, when you get to room then do animation assigned
        // but first start in transit
        // could start by idling

        currentlyDoing = Activity.Transit;
        timer          = 0;
        // create 5 destinations in route
        for (int i = 0; i <= 5; i++)
        {
            route.Add(generateRandomDestination());
        }
    }
Esempio n. 9
0
 // Use this for initialization
 void Start()
 {
     skeletonAnimation   = GetComponent <SkeletonAnimation>();
     dialogue            = GetComponent <DemonDogDialogue>();
     spineAnimationState = skeletonAnimation.AnimationState;
     skeleton            = skeletonAnimation.Skeleton;
 }
Esempio n. 10
0
		/// <param name="parent">May be null.</param>
		public Bone (BoneData data, Skeleton skeleton, Bone parent) {
			if (data == null) throw new ArgumentNullException("data", "data cannot be null.");
			if (skeleton == null) throw new ArgumentNullException("skeleton", "skeleton cannot be null.");
			this.data = data;
			this.skeleton = skeleton;
			this.parent = parent;
			SetToSetupPose();
		}
Esempio n. 11
0
	void Start () {
		// Make sure you get these AnimationState and Skeleton references in Start or Later. Getting and using them in Awake is not guaranteed by default execution order.
		skeletonAnimation = GetComponent<SkeletonAnimation>();
		spineAnimationState = skeletonAnimation.state;
		skeleton = skeletonAnimation.skeleton;

		StartCoroutine(DoDemoRoutine());
	}
Esempio n. 12
0
 // Use this for initialization
 void Start()
 {
     skeletonAnimation = GetComponent <SkeletonAnimator>();
     rigi     = GetComponent <Rigidbody2D>();
     anim     = GetComponent <Animator>();
     skeleton = skeletonAnimation.Skeleton;
     //weapon = GameObject.Find("weapon1");
 }
 public Entity(Skeleton skeleton, Vector2 position)
     : this(position)
 {
     Skeleton = skeleton;
     skeletonBoundingBox = ResourceManager.GetSkeletonBoundingBox(skeleton.Data.Name);
     AnimationState = new AnimationState(new AnimationStateData(skeleton.Data));
     RenderShadow = true;
 }
Esempio n. 14
0
 // Use this for initialization
 void Start()
 {
     skeletonAnimation   = GetComponent <SkeletonAnimation>();
     spineAnimationState = skeletonAnimation.state;
     skeleton            = skeletonAnimation.skeleton;
     Animate_gerakBawah();
     spineAnimationState.TimeScale = 1;
 }
 //[SpineAttachment(dataField: "DataAsset")]
 //public string attachment;
 private void Start()
 {
     skeletonAnimation   = GetComponent <SkeletonAnimation>();
     spineAnimationState = skeletonAnimation.AnimationState;
     skeleton            = skeletonAnimation.Skeleton;
     //
     thisSlotBaseData = skeleton.FindSlot(slot).Bone.Data;
 }
 public virtual void Initialize(bool overwrite)
 {
     if (!this.valid || overwrite)
     {
         if (this.meshFilter != null)
         {
             this.meshFilter.sharedMesh = null;
         }
         this.meshRenderer = base.GetComponent <MeshRenderer>();
         if (this.meshRenderer != null)
         {
             this.meshRenderer.sharedMaterial = null;
         }
         this.currentInstructions.Clear();
         this.rendererBuffers.Clear();
         this.meshGenerator.Begin();
         this.skeleton = null;
         this.valid    = false;
         if (this.skeletonDataAsset == null)
         {
             if (this.logErrors)
             {
                 UnityEngine.Debug.LogError("Missing SkeletonData asset.", this);
             }
         }
         else
         {
             SkeletonData skeletonData = this.skeletonDataAsset.GetSkeletonData(false);
             if (skeletonData != null)
             {
                 this.valid        = true;
                 this.meshFilter   = base.GetComponent <MeshFilter>();
                 this.meshRenderer = base.GetComponent <MeshRenderer>();
                 this.rendererBuffers.Initialize();
                 Spine.Skeleton skeleton = new Spine.Skeleton(skeletonData)
                 {
                     flipX = this.initialFlipX,
                     flipY = this.initialFlipY
                 };
                 this.skeleton = skeleton;
                 if (!string.IsNullOrEmpty(this.initialSkinName) && !string.Equals(this.initialSkinName, "default", StringComparison.Ordinal))
                 {
                     this.skeleton.SetSkin(this.initialSkinName);
                 }
                 this.separatorSlots.Clear();
                 for (int i = 0; i < this.separatorSlotNames.Length; i++)
                 {
                     this.separatorSlots.Add(this.skeleton.FindSlot(this.separatorSlotNames[i]));
                 }
                 this.LateUpdate();
                 if (this.OnRebuild != null)
                 {
                     this.OnRebuild(this);
                 }
             }
         }
     }
 }
Esempio n. 17
0
File: Slot.cs Progetto: D021/ink
		public Slot (SlotData data, Skeleton skeleton, Bone bone) {
			if (data == null) throw new ArgumentNullException("data cannot be null.");
			if (skeleton == null) throw new ArgumentNullException("skeleton cannot be null.");
			if (bone == null) throw new ArgumentNullException("bone cannot be null.");
			this.data = data;
			this.skeleton = skeleton;
			this.bone = bone;
			SetToSetupPose();
		}
Esempio n. 18
0
    void Start()
    {
        // Make sure you get these AnimationState and Skeleton references in Start or Later. Getting and using them in Awake is not guaranteed by default execution order.
        skeletonAnimation   = GetComponent <SkeletonAnimation>();
        spineAnimationState = skeletonAnimation.state;
        skeleton            = skeletonAnimation.skeleton;

        StartCoroutine(DoDemoRoutine());
    }
Esempio n. 19
0
 // Use this for initialization
 void Start()
 {
     LifeTimeCounter     = 0;
     AnimDuration        = 0.8f;
     AnimCounter         = 0.8f;
     skeletonAnimation   = GetComponent <SkeletonAnimation>();
     spineAnimationState = skeletonAnimation.AnimationState;
     skeleton            = skeletonAnimation.Skeleton;
 }
Esempio n. 20
0
        public SkeletonSpatial(GraphicsDevice device, string contentPath, string skin)
        {
            if (!_registered.TryGetValue(contentPath, out _record))
                _record = Load(device, contentPath);

            _skeleton = new Skeleton(_record.Data);
            _skeleton.SetSkin(skin);
            _skeleton.SetSlotsToBindPose();
        }
		public void Draw (Skeleton skeleton) {
			var drawOrder = skeleton.DrawOrder;
			var drawOrderItems = skeleton.DrawOrder.Items;
			float skeletonR = skeleton.R, skeletonG = skeleton.G, skeletonB = skeleton.B, skeletonA = skeleton.A;
			for (int i = 0, n = drawOrder.Count; i < n; i++) {
				Slot slot = drawOrderItems[i];
				RegionAttachment regionAttachment = slot.Attachment as RegionAttachment;
				if (regionAttachment != null) {
					BlendState blend = slot.Data.BlendMode == BlendMode.additive ? BlendState.Additive : defaultBlendState;
					if (device.BlendState != blend) {
						End();
						device.BlendState = blend;
					}

					RegionItem item = batcher.NextItem();

					AtlasRegion region = (AtlasRegion)regionAttachment.RendererObject;
					item.texture = (Texture2D)region.page.rendererObject;

					Color color;
					float a = skeletonA * slot.A;
					if (premultipliedAlpha)
						color = new Color(skeletonR * slot.R * a, skeletonG * slot.G * a, skeletonB * slot.B * a, a);
					else
						color = new Color(skeletonR * slot.R, skeletonG * slot.G, skeletonB * slot.B, a);
					item.vertexTL.Color = color;
					item.vertexBL.Color = color;
					item.vertexBR.Color = color;
					item.vertexTR.Color = color;

					float[] vertices = this.vertices;
					regionAttachment.ComputeWorldVertices(slot.Bone, vertices);
					item.vertexTL.Position.X = vertices[RegionAttachment.X1];
					item.vertexTL.Position.Y = vertices[RegionAttachment.Y1];
					item.vertexTL.Position.Z = 0;
					item.vertexBL.Position.X = vertices[RegionAttachment.X2];
					item.vertexBL.Position.Y = vertices[RegionAttachment.Y2];
					item.vertexBL.Position.Z = 0;
					item.vertexBR.Position.X = vertices[RegionAttachment.X3];
					item.vertexBR.Position.Y = vertices[RegionAttachment.Y3];
					item.vertexBR.Position.Z = 0;
					item.vertexTR.Position.X = vertices[RegionAttachment.X4];
					item.vertexTR.Position.Y = vertices[RegionAttachment.Y4];
					item.vertexTR.Position.Z = 0;

					float[] uvs = regionAttachment.UVs;
					item.vertexTL.TextureCoordinate.X = uvs[RegionAttachment.X1];
					item.vertexTL.TextureCoordinate.Y = uvs[RegionAttachment.Y1];
					item.vertexBL.TextureCoordinate.X = uvs[RegionAttachment.X2];
					item.vertexBL.TextureCoordinate.Y = uvs[RegionAttachment.Y2];
					item.vertexBR.TextureCoordinate.X = uvs[RegionAttachment.X3];
					item.vertexBR.TextureCoordinate.Y = uvs[RegionAttachment.Y3];
					item.vertexTR.TextureCoordinate.X = uvs[RegionAttachment.X4];
					item.vertexTR.TextureCoordinate.Y = uvs[RegionAttachment.Y4];
				}
			}
		}
Esempio n. 22
0
    public void DoUpdate()
    {
        if (!valid)
        {
            Reset();
            return;
        }

        if (bone == null)
        {
            if (boneName == null || boneName.Length == 0)
            {
                return;
            }
            bone = skeletonRenderer.skeleton.FindBone(boneName);
            if (bone == null)
            {
                Debug.LogError("Bone not found: " + boneName, this);
                return;
            }
            else
            {
            }
        }

        Spine.Skeleton skeleton     = skeletonRenderer.skeleton;
        float          flipRotation = (skeleton.flipX ^ skeleton.flipY) ? -1f : 1f;

        if (cachedTransform.parent == skeletonTransform)
        {
            cachedTransform.localPosition = new Vector3(bone.worldX, bone.worldY, followZPosition ? 0f : cachedTransform.localPosition.z) + cachedTransform.localRotation * offset;

            if (followBoneRotation)
            {
                Vector3 rotation = cachedTransform.localRotation.eulerAngles;
                cachedTransform.localRotation = Quaternion.Euler(rotation.x, rotation.y, bone.worldRotation * flipRotation);
            }
        }
        else
        {
            Vector3 targetWorldPosition = skeletonTransform.TransformPoint(new Vector3(bone.worldX, bone.worldY, 0f));
            if (!followZPosition)
            {
                targetWorldPosition.z = cachedTransform.position.z;
            }

            cachedTransform.position = targetWorldPosition;

            if (followBoneRotation)
            {
                Vector3 rotation = skeletonTransform.rotation.eulerAngles;

                cachedTransform.rotation = Quaternion.Euler(rotation.x, rotation.y, skeletonTransform.rotation.eulerAngles.z + (bone.worldRotation * flipRotation));
            }
        }
    }
Esempio n. 23
0
		public IkConstraint (IkConstraintData data, Skeleton skeleton) {
			this.data = data;
			mix = data.mix;
			bendDirection = data.bendDirection;

			bones = new List<Bone>(data.bones.Count);
			foreach (BoneData boneData in data.bones)
				bones.Add(skeleton.FindBone(boneData.name));
			target = skeleton.FindBone(data.target.name);
		}
Esempio n. 24
0
        /** Poses the skeleton at the specified time for this animation. */
        public void Apply(Skeleton skeleton, float time, bool loop)
        {
            if (skeleton == null) throw new ArgumentNullException("skeleton cannot be null.");

            if (loop && Duration != 0) time %= Duration;

            List<Timeline> timelines = Timelines;
            for (int i = 0, n = timelines.Count; i < n; i++)
                timelines[i].Apply(skeleton, time, 1);
        }
    public override float Execute(Skill skill)
    {
        Spine.Skeleton skeleton = actor.GetGameObject().GetComponent <SkeletonAnimation>().skeleton;

        color   = skeleton.GetColor();
        color.a = alphaTarget;
        DOTween.To(() => skeleton.Color, x => skeleton.Color = x, color, duration);

        return(duration);
    }
Esempio n. 26
0
		public DrawPackage(Vector2 pPosition, float pPositionZ, Rectangle pCollisionBox, Color pDebugColor, Skeleton pSkeleton, float pAlpha = 1f)
		{
			mPosition = pPosition;
			mPositionZ = pPositionZ;
			mCollisionBox = pCollisionBox;
			mDebugColor = pDebugColor;
			mSkeleton = pSkeleton;
			mAlpha = pAlpha;
			Spine = true;
		}
Esempio n. 27
0
		public TransformConstraint (TransformConstraintData data, Skeleton skeleton) {
			if (data == null) throw new ArgumentNullException("data cannot be null.");
			if (skeleton == null) throw new ArgumentNullException("skeleton cannot be null.");
			this.data = data;
			translateMix = data.translateMix;
			x = data.x;
			y = data.y;

			bone = skeleton.FindBone(data.bone.name);
			target = skeleton.FindBone(data.target.name);
		}
Esempio n. 28
0
 // Use this for initialization
 void Start()
 {
     skeletonAnimation = GetComponent <SkeletonAnimator>();
     rigi       = GetComponent <Rigidbody2D>();
     anim       = GetComponent <Animator>();
     skeleton   = skeletonAnimation.Skeleton;
     bone       = skeletonAnimation.Skeleton.FindBone(boneName);
     GunposBone = GameObject.Find("gunpos");
     bulletBone = GameObject.Find("bulletpos");
     playerpos  = player.transform.GetChild(0);
 }
Esempio n. 29
0
		private void DrawSlots(Skeleton skeleton)
		{
			isNormalTriangleWindingOrder = skeleton.FlipX ^ skeleton.FlipY;
			List<Slot> drawOrder = skeleton.DrawOrder;
			foreach (Slot slot in drawOrder)
			{
				var attachment = slot.Attachment as RegionAttachment;
				if (attachment != null)
					DrawSlot(skeleton, attachment, slot);
			}
		}
Esempio n. 30
0
    void Start()
    {
        // Make sure you get these AnimationState and Skeleton references in Start or Later.
        // Getting and using them in Awake is not guaranteed by default execution order.
        skeletonAnimation = GetComponent <SkeletonAnimation>();
        //Debug.Log(skeletonAnimation.skeletonDataAsset.GetAnimationStateData().DefaultMix);
        spineAnimationState = skeletonAnimation.AnimationState;
        skeleton            = skeletonAnimation.Skeleton;

        StartCoroutine(DoDemoRoutine());
    }
        public void Draw(Skeleton skeleton, Vector3 Position)
        {
            List<Slot> DrawOrder = skeleton.DrawOrder;

            float depth = Z;
            float depth_offset = 0.0001f;
            for (int i = 0; i < DrawOrder.Count; i++) {
                Slot slot = DrawOrder[i];
                RegionAttachment regionAttachment = slot.Attachment as RegionAttachment;
                if (regionAttachment != null) {
                    SpriteBatchItem item = new SpriteBatchItem();
                    AtlasRegion region = (AtlasRegion)regionAttachment.RendererObject;
                    item.Texture = (int)region.page.rendererObject;

                    byte r = (byte)(skeleton.R * slot.R * 255);
                    byte g = (byte)(skeleton.G * slot.G * 255);
                    byte b = (byte)(skeleton.B * slot.B * 255);
                    byte a = (byte)(skeleton.A * slot.A * 255);
                    item.vertexTL.Color = Color.FromArgb(a, r, g, b);
                    item.vertexBL.Color = Color.FromArgb(a, r, g, b);
                    item.vertexBR.Color = Color.FromArgb(a, r, g, b);
                    item.vertexTR.Color = Color.FromArgb(a, r, g, b);

                    float[] vertices = this.vertices;
                    regionAttachment.ComputeWorldVertices(skeleton.X, skeleton.Y, slot.Bone, vertices);
                    item.vertexTL.Position.X = vertices[RegionAttachment.X1];
                    item.vertexTL.Position.Y = vertices[RegionAttachment.Y1];
                    item.vertexTL.Position.Z = depth;
                    item.vertexBL.Position.X = vertices[RegionAttachment.X2];
                    item.vertexBL.Position.Y = vertices[RegionAttachment.Y2];
                    item.vertexBL.Position.Z = depth;
                    item.vertexBR.Position.X = vertices[RegionAttachment.X3];
                    item.vertexBR.Position.Y = vertices[RegionAttachment.Y3];
                    item.vertexBR.Position.Z = depth;
                    item.vertexTR.Position.X = vertices[RegionAttachment.X4];
                    item.vertexTR.Position.Y = vertices[RegionAttachment.Y4];
                    item.vertexTR.Position.Z = depth;

                    float[] uvs = regionAttachment.UVs;
                    item.vertexTL.TextureCoordinate.X = uvs[RegionAttachment.X1];
                    item.vertexTL.TextureCoordinate.Y = uvs[RegionAttachment.Y1];
                    item.vertexBL.TextureCoordinate.X = uvs[RegionAttachment.X2];
                    item.vertexBL.TextureCoordinate.Y = uvs[RegionAttachment.Y2];
                    item.vertexBR.TextureCoordinate.X = uvs[RegionAttachment.X3];
                    item.vertexBR.TextureCoordinate.Y = uvs[RegionAttachment.Y3];
                    item.vertexTR.TextureCoordinate.X = uvs[RegionAttachment.X4];
                    item.vertexTR.TextureCoordinate.Y = uvs[RegionAttachment.Y4];

                    this.DrawItem(item);
                    depth += depth_offset;
                }
            }
        }
Esempio n. 32
0
		public IkConstraint (IkConstraintData data, Skeleton skeleton) {
			if (data == null) throw new ArgumentNullException("data cannot be null.");
			if (skeleton == null) throw new ArgumentNullException("skeleton cannot be null.");
			this.data = data;
			mix = data.mix;
			bendDirection = data.bendDirection;

			bones = new ExposedList<Bone>(data.bones.Count);
			foreach (BoneData boneData in data.bones)
				bones.Add(skeleton.FindBone(boneData.name));
			target = skeleton.FindBone(data.target.name);
		}
Esempio n. 33
0
		/// <summary>Poses the skeleton at the specified time for this animation mixed with the current pose.</summary>
		/// <param name="lastTime">The last time the animation was applied.</param>
		/// <param name="events">Any triggered events are added.</param>
		/// <param name="alpha">The amount of this animation that affects the current pose.</param>
		public void Mix (Skeleton skeleton, float lastTime, float time, bool loop, List<Event> events, float alpha) {
			if (skeleton == null) throw new ArgumentNullException("skeleton cannot be null.");

			if (loop && duration != 0) {
				time %= duration;
				lastTime %= duration;
			}

			List<Timeline> timelines = this.timelines;
			for (int i = 0, n = timelines.Count; i < n; i++)
				timelines[i].Apply(skeleton, lastTime, time, events, alpha);
		}
Esempio n. 34
0
		/// <summary>Applies all the animation's timelines to the specified skeleton.</summary>
		/// <param name="skeleton">The skeleton to be posed.</param>
		/// <param name="lastTime">The last time the animation was applied.</param>
		/// <param name="time">The point in time in the animation to apply to the skeleton.</param>
		/// <param name="loop">If true, time wraps within the animation duration.</param>
		/// <param name="events">Any triggered events are added. May be null.</param>
		/// <param name="alpha">The percentage between this animation's pose and the current pose.</param>
		/// <param name="setupPose">If true, the animation is mixed with the setup pose, else it is mixed with the current pose. Passing true when alpha is 1 is slightly more efficient.</param>
		/// <param name="mixingOut">True when mixing over time toward the setup or current pose, false when mixing toward the keyed pose. Irrelevant when alpha is 1.</param>
		/// <seealso cref="Timeline.Apply(Skeleton, float, float, ExposedList, float, bool, bool)"/>
		public void Apply (Skeleton skeleton, float lastTime, float time, bool loop, ExposedList<Event> events, float alpha, bool setupPose, bool mixingOut) {
			if (skeleton == null) throw new ArgumentNullException("skeleton", "skeleton cannot be null.");

			if (loop && duration != 0) {
				time %= duration;
				if (lastTime > 0) lastTime %= duration;
			}

			ExposedList<Timeline> timelines = this.timelines;
			for (int i = 0, n = timelines.Count; i < n; i++)
				timelines.Items[i].Apply(skeleton, lastTime, time, events, alpha, setupPose, mixingOut);
		}
Esempio n. 35
0
		public PathConstraint (PathConstraintData data, Skeleton skeleton) {
			if (data == null) throw new ArgumentNullException("data", "data cannot be null.");
			if (skeleton == null) throw new ArgumentNullException("skeleton", "skeleton cannot be null.");
			this.data = data;
			bones = new ExposedList<Bone>(data.Bones.Count);
			foreach (BoneData boneData in data.bones)
				bones.Add(skeleton.FindBone(boneData.name));
			target = skeleton.FindSlot(data.target.name);
			position = data.position;
			spacing = data.spacing;
			rotateMix = data.rotateMix;
			translateMix = data.translateMix;
		}
Esempio n. 36
0
		private void DrawSlot(Skeleton skeleton, RegionAttachment attachment, Slot slot)
		{
			var region = (AtlasRegion)attachment.RendererObject;
			var thisMaterial = (Material)region.page.rendererObject;
			var thisBlendMode = slot.Data.AdditiveBlending ? BlendMode.Additive : BlendMode.Normal;
			var thisBatch = (Batch2D)renderer.FindOrCreateBatch(thisMaterial, thisBlendMode);
			if (currentBatch != null && currentBatch != thisBatch)
				renderer.FlushDrawBuffer(currentBatch);
			currentBatch = thisBatch;
			attachment.ComputeWorldVertices(skeleton.X, skeleton.Y, slot.Bone, vertices);
			currentColor = new Color(color.RedValue * slot.R, color.GreenValue * slot.G,
				color.BlueValue * slot.B, color.AlphaValue * slot.A);
			AddSlotIndicesAndVertices(attachment.UVs);
		}
Esempio n. 37
0
 static int SetSlotsToSetupPose(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         Spine.Skeleton obj = (Spine.Skeleton)ToLua.CheckObject <Spine.Skeleton>(L, 1);
         obj.SetSlotsToSetupPose();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Esempio n. 38
0
 public void Apply(Skeleton skeleton)
 {
     if (Animation == null) return;
     if (previous != null) {
         previous.Apply(skeleton, previousTime, previousLoop);
         float alpha = mixTime / mixDuration;
         if (alpha >= 1) {
             alpha = 1;
             previous = null;
         }
         Animation.Mix(skeleton, Time, Loop, alpha);
     } else
         Animation.Apply(skeleton, Time, Loop);
 }
        public void Draw(SpriteBatchEx spriteBatch, Skeleton skeleton, Vector2 position, float rotation, Vector2 scale, Color tintColor, bool flipHorizontal, bool flipVertical)
        {
            List<Slot> drawOrder = skeleton.DrawOrder;
            float x = skeleton.X, y = skeleton.Y;
            float skeletonR = skeleton.R, skeletonG = skeleton.G, skeletonB = skeleton.B, skeletonA = skeleton.A;

            for (int i = 0, n = drawOrder.Count; i < n; i++)
            {
                Slot slot = drawOrder[i];

                RegionAttachment regionAttachment = slot.Attachment as RegionAttachment;
                if (regionAttachment != null)
                {
                    AtlasRegion region = (AtlasRegion)regionAttachment.RendererObject;

                    byte r = (byte)(skeletonR * slot.R * 255);
                    byte g = (byte)(skeletonG * slot.G * 255);
                    byte b = (byte)(skeletonB * slot.B * 255);
                    byte a = (byte)(skeletonA * slot.A * 255);

                    float offsetX = (regionAttachment.Offset[0] + regionAttachment.Offset[4]) / 2;
                    float offsetY = (regionAttachment.Offset[1] + regionAttachment.Offset[5]) / 2;

                    float m00 = slot.Bone.M00;
                    float m01 = slot.Bone.M01;
                    float m11 = slot.Bone.M11;
                    float m10 = slot.Bone.M10;

                    float localX = slot.Bone.WorldX + x;
                    float localY = slot.Bone.WorldY + y;

                    Texture2D texture = (Texture2D)region.page.rendererObject;

                    // notes:
                    // I'm not sure if multiplying the tint color against Spine's color is correct.
                    // Keep in mind that we're usually in Premultipled Alpha mode here.
                    spriteBatch.Draw(texture,
                        new Vector2(offsetX * m00 + offsetY * m01 + localX, offsetX * m10 + offsetY * m11 + localY),
                        new Rectangle(region.x, region.y, region.width, region.height),
                        new Color(r * tintColor.R, g * tintColor.G, b * tintColor.B, a * tintColor.A),
                        -(slot.Bone.WorldRotation + regionAttachment.Rotation) * 3.14159f / 180.0f,
                        new Vector2(0.5f, 0.5f),
                        new Vector2(slot.Bone.WorldScaleX, slot.Bone.WorldScaleY),
                        region.rotate ? SpriteEffectsEx.RotatePackedUVs : SpriteEffectsEx.None,
                        Matrix.CreateScale(flipHorizontal ? -scale.X : scale.X, flipVertical ? -scale.Y : scale.Y, 1) *
                        Matrix.CreateRotationZ(rotation) *
                        Matrix.CreateTranslation(position.X, position.Y, 0));
                }
            }
        }
Esempio n. 40
0
 static int UpdateWorldTransform(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         Spine.Skeleton obj = (Spine.Skeleton)ToLua.CheckObject <Spine.Skeleton>(L, 1);
         obj.UpdateWorldTransform();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Esempio n. 41
0
        public void Draw(Skeleton skeleton)
        {
            List<Slot> drawOrder = skeleton.DrawOrder;
            for (int i = 0, n = drawOrder.Count; i < n; i++) {
                Slot slot = drawOrder[i];
                Attachment attachment = slot.Attachment;
                if (attachment == null)
                    continue;
                if (attachment is RegionAttachment) {
                    RegionAttachment regionAttachment = (RegionAttachment)attachment;

                    SpriteBatchItem item = batcher.CreateBatchItem();
                    item.Texture = ((XnaAtlasPage)regionAttachment.Region.Page).Texture;

                    item.vertexTL.Color = new Color(slot.R, slot.G, slot.B, slot.A);

                    item.vertexBL.Color = new Color(slot.R, slot.G, slot.B, slot.A);

                    item.vertexBR.Color = new Color(slot.R, slot.G, slot.B, slot.A);

                    item.vertexTR.Color = new Color(slot.R, slot.G, slot.B, slot.A);

                    regionAttachment.UpdateVertices(slot.Bone);
                    float[] vertices = regionAttachment.Vertices;
                    item.vertexTL.Position.X = vertices[RegionAttachment.X1];
                    item.vertexTL.Position.Y = vertices[RegionAttachment.Y1];
                    item.vertexTL.Position.Z = 0;
                    item.vertexBL.Position.X = vertices[RegionAttachment.X2];
                    item.vertexBL.Position.Y = vertices[RegionAttachment.Y2];
                    item.vertexBL.Position.Z = 0;
                    item.vertexBR.Position.X = vertices[RegionAttachment.X3];
                    item.vertexBR.Position.Y = vertices[RegionAttachment.Y3];
                    item.vertexBR.Position.Z = 0;
                    item.vertexTR.Position.X = vertices[RegionAttachment.X4];
                    item.vertexTR.Position.Y = vertices[RegionAttachment.Y4];
                    item.vertexTR.Position.Z = 0;

                    float[] uvs = regionAttachment.UVs;
                    item.vertexTL.TextureCoordinate.X = uvs[RegionAttachment.X1];
                    item.vertexTL.TextureCoordinate.Y = uvs[RegionAttachment.Y1];
                    item.vertexBL.TextureCoordinate.X = uvs[RegionAttachment.X2];
                    item.vertexBL.TextureCoordinate.Y = uvs[RegionAttachment.Y2];
                    item.vertexBR.TextureCoordinate.X = uvs[RegionAttachment.X3];
                    item.vertexBR.TextureCoordinate.Y = uvs[RegionAttachment.Y3];
                    item.vertexTR.TextureCoordinate.X = uvs[RegionAttachment.X4];
                    item.vertexTR.TextureCoordinate.Y = uvs[RegionAttachment.Y4];
                }
            }
        }
Esempio n. 42
0
 static int Update(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         Spine.Skeleton obj  = (Spine.Skeleton)ToLua.CheckObject <Spine.Skeleton>(L, 1);
         float          arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
         obj.Update(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Esempio n. 43
0
    // Use this for initialization
    void Start()
    {
        skeletonAnimation   = GetComponent <SkeletonAnimation>();
        spineAnimationState = skeletonAnimation.AnimationState;
        skeleton            = skeletonAnimation.Skeleton;

        skeletonAnimation.AnimationState.Event += HandleEvent;


        //Initialize State Machine Engine
        fsm = StateMachine <States> .Initialize(this, States.Idle);

        mTargetPos = Vector3.zero;
        nextState  = States.Idle;
    }
Esempio n. 44
0
 static int Apply(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         Spine.AnimationState obj  = (Spine.AnimationState)ToLua.CheckObject(L, 1, typeof(Spine.AnimationState));
         Spine.Skeleton       arg0 = (Spine.Skeleton)ToLua.CheckObject(L, 2, typeof(Spine.Skeleton));
         obj.Apply(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Esempio n. 45
0
    // Use this for initialization
    void Start()
    {
        skeletonAnimation   = GetComponent <SkeletonAnimation>();
        spineAnimationState = skeletonAnimation.AnimationState;
        skeleton            = skeletonAnimation.Skeleton;

        spineAnimationState.SetAnimation(3, "walk", true);

        animator = GetComponent <Animator>();
        animator.Play("walk");
        base.Start(); //Utilizing Start() from baseEnemy.cs
        damage = 3;
        health = 5;
        speed  = 3.0f;
    }
		public TransformConstraint (TransformConstraintData data, Skeleton skeleton) {
			if (data == null) throw new ArgumentNullException("data", "data cannot be null.");
			if (skeleton == null) throw new ArgumentNullException("skeleton", "skeleton cannot be null.");
			this.data = data;
			rotateMix = data.rotateMix;
			translateMix = data.translateMix;
			scaleMix = data.scaleMix;
			shearMix = data.shearMix;

			bones = new ExposedList<Bone>();
			foreach (BoneData boneData in data.bones)
				bones.Add (skeleton.FindBone (boneData.name));
			
			target = skeleton.FindBone(data.target.name);
		}
Esempio n. 47
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;
        }
        /// <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;
        }
Esempio n. 49
0
        protected override void LoadContent()
        {
            Effect spriteBatchEffect = Content.Load<Effect>("SpriteBatchEffect");
            spriteBatch = new SpriteBatchEx(GraphicsDevice, spriteBatchEffect);

            Bone.yDown = true;
            skeletonData = Content.Load<SkeletonData>("spineboy/spineboy");
            skeleton = new Skeleton(skeletonData);
            skeleton.SetSlotsToSetupPose();

            AnimationStateData stateData = new AnimationStateData(skeleton.Data);
            animationState = new AnimationState(stateData);
            animationState.SetAnimation(0, "walk", true);

            skeleton.UpdateWorldTransform();
        }
Esempio n. 50
0
 static int Apply(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         Spine.AnimationState obj  = (Spine.AnimationState)ToLua.CheckObject <Spine.AnimationState>(L, 1);
         Spine.Skeleton       arg0 = (Spine.Skeleton)ToLua.CheckObject <Spine.Skeleton>(L, 2);
         bool o = obj.Apply(arg0);
         LuaDLL.lua_pushboolean(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
		void OnEnable () {
			skeletonUtility = (SkeletonUtility)target;
			skeletonRenderer = skeletonUtility.GetComponent<SkeletonRenderer>();
			skeleton = skeletonRenderer.skeleton;
			transform = skeletonRenderer.transform;

			if (skeleton == null) {
				skeletonRenderer.Initialize(false);
				skeletonRenderer.LateUpdate();

				skeleton = skeletonRenderer.skeleton;
			}

			UpdateAttachments();
			isPrefab |= PrefabUtility.GetPrefabType(this.target) == PrefabType.Prefab;
		}
Esempio n. 52
0
 static int FindSlotIndex(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         Spine.Skeleton obj  = (Spine.Skeleton)ToLua.CheckObject <Spine.Skeleton>(L, 1);
         string         arg0 = ToLua.CheckString(L, 2);
         int            o    = obj.FindSlotIndex(arg0);
         LuaDLL.lua_pushinteger(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Esempio n. 53
0
 static int SetAttachment(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         Spine.Skeleton obj  = (Spine.Skeleton)ToLua.CheckObject <Spine.Skeleton>(L, 1);
         string         arg0 = ToLua.CheckString(L, 2);
         string         arg1 = ToLua.CheckString(L, 3);
         obj.SetAttachment(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Esempio n. 54
0
 static int FindPathConstraint(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         Spine.Skeleton       obj  = (Spine.Skeleton)ToLua.CheckObject <Spine.Skeleton>(L, 1);
         string               arg0 = ToLua.CheckString(L, 2);
         Spine.PathConstraint o    = obj.FindPathConstraint(arg0);
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Esempio n. 55
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");
		}
Esempio n. 56
0
    static int set_Skin(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            Spine.Skeleton obj  = (Spine.Skeleton)o;
            Spine.Skin     arg0 = (Spine.Skin)ToLua.CheckObject <Spine.Skin>(L, 2);
            obj.Skin = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index Skin on a nil value"));
        }
    }
Esempio n. 57
0
    static int set_FlipY(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            Spine.Skeleton obj  = (Spine.Skeleton)o;
            bool           arg0 = LuaDLL.luaL_checkboolean(L, 2);
            obj.FlipY = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index FlipY on a nil value"));
        }
    }
Esempio n. 58
0
 //initialize all the spine element
 public void SetupSpineAnim()
 {
     if (skeletonAnimation == null)
     {
         skeletonAnimation         = GetComponent <SkeletonAnimation>();
         skeletonAnimation.enabled = true;
         SpineAnimationState       = skeletonAnimation.AnimationState;
         skeleton = skeletonAnimation.Skeleton;
         //SpineAnimationState.Complete += SpineAnimationState_Complete;
         if (SpineAnimationState != null)
         {
             SpineAnimationState.Event += SpineAnimationState_Event;
         }
         //SpineAnimationState.SetAnimation(0, CharacterAnimationStateType.Idle.ToString(), true);
         //SpineAnimationState.SetEmptyAnimation(1, 0);
     }
 }
Esempio n. 59
0
    static int set_Y(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            Spine.Skeleton obj  = (Spine.Skeleton)o;
            float          arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
            obj.Y = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index Y on a nil value"));
        }
    }
Esempio n. 60
0
		public TransformConstraint (TransformConstraintData data, Skeleton skeleton) {
			if (data == null) throw new ArgumentNullException("data cannot be null.");
			if (skeleton == null) throw new ArgumentNullException("skeleton cannot be null.");
			this.data = data;
			translateMix = data.translateMix;
			rotateMix = data.rotateMix;
			scaleMix = data.scaleMix;
			shearMix = data.shearMix;
			offsetRotation = data.offsetRotation;
			offsetX = data.offsetX;
			offsetY = data.offsetY;
			offsetScaleX = data.offsetScaleX;
			offsetScaleY = data.offsetScaleY;
			offsetShearY = data.offsetShearY;

			bone = skeleton.FindBone(data.bone.name);
			target = skeleton.FindBone(data.target.name);
		}