exAtlasInfo.Element.Width C# (CSharp) Method

Width() public method

public Width ( ) : int
return int
        public int Width()
        {
            if ( rotated )
                return (int)trimRect.height;
            return (int)trimRect.width;
        }

Usage Example

Example #1
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    void AtlasElementField(Rect _atlasRect, exAtlasInfo _atlasInfo, exAtlasInfo.Element _el)
    {
        Color oldBGColor = GUI.backgroundColor;
        Rect  srcRect;
        Rect  rect = new Rect(_el.coord[0] * _atlasInfo.scale,
                              _el.coord[1] * _atlasInfo.scale,
                              _el.Width() * _atlasInfo.scale,
                              _el.Height() * _atlasInfo.scale);
        bool selected = selectedElements.IndexOf(_el) != -1;

        // ========================================================
        // draw the sprite background
        // ========================================================

        GUI.BeginGroup(_atlasRect);
        GUI.color = _el.atlasInfo.elementBgColor;
        GUI.DrawTexture(rect, exEditorHelper.WhiteTexture());
        GUI.color = oldBGColor;
        GUI.EndGroup();


        // ========================================================
        // draw the texture
        // ========================================================

        // process rotate
        Matrix4x4 oldMat = GUI.matrix;

        if (_el.rotated)
        {
            GUIUtility.RotateAroundPivot(90.0f, new Vector2(_atlasRect.x, _atlasRect.y));
            GUI.matrix = GUI.matrix * Matrix4x4.TRS(new Vector3(0.0f, -_atlasRect.width, 0.0f), Quaternion.identity, Vector3.one);

            // NOTE: clipping is done before rotating, if we rotate, we have to change the clip
            GUI.BeginGroup(_atlasRect);
            srcRect = new Rect(_el.coord[1],
                               _atlasRect.width - _el.coord[0] - _el.trimRect.height,
                               _el.trimRect.width,
                               _el.trimRect.height);
        }
        else
        {
            GUI.BeginGroup(_atlasRect);
            srcRect = new Rect(_el.coord[0],
                               _el.coord[1],
                               _el.trimRect.width,
                               _el.trimRect.height);
        }
        srcRect = new Rect(srcRect.x * _atlasInfo.scale,
                           srcRect.y * _atlasInfo.scale,
                           srcRect.width * _atlasInfo.scale,
                           srcRect.height * _atlasInfo.scale);

        // draw texture
        if (_el.trim)
        {
            Rect rect2 = new Rect(-_el.trimRect.x * _atlasInfo.scale,
                                  -_el.trimRect.y * _atlasInfo.scale,
                                  _el.texture.width * _atlasInfo.scale,
                                  _el.texture.height * _atlasInfo.scale);
            GUI.BeginGroup(srcRect);
            GUI.DrawTexture(rect2, _el.texture);
            GUI.EndGroup();
        }
        else
        {
            GUI.DrawTexture(srcRect, _el.texture);
        }

        // recover from rotate
        if (_el.rotated)
        {
            GUI.matrix = oldMat;
        }
        GUI.EndGroup();

        // ========================================================
        // draw selected border
        // ========================================================

        GUI.BeginGroup(_atlasRect);
        if (selected)
        {
            GUI.backgroundColor = _el.atlasInfo.elementSelectColor;
            GUI.Box(rect, GUIContent.none, exEditorHelper.RectBorderStyle());
            GUI.backgroundColor = oldBGColor;
        }
        GUI.EndGroup();

        // ========================================================
        // process mouse event
        Event e = Event.current;

        // ========================================================

        GUI.BeginGroup(_atlasRect);
        if (e.type == EventType.MouseDown && e.button == 0 && e.clickCount == 1)
        {
            if (rect.Contains(e.mousePosition))
            {
                GUIUtility.keyboardControl = -1; // remove any keyboard control
                if (e.command || e.control)
                {
                    ToggleSelected(_el);
                }
                else
                {
                    inDraggingElementState = true;
                    if (selected == false)
                    {
                        if (e.command == false && e.control == false)
                        {
                            selectedElements.Clear();
                            AddSelected(_el);
                        }
                    }
                }

                e.Use();
                Repaint();
            }
        }
        GUI.EndGroup();
    }
All Usage Examples Of exAtlasInfo.Element::Width
exAtlasInfo.Element