Exemplo n.º 1
0
        public void Attach()
        {
            var skeletonComponent = GetComponent <ISkeletonComponent>();

            var skeletonRenderer = skeletonComponent as SkeletonRenderer;

            if (skeletonRenderer != null)
            {
                this.applyPMA = skeletonRenderer.pmaVertexColors;
            }
            else
            {
                var skeletonGraphic = skeletonComponent as SkeletonGraphic;
                if (skeletonGraphic != null)
                {
                    this.applyPMA = skeletonGraphic.SpineMeshGenerator.PremultiplyVertexColors;
                }
            }

            Shader attachmentShader = applyPMA ? Shader.Find(DefaultPMAShader) : Shader.Find(DefaultStraightAlphaShader);

            loader = loader ?? new SpriteAttachmentLoader(sprite, attachmentShader, applyPMA);

            if (attachment == null)
            {
                attachment = loader.NewRegionAttachment(null, sprite.name, "");
            }

            skeletonComponent.Skeleton.FindSlot(slot).Attachment = attachment;

            if (!keepLoaderInMemory)
            {
                loader = null;
            }
        }
Exemplo n.º 2
0
        public static RegionAttachment ToRegionAttachment(this Sprite sprite, string shaderName = "Spine/Skeleton")
        {
            var loader = new SpriteAttachmentLoader(sprite, Shader.Find(shaderName));
            var att    = loader.NewRegionAttachment(null, sprite.name, "");

            loader = null;
            return(att);
        }
Exemplo n.º 3
0
        public static RegionAttachment ToRegionAttachment(this Sprite sprite, Shader shader, bool applyPMA)
        {
            var loader = new SpriteAttachmentLoader(sprite, shader, applyPMA);
            var att    = loader.NewRegionAttachment(null, sprite.name, "");

            loader = null;
            return(att);
        }
Exemplo n.º 4
0
        public RegionAttachment NewRegionAttachment(Skin skin, string name, string path)
        {
            RegionAttachment regionAttachment = new RegionAttachment(name);
            Texture2D        texture          = this.sprite.texture;
            int         instanceID            = texture.GetInstanceID();
            AtlasRegion atlasRegion;

            if (!SpriteAttachmentLoader.atlasTable.TryGetValue(instanceID, out atlasRegion))
            {
                Material material = new Material(this.shader);
                if (this.sprite.packed)
                {
                    material.name = "Unity Packed Sprite Material";
                }
                else
                {
                    material.name = this.sprite.name + " Sprite Material";
                }
                material.mainTexture = texture;
                atlasRegion          = new AtlasRegion();
                AtlasPage atlasPage = new AtlasPage();
                atlasPage.rendererObject = material;
                atlasRegion.page         = atlasPage;
                SpriteAttachmentLoader.atlasTable[instanceID] = atlasRegion;
            }
            Rect textureRect = this.sprite.textureRect;

            textureRect.x      = Mathf.InverseLerp(0f, (float)texture.width, textureRect.x);
            textureRect.y      = Mathf.InverseLerp(0f, (float)texture.height, textureRect.y);
            textureRect.width  = Mathf.InverseLerp(0f, (float)texture.width, textureRect.width);
            textureRect.height = Mathf.InverseLerp(0f, (float)texture.height, textureRect.height);
            Bounds  bounds  = this.sprite.bounds;
            Vector2 vector  = bounds.min;
            Vector2 vector2 = bounds.max;
            Vector2 vector3 = bounds.size;
            float   num     = 1f / this.sprite.pixelsPerUnit;
            bool    rotate  = false;

            if (this.sprite.packed)
            {
                rotate = (this.sprite.packingRotation == SpritePackingRotation.Any);
            }
            regionAttachment.SetUVs(textureRect.xMin, textureRect.yMax, textureRect.xMax, textureRect.yMin, rotate);
            regionAttachment.RendererObject = atlasRegion;
            regionAttachment.SetColor(Color.white);
            regionAttachment.ScaleX               = 1f;
            regionAttachment.ScaleY               = 1f;
            regionAttachment.RegionOffsetX        = this.sprite.rect.width * (0.5f - SpriteAttachmentLoader.InverseLerp(vector.x, vector2.x, 0f)) * num;
            regionAttachment.RegionOffsetY        = this.sprite.rect.height * (0.5f - SpriteAttachmentLoader.InverseLerp(vector.y, vector2.y, 0f)) * num;
            regionAttachment.Width                = vector3.x;
            regionAttachment.Height               = vector3.y;
            regionAttachment.RegionWidth          = vector3.x;
            regionAttachment.RegionHeight         = vector3.y;
            regionAttachment.RegionOriginalWidth  = vector3.x;
            regionAttachment.RegionOriginalHeight = vector3.y;
            regionAttachment.UpdateOffset();
            return(regionAttachment);
        }
Exemplo n.º 5
0
		public void Attach () {
			var skeletonRenderer = GetComponent<SkeletonRenderer>();

			if (loader == null)
				//create loader instance, tell it what sprite and shader to use
				loader = new SpriteAttachmentLoader(sprite, Shader.Find("Spine/Skeleton"));

			if (attachment == null)
				attachment = loader.NewRegionAttachment(null, sprite.name, "");

			skeletonRenderer.skeleton.FindSlot(slot).Attachment = attachment;

			if (!keepLoaderInMemory)
				loader = null;
		}
Exemplo n.º 6
0
        public void Attach()
        {
            var skeletonRenderer = GetComponent <SkeletonRenderer>();

            if (loader == null)
            {
                //create loader instance, tell it what sprite and shader to use
                loader = new SpriteAttachmentLoader(sprite, Shader.Find("Spine/Skeleton"));
            }

            if (attachment == null)
            {
                attachment = loader.NewRegionAttachment(null, sprite.name, "");
            }

            skeletonRenderer.skeleton.FindSlot(slot).Attachment = attachment;

            if (!keepLoaderInMemory)
            {
                loader = null;
            }
        }
Exemplo n.º 7
0
		public void Attach () {
			var skeletonComponent = GetComponent<ISkeletonComponent>();

			var skeletonRenderer = skeletonComponent as SkeletonRenderer;
			if (skeletonRenderer != null)
				this.applyPMA = skeletonRenderer.pmaVertexColors;
			else {
				var skeletonGraphic = skeletonComponent as SkeletonGraphic;
				if (skeletonGraphic != null)
					this.applyPMA = skeletonGraphic.SpineMeshGenerator.PremultiplyVertexColors;
			}

			Shader attachmentShader = applyPMA ? Shader.Find(DefaultPMAShader) : Shader.Find(DefaultStraightAlphaShader);

			loader = loader ?? new SpriteAttachmentLoader(sprite, attachmentShader, applyPMA);

			if (attachment == null)
				attachment = loader.NewRegionAttachment(null, sprite.name, "");

			skeletonComponent.Skeleton.FindSlot(slot).Attachment = attachment;

			if (!keepLoaderInMemory)
				loader = null;
		}
Exemplo n.º 8
0
		public static RegionAttachment ToRegionAttachment (this Sprite sprite, string shaderName = "Spine/Skeleton") {
			var loader = new SpriteAttachmentLoader(sprite, Shader.Find(shaderName));
			var att = loader.NewRegionAttachment(null, sprite.name, "");
			loader = null;
			return att;
		}
Exemplo n.º 9
0
        public static RegionAttachment ToRegionAttachment(this UnityEngine.Sprite sprite, Shader shader, bool applyPMA)
        {
            SpriteAttachmentLoader spriteAttachmentLoader = new SpriteAttachmentLoader(sprite, shader, applyPMA);

            return(spriteAttachmentLoader.NewRegionAttachment(null, sprite.name, string.Empty));
        }
Exemplo n.º 10
0
		public static RegionAttachment ToRegionAttachment (this Sprite sprite, Shader shader, bool applyPMA) {
			var loader = new SpriteAttachmentLoader(sprite, shader, applyPMA);
			var att = loader.NewRegionAttachment(null, sprite.name, "");
			loader = null;
			return att;
		}