Example #1
0
        /// <summary>
        /// Changes the user interface frame.
        /// </summary>
        /// <param name="uf">Uf.</param>
        /// <param name="texture">Texture.</param>
        /// <param name="mat">Mat.</param>
        public void ChangeUIFrame(UIFrame uf, Texture texture, Material mat = null)
        {
            if (!uf || !texture)
            {
                return;
            }

            //new textureframe
            TextureFrame frame = new TextureFrame();

            frame.atlasTextureSize = new Vector2(texture.width, texture.height);
            frame.uiMaterial       = mat == null ? uf.material : mat;
            frame.rect.x           = 0f;
            frame.rect.y           = 0f;
            frame.rect.width       = texture.width;
            frame.rect.height      = texture.height;
            frame.frameSize        = new Rect(0, 0, texture.width, texture.height);
            frame.isRotated        = false;
            frame.rect             = uf.frame.frameSize;
            if (!uf.isCreatedMesh)
            {
                uf.CreateQuad();
            }
            uf.frame = frame;
            if (mat)
            {
                uf.material = mat;
            }
            //change texture
            uf.texture = texture;
        }
Example #2
0
        static void ShowUIFrame(TextureFrame frame, SpineData.SkinAttachment attachmentData, Transform slot, Transform skinParent, SpineArmatureEditor armatureEditor, SpineData.SlotData slotData)
        {
            GameObject go       = new GameObject();
            UIFrame    newFrame = go.AddComponent <UIFrame>();

            newFrame.raycastTarget = false;
            newFrame.GetComponent <Graphic>().raycastTarget = false;
            newFrame.CreateQuad();
            newFrame.frame = frame;
            newFrame.name  = attachmentData.textureName;
            newFrame.transform.SetParent(skinParent);

            Vector3 localPos = Vector3.zero;

            localPos.x = attachmentData.x;
            localPos.y = attachmentData.y;
            go.transform.localPosition = localPos;

            Vector3 localSc = Vector3.one;

            localSc.x = attachmentData.scaleX;
            localSc.y = attachmentData.scaleY;

            if (newFrame.frame.isRotated)
            {
                if (attachmentData.width > 0)
                {
                    localSc.x *= attachmentData.width / frame.rect.height;
                }
                if (attachmentData.height > 0)
                {
                    localSc.y *= attachmentData.height / frame.rect.width;
                }
            }
            else
            {
                if (attachmentData.width > 0)
                {
                    localSc.x *= attachmentData.width / frame.rect.width;
                }
                if (attachmentData.height > 0)
                {
                    localSc.y *= attachmentData.height / frame.rect.height;
                }
            }
            newFrame.transform.localScale = localSc;
            newFrame.color = attachmentData.color;
            newFrame.transform.localRotation = Quaternion.Euler(0, 0, attachmentData.rotation);

            if (armatureEditor.genImgCollider)
            {
                BoxCollider2D collider = newFrame.gameObject.AddComponent <BoxCollider2D>();
                if (newFrame.frame.isRotated)
                {
                    collider.size = new Vector2(newFrame.frame.rect.size.y, newFrame.frame.rect.size.x) * armatureEditor.unit;

                    Vector2 center = new Vector2(
                        -newFrame.frame.frameSize.width / 2 - newFrame.frame.frameSize.x + newFrame.frame.rect.width / 2,
                        newFrame.frame.frameSize.height / 2 + newFrame.frame.frameSize.y - newFrame.frame.rect.height / 2);
                    collider.offset = center * armatureEditor.unit;
                }
                else
                {
                    collider.size = newFrame.frame.rect.size * armatureEditor.unit;

                    Vector2 center = new Vector2(
                        -newFrame.frame.frameSize.width / 2 - newFrame.frame.frameSize.x + newFrame.frame.rect.width / 2,
                        newFrame.frame.frameSize.height / 2 + newFrame.frame.frameSize.y - newFrame.frame.rect.height / 2);
                    collider.offset = center * armatureEditor.unit;
                }
            }
            newFrame.UpdateAll();
        }