Exemple #1
0
 public void SetSpritePivotAndAlignment(Vector2 pivot, SpriteAlignment alignment)
 {
     undoSystem.RegisterCompleteObjectUndo(m_RectsCache, "Change Sprite Pivot");
     spriteEditor.SetDataModified();
     selected.alignment = alignment;
     selected.pivot     = SpriteEditorUtility.GetPivotValue(alignment, pivot);
 }
 private void DrawGizmos()
 {
     if (eventSystem.current.type != EventType.Repaint)
     {
         return;
     }
     for (int i = 0; i < spriteCount; i++)
     {
         List <Vector2[]> outline = GetSpriteOutlineAt(i);
         Vector2          offset  = GetSpriteRectAt(i).size * 0.5f;
         if (outline.Count > 0)
         {
             SpriteEditorUtility.BeginLines(new Color(0.75f, 0.75f, 0.75f, 0.75f));
             for (int j = 0; j < outline.Count; ++j)
             {
                 for (int k = 0, last = outline[j].Length - 1; k < outline[j].Length; last = k, ++k)
                 {
                     SpriteEditorUtility.DrawLine(outline[j][last] + offset, outline[j][k] + offset);
                 }
             }
             SpriteEditorUtility.EndLines();
         }
     }
     DrawSpriteRectGizmos();
 }
Exemple #3
0
 private void DrawGizmos()
 {
     if (base.eventSystem.current.type == EventType.Repaint)
     {
         for (int i = 0; i < base.spriteCount; i++)
         {
             List <SpriteOutline> spriteOutlineAt = base.GetSpriteOutlineAt(i);
             Vector2 b = base.GetSpriteRectAt(i).size * 0.5f;
             if (spriteOutlineAt.Count > 0)
             {
                 SpriteEditorUtility.BeginLines(new Color(0.75f, 0.75f, 0.75f, 0.75f));
                 for (int j = 0; j < spriteOutlineAt.Count; j++)
                 {
                     int k     = 0;
                     int index = spriteOutlineAt[j].Count - 1;
                     while (k < spriteOutlineAt[j].Count)
                     {
                         SpriteEditorUtility.DrawLine(spriteOutlineAt[j][index] + b, spriteOutlineAt[j][k] + b);
                         index = k;
                         k++;
                     }
                 }
                 SpriteEditorUtility.EndLines();
             }
         }
         base.DrawSpriteRectGizmos();
     }
 }
        private void DoBorderFields()
        {
            EditorGUI.BeginChangeCheck();

            Vector4 oldBorder = selectedSpriteBorder;
            int     x         = Mathf.RoundToInt(oldBorder.x);
            int     y         = Mathf.RoundToInt(oldBorder.y);
            int     z         = Mathf.RoundToInt(oldBorder.z);
            int     w         = Mathf.RoundToInt(oldBorder.w);

            SpriteEditorUtility.FourIntFields(new Vector2(kInspectorWidth - kInspectorWindowMargin, EditorGUI.kSingleLineHeight * 2f + EditorGUI.kVerticalSpacingMultiField),
                                              styles.borderLabel,
                                              styles.lLabel,
                                              styles.tLabel,
                                              styles.rLabel,
                                              styles.bLabel,
                                              ref x, ref w, ref z, ref y);

            Vector4 newBorder = new Vector4(x, y, z, w);

            if (EditorGUI.EndChangeCheck())
            {
                selectedSpriteBorder = newBorder;
            }
        }
Exemple #5
0
        public static void DrawPreview(Rect r, Sprite frame, Material spriteRendererMaterial, bool isPolygon)
        {
            if (frame == null)
            {
                return;
            }

            float zoomLevel  = Mathf.Min(r.width / frame.rect.width, r.height / frame.rect.height);
            Rect  wantedRect = new Rect(r.x, r.y, frame.rect.width * zoomLevel, frame.rect.height * zoomLevel);

            wantedRect.center = r.center;

            Texture2D previewTexture = BuildPreviewTexture((int)wantedRect.width, (int)wantedRect.height, frame, spriteRendererMaterial, isPolygon);

            EditorGUI.DrawTextureTransparent(wantedRect, previewTexture, ScaleMode.ScaleToFit);

            var border = frame.border;

            border *= zoomLevel;
            if (!Mathf.Approximately(border.sqrMagnitude, 0))
            {
                SpriteEditorUtility.BeginLines(new Color(0f, 1f, 0f, 0.7f));
                //TODO: this
                //SpriteEditorUtility.DrawBorder (wantedRect, border);
                SpriteEditorUtility.EndLines();
            }

            DestroyImmediate(previewTexture);
        }
 internal SpriteDataExt(SerializedProperty sp)
 {
     rect               = sp.FindPropertyRelative("m_Rect").rectValue;
     border             = sp.FindPropertyRelative("m_Border").vector4Value;
     name               = sp.FindPropertyRelative("m_Name").stringValue;
     alignment          = (SpriteAlignment)sp.FindPropertyRelative("m_Alignment").intValue;
     pivot              = SpriteEditorUtility.GetPivotValue(alignment, sp.FindPropertyRelative("m_Pivot").vector2Value);
     tessellationDetail = sp.FindPropertyRelative("m_TessellationDetail").floatValue;
     spriteID           = new GUID(sp.FindPropertyRelative("m_SpriteID").stringValue);
 }
Exemple #7
0
 public void Load(SerializedProperty sp)
 {
     base.rect               = sp.FindPropertyRelative("m_Rect").rectValue;
     base.border             = sp.FindPropertyRelative("m_Border").vector4Value;
     base.name               = sp.FindPropertyRelative("m_Name").stringValue;
     base.alignment          = (SpriteAlignment)sp.FindPropertyRelative("m_Alignment").intValue;
     base.pivot              = SpriteEditorUtility.GetPivotValue(base.alignment, sp.FindPropertyRelative("m_Pivot").vector2Value);
     this.tessellationDetail = sp.FindPropertyRelative("m_TessellationDetail").floatValue;
     base.spriteID           = new GUID(sp.FindPropertyRelative("m_SpriteID").stringValue);
 }
Exemple #8
0
        public void LoadFromSerializedProperty(SerializedProperty sp)
        {
            this.rect               = sp.FindPropertyRelative("m_Rect").rectValue;
            this.border             = sp.FindPropertyRelative("m_Border").vector4Value;
            this.name               = sp.FindPropertyRelative("m_Name").stringValue;
            this.alignment          = (SpriteAlignment)sp.FindPropertyRelative("m_Alignment").intValue;
            this.pivot              = SpriteEditorUtility.GetPivotValue(this.alignment, sp.FindPropertyRelative("m_Pivot").vector2Value);
            this.tessellationDetail = sp.FindPropertyRelative("m_TessellationDetail").floatValue;
            SerializedProperty outlineSP = sp.FindPropertyRelative("m_Outline");

            this.outline = SpriteRect.AcquireOutline(outlineSP);
        }
 private void DrawGizmos()
 {
     if (this.eventSystem.current.type == EventType.Repaint)
     {
         SpriteRect selectedSpriteRect = this.spriteEditorWindow.selectedSpriteRect;
         if (selectedSpriteRect != null)
         {
             SpriteEditorUtility.BeginLines(this.styles.spriteBorderColor);
             SpriteEditorUtility.DrawBox(selectedSpriteRect.rect);
             SpriteEditorUtility.EndLines();
         }
     }
 }
 private void HandleDragging()
 {
     if (base.hasSelected && !base.MouseOnTopOfInspector())
     {
         Rect clamp = new Rect(0f, 0f, (float)base.textureActualWidth, (float)base.textureActualHeight);
         EditorGUI.BeginChangeCheck();
         Rect selectedSpriteRect  = base.selectedSpriteRect;
         Rect selectedSpriteRect2 = SpriteEditorUtility.ClampedRect(SpriteEditorUtility.RoundedRect(SpriteEditorHandles.SliderRect(selectedSpriteRect)), clamp, true);
         if (EditorGUI.EndChangeCheck())
         {
             base.selectedSpriteRect = selectedSpriteRect2;
         }
     }
 }
Exemple #11
0
        protected void DrawTexturespaceBackground()
        {
            float   num  = Mathf.Max(this.maxRect.width, this.maxRect.height);
            Vector2 b    = new Vector2(this.maxRect.xMin, this.maxRect.yMin);
            float   num2 = num * 0.5f;
            float   a    = (!EditorGUIUtility.isProSkin) ? 0.08f : 0.15f;
            float   num3 = 8f;

            SpriteEditorUtility.BeginLines(new Color(0f, 0f, 0f, a));
            for (float num4 = 0f; num4 <= num; num4 += num3)
            {
                SpriteEditorUtility.DrawLine(new Vector2(-num2 + num4, num2 + num4) + b, new Vector2(num2 + num4, -num2 + num4) + b);
            }
            SpriteEditorUtility.EndLines();
        }
Exemple #12
0
        protected void DrawTexturespaceBackground()
        {
            float   num    = Mathf.Max(this.maxRect.width, this.maxRect.height);
            Vector2 vector = new Vector2(this.maxRect.xMin, this.maxRect.yMin);
            float   num2   = num * 0.5f;
            float   a      = !EditorGUIUtility.isProSkin ? 0.08f : 0.15f;
            float   num4   = 8f;

            SpriteEditorUtility.BeginLines(new Color(0f, 0f, 0f, a));
            for (float i = 0f; i <= num; i += num4)
            {
                SpriteEditorUtility.DrawLine((Vector3)(new Vector2(-num2 + i, num2 + i) + vector), (Vector3)(new Vector2(num2 + i, -num2 + i) + vector));
            }
            SpriteEditorUtility.EndLines();
        }
Exemple #13
0
 protected override void DrawGizmos()
 {
     if (!((UnityEngine.Object) this.m_SelectedSprite != (UnityEngine.Object)null) || !((UnityEngine.Object) this.m_Texture != (UnityEngine.Object)null))
     {
         return;
     }
     Vector2[]           spriteUvs   = SpriteUtility.GetSpriteUVs(this.m_SelectedSprite, true);
     PackerWindow.Edge[] uniqueEdges = this.FindUniqueEdges(this.m_SelectedSprite.triangles);
     SpriteEditorUtility.BeginLines(new Color(0.3921f, 0.5843f, 0.9294f, 0.75f));
     foreach (PackerWindow.Edge edge in uniqueEdges)
     {
         this.DrawLineUtility(spriteUvs[(int)edge.v0], spriteUvs[(int)edge.v1]);
     }
     SpriteEditorUtility.EndLines();
 }
Exemple #14
0
        private void DoPositionField()
        {
            EditorGUI.BeginChangeCheck();
            Rect selectedSpriteRect = this.selectedSpriteRect;
            int  num  = Mathf.RoundToInt(selectedSpriteRect.x);
            int  num2 = Mathf.RoundToInt(selectedSpriteRect.y);
            int  num3 = Mathf.RoundToInt(selectedSpriteRect.width);
            int  num4 = Mathf.RoundToInt(selectedSpriteRect.height);

            SpriteEditorUtility.FourIntFields(new Vector2(322f, 32f), SpriteFrameModuleBase.styles.positionLabel, SpriteFrameModuleBase.styles.xLabel, SpriteFrameModuleBase.styles.yLabel, SpriteFrameModuleBase.styles.wLabel, SpriteFrameModuleBase.styles.hLabel, ref num, ref num2, ref num3, ref num4);
            if (EditorGUI.EndChangeCheck())
            {
                this.selectedSpriteRect = new Rect((float)num, (float)num2, (float)num3, (float)num4);
            }
        }
 protected override void DrawGizmos()
 {
     if ((this.m_SelectedSprite != null) && (base.m_Texture != null))
     {
         Vector2[] spriteUVs = UnityEditor.Sprites.SpriteUtility.GetSpriteUVs(this.m_SelectedSprite, true);
         ushort[]  triangles = this.m_SelectedSprite.triangles;
         Edge[]    edgeArray = this.FindUniqueEdges(triangles);
         SpriteEditorUtility.BeginLines(new Color(0.3921f, 0.5843f, 0.9294f, 0.75f));
         foreach (Edge edge in edgeArray)
         {
             this.DrawLineUtility(spriteUVs[edge.v0], spriteUVs[edge.v1]);
         }
         SpriteEditorUtility.EndLines();
     }
 }
        protected void DrawTexturespaceBackground()
        {
            float   size   = Mathf.Max(maxRect.width, maxRect.height);
            Vector2 offset = new Vector2(maxRect.xMin, maxRect.yMin);

            float halfSize = size * .5f;
            float alpha    = EditorGUIUtility.isProSkin ? 0.15f : 0.08f;
            float gridSize = 8f;

            SpriteEditorUtility.BeginLines(new Color(0f, 0f, 0f, alpha));
            for (float v = 0; v <= size; v += gridSize)
            {
                SpriteEditorUtility.DrawLine(new Vector2(-halfSize + v, halfSize + v) + offset, new Vector2(halfSize + v, -halfSize + v) + offset);
            }
            SpriteEditorUtility.EndLines();
        }
        protected override void DrawGizmos()
        {
            if (m_SelectedSprite != null && m_Texture != null)
            {
                Vector2[] uvs         = SpriteUtility.GetSpriteUVs(m_SelectedSprite, true);
                UInt16[]  indices     = m_SelectedSprite.triangles;
                Edge[]    uniqueEdges = FindUniqueEdges(indices);                            // Assumes that our mesh has no duplicate vertices

                SpriteEditorUtility.BeginLines(new Color(0.3921f, 0.5843f, 0.9294f, 0.75f)); // Cornflower blue :)
                foreach (Edge e in uniqueEdges)
                {
                    DrawLineUtility(uvs[e.v0], uvs[e.v1]);
                }
                SpriteEditorUtility.EndLines();
            }
        }
Exemple #18
0
        private void HandleDragging()
        {
            if (hasSelected && !MouseOnTopOfInspector())
            {
                Rect textureBounds = new Rect(0, 0, textureActualWidth, textureActualHeight);
                EditorGUI.BeginChangeCheck();

                Rect oldRect = selectedSpriteRect;
                Rect newRect = SpriteEditorUtility.ClampedRect(SpriteEditorUtility.RoundedRect(SpriteEditorHandles.SliderRect(oldRect)), textureBounds, true);

                if (EditorGUI.EndChangeCheck())
                {
                    selectedSpriteRect = newRect;
                }
            }
        }
Exemple #19
0
 protected override void DoTextureGUIExtras()
 {
     this.HandleFrameSelected();
     if (this.m_EventSystem.current.type == EventType.Repaint)
     {
         SpriteEditorUtility.BeginLines(new Color(1f, 1f, 1f, 0.5f));
         for (int i = 0; i < this.m_RectsCache.Count; i++)
         {
             if (this.m_RectsCache.RectAt(i) != this.selectedSpriteRect)
             {
                 SpriteEditorUtility.DrawBox(this.m_RectsCache.RectAt(i).rect);
             }
         }
         SpriteEditorUtility.EndLines();
     }
     this.m_CurrentModule.DoTextureGUI();
 }
Exemple #20
0
        private void DoBorderFields()
        {
            EditorGUI.BeginChangeCheck();
            Vector4 selectedSpriteBorder = this.selectedSpriteBorder;
            int     num  = Mathf.RoundToInt(selectedSpriteBorder.x);
            int     num2 = Mathf.RoundToInt(selectedSpriteBorder.y);
            int     num3 = Mathf.RoundToInt(selectedSpriteBorder.z);
            int     num4 = Mathf.RoundToInt(selectedSpriteBorder.w);

            SpriteEditorUtility.FourIntFields(new Vector2(322f, 32f), SpriteFrameModuleBase.styles.borderLabel, SpriteFrameModuleBase.styles.lLabel, SpriteFrameModuleBase.styles.tLabel, SpriteFrameModuleBase.styles.rLabel, SpriteFrameModuleBase.styles.bLabel, ref num, ref num4, ref num3, ref num2);
            Vector4 selectedSpriteBorder2 = new Vector4((float)num, (float)num2, (float)num3, (float)num4);

            if (EditorGUI.EndChangeCheck())
            {
                this.selectedSpriteBorder = selectedSpriteBorder2;
            }
        }
 protected override void DrawGizmos()
 {
     if (this.m_SelectedSprite != null && this.m_Texture != null)
     {
         Vector2[]           spriteUVs = SpriteUtility.GetSpriteUVs(this.m_SelectedSprite, true);
         ushort[]            triangles = this.m_SelectedSprite.triangles;
         PackerWindow.Edge[] array     = this.FindUniqueEdges(triangles);
         SpriteEditorUtility.BeginLines(new Color(0.3921f, 0.5843f, 0.9294f, 0.75f));
         PackerWindow.Edge[] array2 = array;
         for (int i = 0; i < array2.Length; i++)
         {
             PackerWindow.Edge edge = array2[i];
             this.DrawLineUtility(spriteUVs[(int)edge.v0], spriteUVs[(int)edge.v1]);
         }
         SpriteEditorUtility.EndLines();
     }
 }
Exemple #22
0
        protected static Rect ClampSpriteRect(Rect rect, float maxX, float maxY)
        {
            Rect rect2 = default(Rect);

            rect2.xMin = Mathf.Clamp(rect.xMin, 0f, maxX - 1f);
            rect2.yMin = Mathf.Clamp(rect.yMin, 0f, maxY - 1f);
            rect2.xMax = Mathf.Clamp(rect.xMax, 1f, maxX);
            rect2.yMax = Mathf.Clamp(rect.yMax, 1f, maxY);
            if (Mathf.RoundToInt(rect2.width) == 0)
            {
                rect2.width = 1f;
            }
            if (Mathf.RoundToInt(rect2.height) == 0)
            {
                rect2.height = 1f;
            }
            return(SpriteEditorUtility.RoundedRect(rect2));
        }
Exemple #23
0
 public static void DrawPreview(Rect r, Sprite frame, Material spriteRendererMaterial, bool isPolygon)
 {
     if (!(frame == null))
     {
         float num      = Mathf.Min(r.width / frame.rect.width, r.height / frame.rect.height);
         Rect  position = new Rect(r.x, r.y, frame.rect.width * num, frame.rect.height * num);
         position.center = r.center;
         Texture2D texture2D = SpriteInspector.BuildPreviewTexture((int)position.width, (int)position.height, frame, spriteRendererMaterial, isPolygon);
         EditorGUI.DrawTextureTransparent(position, texture2D, ScaleMode.ScaleToFit);
         Vector4 border = frame.border;
         if (!Mathf.Approximately((border * num).sqrMagnitude, 0f))
         {
             SpriteEditorUtility.BeginLines(new Color(0f, 1f, 0f, 0.7f));
             SpriteEditorUtility.EndLines();
         }
         UnityEngine.Object.DestroyImmediate(texture2D);
     }
 }
        protected void DrawTexturespaceBackground()
        {
            float   num1    = Mathf.Max(this.maxRect.width, this.maxRect.height);
            Vector2 vector2 = new Vector2(this.maxRect.xMin, this.maxRect.yMin);
            float   num2    = num1 * 0.5f;
            float   a       = !EditorGUIUtility.isProSkin ? 0.08f : 0.15f;
            float   num3    = 8f;

            SpriteEditorUtility.BeginLines(new Color(0.0f, 0.0f, 0.0f, a));
            float num4 = 0.0f;

            while ((double)num4 <= (double)num1)
            {
                SpriteEditorUtility.DrawLine((Vector3)(new Vector2(-num2 + num4, num2 + num4) + vector2), (Vector3)(new Vector2(num2 + num4, -num2 + num4) + vector2));
                num4 += num3;
            }
            SpriteEditorUtility.EndLines();
        }
Exemple #25
0
        public void Load(SerializedObject so)
        {
            TextureImporter textureImporter = so.targetObject as TextureImporter;
            Texture         texture         = AssetDatabase.LoadAssetAtPath <Texture>(textureImporter.assetPath);

            base.name               = texture.name;
            base.alignment          = (SpriteAlignment)so.FindProperty("m_Alignment").intValue;
            base.border             = textureImporter.spriteBorder;
            base.pivot              = SpriteEditorUtility.GetPivotValue(base.alignment, textureImporter.spritePivot);
            this.tessellationDetail = so.FindProperty("m_SpriteTessellationDetail").floatValue;
            int num  = 0;
            int num2 = 0;

            textureImporter.GetWidthAndHeight(ref num, ref num2);
            base.rect = new Rect(0f, 0f, (float)num, (float)num2);
            SerializedProperty serializedProperty = so.FindProperty("m_SpriteSheet.m_SpriteID");

            base.spriteID = new GUID(serializedProperty.stringValue);
        }
Exemple #26
0
 protected override void DoTextureGUIExtras()
 {
     this.HandleFrameSelected();
     if (this.m_EventSystem.current.type == EventType.Repaint)
     {
         SpriteEditorUtility.BeginLines(new Color(1f, 1f, 1f, 0.5f));
         SpriteRect expr_42 = this.selectedSpriteRect;
         GUID?      gUID    = (expr_42 != null) ? new GUID?(expr_42.spriteID) : null;
         for (int i = 0; i < this.m_RectsCache.Count; i++)
         {
             if (this.m_RectsCache[i].spriteID != gUID)
             {
                 SpriteEditorUtility.DrawBox(this.m_RectsCache[i].rect);
             }
         }
         SpriteEditorUtility.EndLines();
     }
     this.m_CurrentModule.DoMainGUI();
 }
 private void RefreshRects()
 {
     if (this.m_RectsCache)
     {
         this.m_RectsCache.ClearAll();
         Undo.ClearUndo(this.m_RectsCache);
         UnityEngine.Object.DestroyImmediate(this.m_RectsCache);
     }
     this.m_RectsCache = ScriptableObject.CreateInstance <SpriteRectCache>();
     if (this.m_TextureImporterSprites != null)
     {
         if (this.multipleSprites)
         {
             for (int i = 0; i < this.m_TextureImporterSprites.arraySize; i++)
             {
                 SpriteRect spriteRect = new SpriteRect();
                 spriteRect.LoadFromSerializedProperty(this.m_TextureImporterSprites.GetArrayElementAtIndex(i));
                 this.m_RectsCache.AddRect(spriteRect);
                 EditorUtility.DisplayProgressBar(SpriteEditorWindow.SpriteEditorWindowStyles.loadProgressTitle.text, string.Format(SpriteEditorWindow.SpriteEditorWindowStyles.loadContentText.text, i, this.m_TextureImporterSprites.arraySize), (float)i / (float)this.m_TextureImporterSprites.arraySize);
             }
         }
         else if (this.validSprite)
         {
             SpriteRect spriteRect2 = new SpriteRect();
             spriteRect2.rect               = new Rect(0f, 0f, (float)this.m_Texture.width, (float)this.m_Texture.height);
             spriteRect2.name               = this.m_OriginalTexture.name;
             spriteRect2.alignment          = (SpriteAlignment)this.m_TextureImporterSO.FindProperty("m_Alignment").intValue;
             spriteRect2.border             = this.m_TextureImporter.spriteBorder;
             spriteRect2.pivot              = SpriteEditorUtility.GetPivotValue(spriteRect2.alignment, this.m_TextureImporter.spritePivot);
             spriteRect2.tessellationDetail = this.m_TextureImporterSO.FindProperty("m_SpriteTessellationDetail").floatValue;
             SerializedProperty outlineSP = this.m_TextureImporterSO.FindProperty("m_SpriteSheet.m_Outline");
             spriteRect2.outline = SpriteRect.AcquireOutline(outlineSP);
             SerializedProperty outlineSP2 = this.m_TextureImporterSO.FindProperty("m_SpriteSheet.m_PhysicsShape");
             spriteRect2.physicsShape = SpriteRect.AcquireOutline(outlineSP2);
             this.m_RectsCache.AddRect(spriteRect2);
         }
         EditorUtility.ClearProgressBar();
         if (this.m_RectsCache.Count > 0)
         {
             this.selectedSpriteRect = this.m_RectsCache.RectAt(0);
         }
     }
 }
Exemple #28
0
        protected void DrawSpriteRectGizmos()
        {
            if (this.eventSystem.current.type == EventType.Repaint)
            {
                SpriteEditorUtility.BeginLines(new Color(0f, 1f, 0f, 0.7f));
                int num = this.CurrentSelectedSpriteIndex();
                int i   = 0;
                while (i < this.spriteCount)
                {
                    Vector4 spriteBorderAt = this.GetSpriteBorderAt(i);
                    if (num == i || this.m_GizmoMode == SpriteFrameModuleBase.GizmoMode.BorderEditing)
                    {
                        goto IL_80;
                    }
                    if (!Mathf.Approximately(spriteBorderAt.sqrMagnitude, 0f))
                    {
                        goto IL_80;
                    }
IL_175:
                    i++;
                    continue;
IL_80:
                    Rect spriteRectAt = this.GetSpriteRectAt(i);
                    SpriteEditorUtility.DrawLine(new Vector3(spriteRectAt.xMin + spriteBorderAt.x, spriteRectAt.yMin), new Vector3(spriteRectAt.xMin + spriteBorderAt.x, spriteRectAt.yMax));
                    SpriteEditorUtility.DrawLine(new Vector3(spriteRectAt.xMax - spriteBorderAt.z, spriteRectAt.yMin), new Vector3(spriteRectAt.xMax - spriteBorderAt.z, spriteRectAt.yMax));
                    SpriteEditorUtility.DrawLine(new Vector3(spriteRectAt.xMin, spriteRectAt.yMin + spriteBorderAt.y), new Vector3(spriteRectAt.xMax, spriteRectAt.yMin + spriteBorderAt.y));
                    SpriteEditorUtility.DrawLine(new Vector3(spriteRectAt.xMin, spriteRectAt.yMax - spriteBorderAt.w), new Vector3(spriteRectAt.xMax, spriteRectAt.yMax - spriteBorderAt.w));
                    goto IL_175;
                }
                SpriteEditorUtility.EndLines();
                if (this.ShouldShowRectScaling())
                {
                    Rect selectedSpriteRect = this.selectedSpriteRect;
                    SpriteEditorUtility.BeginLines(new Color(0f, 0.1f, 0.3f, 0.25f));
                    SpriteEditorUtility.DrawBox(new Rect(selectedSpriteRect.xMin + 1f / this.m_Zoom, selectedSpriteRect.yMin + 1f / this.m_Zoom, selectedSpriteRect.width, selectedSpriteRect.height));
                    SpriteEditorUtility.EndLines();
                    SpriteEditorUtility.BeginLines(new Color(0.25f, 0.5f, 1f, 0.75f));
                    SpriteEditorUtility.DrawBox(selectedSpriteRect);
                    SpriteEditorUtility.EndLines();
                }
            }
        }
Exemple #29
0
        protected void DrawSpriteRectGizmos()
        {
            if (eventSystem.current.type != EventType.Repaint)
            {
                return;
            }

            SpriteEditorUtility.BeginLines(new Color(0f, 1f, 0f, 0.7f));
            int currentSelectedSpriteIndex = CurrentSelectedSpriteIndex();

            for (int i = 0; i < spriteCount; i++)
            {
                Vector4 border = GetSpriteBorderAt(i);
                if (currentSelectedSpriteIndex != i && m_GizmoMode != GizmoMode.BorderEditing)
                {
                    if (Mathf.Approximately(border.sqrMagnitude, 0))
                    {
                        continue;
                    }
                }


                var rect = GetSpriteRectAt(i);
                SpriteEditorUtility.DrawLine(new Vector3(rect.xMin + border.x, rect.yMin), new Vector3(rect.xMin + border.x, rect.yMax));
                SpriteEditorUtility.DrawLine(new Vector3(rect.xMax - border.z, rect.yMin), new Vector3(rect.xMax - border.z, rect.yMax));

                SpriteEditorUtility.DrawLine(new Vector3(rect.xMin, rect.yMin + border.y), new Vector3(rect.xMax, rect.yMin + border.y));
                SpriteEditorUtility.DrawLine(new Vector3(rect.xMin, rect.yMax - border.w), new Vector3(rect.xMax, rect.yMax - border.w));
            }
            SpriteEditorUtility.EndLines();

            if (ShouldShowRectScaling())
            {
                Rect r = selectedSpriteRect;
                SpriteEditorUtility.BeginLines(new Color(0f, 0.1f, 0.3f, 0.25f));
                SpriteEditorUtility.DrawBox(new Rect(r.xMin + 1f / m_Zoom, r.yMin + 1f / m_Zoom, r.width, r.height));
                SpriteEditorUtility.EndLines();
                SpriteEditorUtility.BeginLines(new Color(0.25f, 0.5f, 1f, 0.75f));
                SpriteEditorUtility.DrawBox(r);
                SpriteEditorUtility.EndLines();
            }
        }
Exemple #30
0
 public static void DrawPreview(Rect r, Sprite frame, Material spriteRendererMaterial)
 {
     if (frame != null)
     {
         float num      = Mathf.Min((float)(r.width / frame.rect.width), (float)(r.height / frame.rect.height));
         Rect  position = new Rect(r.x, r.y, frame.rect.width * num, frame.rect.height * num)
         {
             center = r.center
         };
         Texture2D image = BuildPreviewTexture((int)position.width, (int)position.height, frame, spriteRendererMaterial);
         EditorGUI.DrawTextureTransparent(position, image, ScaleMode.ScaleToFit);
         Vector4 vector = (Vector4)(frame.border * num);
         if (!Mathf.Approximately(vector.sqrMagnitude, 0f))
         {
             SpriteEditorUtility.BeginLines(new Color(0f, 1f, 0f, 0.7f));
             SpriteEditorUtility.EndLines();
         }
         UnityEngine.Object.DestroyImmediate(image);
     }
 }