Exemplo n.º 1
0
 public void Draw(object value, Rect fullRect, bool selected, IconStyle style)
 {
     if (!(value is Sprite sprite))
     {
         return;
     }
     PvCustomizerGUI.DrawSprite(style.DrawRect, sprite, style.Material, tint: style.Tint);
 }
Exemplo n.º 2
0
        public void Draw(object value, Rect fullRect, bool selected, IconStyle style)
        {
            if (!(value is IList <Sprite> sprites))
            {
                return;
            }

            Rect drawRect = style.DrawRect;

            if (sprites.Count == 0)
            {
                PvCustomizerGUI.DrawBorder(drawRect, Color.magenta);
                PvCustomizerGUI.DrawTextDirect(drawRect, "Empty Array",
                                               Color.magenta, UnityEngine.FontStyle.Normal, PvAnchor.MiddleCenter);
            }
            else
            {
                int   gridSize = Mathf.CeilToInt(Mathf.Sqrt(sprites.Count));
                float width    = drawRect.width / gridSize;
                float height   = drawRect.height / gridSize;

                int nonNull = 0;

                for (int i = 0; i < sprites.Count; i++)
                {
                    Sprite sprite = sprites[i];
                    if (sprite == null)
                    {
                        continue;
                    }
                    nonNull++;
                    PvCustomizerGUI.DrawSprite(new Rect()
                    {
                        x      = drawRect.x + width * (i % gridSize),
                        y      = drawRect.y + height * (i / gridSize),
                        width  = width,
                        height = height
                    }, sprite, style.Material, style.Tint, style.ScaleMode);
                }

                if (style.SizeType == IconSizeType.Large)
                {
                    const int size = 10;
                    using (new TempFontSize(size))
                    {
                        string label = $"{nonNull}/{sprites.Count}";
                        GUI.skin.label.CalcMinMaxWidth(new GUIContent(label), out var min, out var max);
                        Rect area = new Rect(drawRect.xMax - min, drawRect.yMax - size / 2f, min * 2, size / 2f);

                        PvCustomizerGUI.DrawTextDirect(area, label, textAnchor: PvAnchor.UpperRight);
                    }
                }
            }
        }
        private void DrawTintExample()
        {
            if (_folderExampleSprite == null)
            {
                _folderExampleSprite = Resource.Load <Sprite>("Icons/Game Elements/008-castle.png");
            }
            Vector2 localBoundSize = _tintExampleContainer.localBound.size;
            Rect    drawRect       = GUILayoutUtility.GetRect(localBoundSize.x, localBoundSize.y);

            PvCustomizerGUI.DrawSprite(drawRect, _folderExampleSprite, tint: PvCustomizerGUI.ICON_SELECTED_TINT);
        }