コード例 #1
0
 protected void HandlePivotHandle()
 {
     if (this.hasSelected)
     {
         EditorGUI.BeginChangeCheck();
         SpriteAlignment alignment          = this.selectedSpriteAlignment;
         Vector2         vector             = this.selectedSpritePivot;
         Rect            selectedSpriteRect = this.selectedSpriteRect;
         vector = SpriteFrameModuleBase.ApplySpriteAlignmentToPivot(vector, selectedSpriteRect, alignment);
         Vector2 vector2 = SpriteEditorHandles.PivotSlider(selectedSpriteRect, vector, SpriteFrameModuleBase.styles.pivotdot, SpriteFrameModuleBase.styles.pivotdotactive);
         if (EditorGUI.EndChangeCheck())
         {
             if (this.eventSystem.current.control)
             {
                 this.SnapPivot(vector2, out vector, out alignment);
             }
             else
             {
                 vector    = vector2;
                 alignment = SpriteAlignment.Custom;
             }
             this.SetSpritePivotAndAlignment(vector, alignment);
         }
     }
 }
コード例 #2
0
 public void ScaleSpriteRect(Rect r)
 {
     if (base.selected != null)
     {
         base.undoSystem.RegisterCompleteObjectUndo(this.m_RectsCache, "Scale sprite");
         base.selected.rect   = SpriteFrameModuleBase.ClampSpriteRect(r, (float)base.textureActualWidth, (float)base.textureActualHeight);
         base.selected.border = SpriteFrameModuleBase.ClampSpriteBorderToRect(base.selected.border, base.selected.rect);
         base.spriteEditor.SetDataModified();
     }
 }
コード例 #3
0
        protected static Vector4 ClampSpriteBorderToRect(Vector4 border, Rect rect)
        {
            Rect    rect2  = SpriteFrameModuleBase.FlipNegativeRect(rect);
            float   width  = rect2.width;
            float   height = rect2.height;
            Vector4 result = default(Vector4);

            result.x = (float)Mathf.RoundToInt(Mathf.Clamp(border.x, 0f, Mathf.Min(Mathf.Abs(width - border.z), width)));
            result.z = (float)Mathf.RoundToInt(Mathf.Clamp(border.z, 0f, Mathf.Min(Mathf.Abs(width - result.x), width)));
            result.y = (float)Mathf.RoundToInt(Mathf.Clamp(border.y, 0f, Mathf.Min(Mathf.Abs(height - border.w), height)));
            result.w = (float)Mathf.RoundToInt(Mathf.Clamp(border.w, 0f, Mathf.Min(Mathf.Abs(height - result.y), height)));
            return(result);
        }
コード例 #4
0
        public void TrimAlpha()
        {
            ITexture2D readableTexture2D = base.spriteEditor.GetReadableTexture2D();

            if (!(readableTexture2D == null))
            {
                Rect rect = base.selected.rect;
                int  num  = (int)rect.xMax;
                int  num2 = (int)rect.xMin;
                int  num3 = (int)rect.yMax;
                int  num4 = (int)rect.yMin;
                for (int i = (int)rect.yMin; i < (int)rect.yMax; i++)
                {
                    for (int j = (int)rect.xMin; j < (int)rect.xMax; j++)
                    {
                        if (this.PixelHasAlpha(j, i, readableTexture2D))
                        {
                            num  = Mathf.Min(num, j);
                            num2 = Mathf.Max(num2, j);
                            num3 = Mathf.Min(num3, i);
                            num4 = Mathf.Max(num4, i);
                        }
                    }
                }
                if (num > num2 || num3 > num4)
                {
                    rect = new Rect(0f, 0f, 0f, 0f);
                }
                else
                {
                    rect = new Rect((float)num, (float)num3, (float)(num2 - num + 1), (float)(num4 - num3 + 1));
                }
                if (rect.width <= 0f && rect.height <= 0f)
                {
                    this.m_RectsCache.RemoveRect(base.selected);
                    base.spriteEditor.SetDataModified();
                    base.selected = null;
                }
                else
                {
                    rect = SpriteFrameModuleBase.ClampSpriteRect(rect, (float)readableTexture2D.width, (float)readableTexture2D.height);
                    if (base.selected.rect != rect)
                    {
                        base.spriteEditor.SetDataModified();
                    }
                    base.selected.rect = rect;
                }
            }
        }
コード例 #5
0
        private static Vector2 ApplySpriteAlignmentToPivot(Vector2 pivot, Rect rect, SpriteAlignment alignment)
        {
            Vector2 result;

            if (alignment != SpriteAlignment.Custom)
            {
                Vector2[] snapPointsArray = SpriteFrameModuleBase.GetSnapPointsArray(rect);
                Vector2   texturePos      = snapPointsArray[(int)alignment];
                result = SpriteFrameModuleBase.ConvertFromTextureToNormalizedSpace(texturePos, rect);
            }
            else
            {
                result = pivot;
            }
            return(result);
        }
コード例 #6
0
        protected void SnapPivot(Vector2 pivot, out Vector2 outPivot, out SpriteAlignment outAlignment)
        {
            Rect    selectedSpriteRect = this.selectedSpriteRect;
            Vector2 a = new Vector2(selectedSpriteRect.xMin + selectedSpriteRect.width * pivot.x, selectedSpriteRect.yMin + selectedSpriteRect.height * pivot.y);

            Vector2[]       snapPointsArray = SpriteFrameModuleBase.GetSnapPointsArray(selectedSpriteRect);
            SpriteAlignment spriteAlignment = SpriteAlignment.Custom;
            float           num             = 3.40282347E+38f;

            for (int i = 0; i < snapPointsArray.Length; i++)
            {
                float num2 = (a - snapPointsArray[i]).magnitude * this.m_Zoom;
                if (num2 < num)
                {
                    spriteAlignment = (SpriteAlignment)i;
                    num             = num2;
                }
            }
            outAlignment = spriteAlignment;
            outPivot     = SpriteFrameModuleBase.ConvertFromTextureToNormalizedSpace(snapPointsArray[(int)spriteAlignment], selectedSpriteRect);
        }
コード例 #7
0
 public void CreateSprite(Rect rect)
 {
     rect = SpriteFrameModuleBase.ClampSpriteRect(rect, (float)base.textureActualWidth, (float)base.textureActualHeight);
     base.undoSystem.RegisterCompleteObjectUndo(this.m_RectsCache, "Create sprite");
     base.selected = this.AddSpriteWithUniqueName(rect, 0, Vector2.zero, 254, 0.25f, 0);
 }