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(); } }
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; } } }
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); }