public void CreateNewOutline(Rect rectOutline)
        {
            Rect rect = this.m_Selected.rect;

            if (rect.Contains(rectOutline.min) && rect.Contains(rectOutline.max))
            {
                this.RecordUndo();
                SpriteOutline spriteOutline = new SpriteOutline();
                Vector2       b             = new Vector2(0.5f * rect.width + rect.x, 0.5f * rect.height + rect.y);
                Rect          rect2         = new Rect(rectOutline);
                rect2.min = this.SnapPoint(rectOutline.min);
                rect2.max = this.SnapPoint(rectOutline.max);
                spriteOutline.Add(SpriteOutlineModule.CapPointToRect(new Vector2(rect2.xMin, rect2.yMin), rect) - b);
                spriteOutline.Add(SpriteOutlineModule.CapPointToRect(new Vector2(rect2.xMin, rect2.yMax), rect) - b);
                spriteOutline.Add(SpriteOutlineModule.CapPointToRect(new Vector2(rect2.xMax, rect2.yMax), rect) - b);
                spriteOutline.Add(SpriteOutlineModule.CapPointToRect(new Vector2(rect2.xMax, rect2.yMin), rect) - b);
                this.selectedShapeOutline.Add(spriteOutline);
                this.spriteEditorWindow.SetDataModified();
                this.shapeEditorDirty = true;
            }
        }
Beispiel #2
0
        public void CreateNewOutline(Rect rectOutline)
        {
            Rect rect = m_Selected.rect;

            if (rect.Contains(rectOutline.min) && rect.Contains(rectOutline.max))
            {
                RecordUndo();
                SpriteOutline so            = new SpriteOutline();
                Vector2       outlineOffset = new Vector2(0.5f * rect.width + rect.x, 0.5f * rect.height + rect.y);
                Rect          selectionRect = new Rect(rectOutline);
                selectionRect.min = SnapPoint(rectOutline.min);
                selectionRect.max = SnapPoint(rectOutline.max);
                so.Add(CapPointToRect(new Vector2(selectionRect.xMin, selectionRect.yMin), rect) - outlineOffset);
                so.Add(CapPointToRect(new Vector2(selectionRect.xMin, selectionRect.yMax), rect) - outlineOffset);
                so.Add(CapPointToRect(new Vector2(selectionRect.xMax, selectionRect.yMax), rect) - outlineOffset);
                so.Add(CapPointToRect(new Vector2(selectionRect.xMax, selectionRect.yMin), rect) - outlineOffset);
                selectedShapeOutline.Add(so);
                spriteEditorWindow.SetDataModified();
                shapeEditorDirty = true;
            }
        }
Beispiel #3
0
        protected static List <SpriteOutline> GenerateSpriteRectOutline(Rect rect, float detail, byte alphaTolerance, ITextureDataProvider textureProvider)
        {
            List <SpriteOutline> outline = new List <SpriteOutline>();
            var texture = textureProvider.GetReadableTexture2D();

            if (texture != null)
            {
                Vector2[][] paths;

                // we might have a texture that is capped because of max size or NPOT.
                // in that case, we need to convert values from capped space to actual texture space and back.
                int actualWidth = 0, actualHeight = 0;
                int cappedWidth, cappedHeight;
                textureProvider.GetTextureActualWidthAndHeight(out actualWidth, out actualHeight);
                cappedWidth  = texture.width;
                cappedHeight = texture.height;

                Vector2 scale      = new Vector2(cappedWidth / (float)actualWidth, cappedHeight / (float)actualHeight);
                Rect    spriteRect = rect;
                spriteRect.xMin *= scale.x;
                spriteRect.xMax *= scale.x;
                spriteRect.yMin *= scale.y;
                spriteRect.yMax *= scale.y;

                Sprites.SpriteUtility.GenerateOutline(texture, spriteRect, detail, alphaTolerance, true, out paths);

                Rect capRect = new Rect();
                capRect.size   = rect.size;
                capRect.center = Vector2.zero;
                for (int j = 0; j < paths.Length; ++j)
                {
                    SpriteOutline points = new SpriteOutline();
                    foreach (Vector2 v in paths[j])
                    {
                        points.Add(CapPointToRect(new Vector2(v.x / scale.x, v.y / scale.y), capRect));
                    }

                    outline.Add(points);
                }
            }
            return(outline);
        }
        protected static List <SpriteOutline> GenerateSpriteRectOutline(Rect rect, ITexture2D texture, float detail, byte alphaTolerance)
        {
            List <SpriteOutline> list = new List <SpriteOutline>();

            if (texture != null)
            {
                int num  = 0;
                int num2 = 0;
                UnityEditor.TextureImporter textureImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(texture)) as UnityEditor.TextureImporter;
                textureImporter.GetWidthAndHeight(ref num, ref num2);
                int     width  = texture.width;
                int     height = texture.height;
                Vector2 vector = new Vector2((float)width / (float)num, (float)height / (float)num2);
                Rect    rect2  = rect;
                rect2.xMin *= vector.x;
                rect2.xMax *= vector.x;
                rect2.yMin *= vector.y;
                rect2.yMax *= vector.y;
                Vector2[][] array;
                UnityEditor.Sprites.SpriteUtility.GenerateOutline(texture, rect2, detail, alphaTolerance, true, out array);
                Rect r = default(Rect);
                r.size   = rect.size;
                r.center = Vector2.zero;
                for (int i = 0; i < array.Length; i++)
                {
                    SpriteOutline spriteOutline = new SpriteOutline();
                    Vector2[]     array2        = array[i];
                    for (int j = 0; j < array2.Length; j++)
                    {
                        Vector2 vector2 = array2[j];
                        spriteOutline.Add(SpriteOutlineModule.CapPointToRect(new Vector2(vector2.x / vector.x, vector2.y / vector.y), r));
                    }
                    list.Add(spriteOutline);
                }
            }
            return(list);
        }