Ejemplo n.º 1
0
        //Element
        public void Element(string textureName, ICComRect position, RectOffset borders, RectOffset offset)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            position.Init(this);
            Rect rect = position.GetRect();

            GUIStyle elementStyle = new GUIStyle();

            elementStyle.normal.background = ICEditorFunc.GetIcon(textureName);
            elementStyle.hover.background  = ICEditorFunc.GetIcon(textureName);

            if (borders != null)
            {
                elementStyle.border = borders;
            }
            Rect paddedRect = ToDisplay(rect);

            if (offset != null)
            {
                paddedRect = new Rect(paddedRect.x - offset.left, paddedRect.y - offset.top, paddedRect.width + offset.left + offset.right, paddedRect.height + offset.top + offset.bottom);
            }

#if UNITY_EDITOR
            elementStyle.Draw(paddedRect, UnityEditor.EditorGUIUtility.isProSkin, false, false, false);
#endif
        }
Ejemplo n.º 2
0
        public void Icon(ICComRect position, Texture2D texture,
                         IconAligment horizontalAlign = IconAligment.resize,
                         IconAligment verticalAlign   = IconAligment.resize,
                         bool tile = false)
        {
#if UNITY_EDITOR
            if (texture == null)
            {
                return;
            }

            position.Init(this);
            var rect = position.GetRect(margin);

            //aligning texture if the rect width or height is more than icon size
            if (rect.width > texture.width)
            {
                switch (horizontalAlign)
                {
                case IconAligment.min: rect.width = texture.width; break;

                case IconAligment.center: rect.x += rect.width / 2; rect.x -= texture.width / 2; rect.width = texture.width; break;

                case IconAligment.max: rect.x += rect.width; rect.x -= texture.width; rect.width = texture.width; break;
                }
            }
            if (rect.height > texture.height)
            {
                switch (verticalAlign)
                {
                case IconAligment.min: rect.height = texture.height; break;

                case IconAligment.center: rect.y += rect.height / 2; rect.y -= texture.height / 2; rect.height = texture.height; break;

                case IconAligment.max: rect.y += rect.height; rect.y -= texture.height; rect.height = texture.height; break;
                }
            }
            if (!tile)
            {
                GUI.DrawTexture(ToDisplay(rect), texture, ScaleMode.ScaleAndCrop);
            }
            else
            {
                //Debug.Log(zoom);
                Rect localRect = ToDisplay(rect);
                for (float x = 0; x < rect.width; x += texture.width * zoom)
                {
                    for (float y = 0; y < rect.height + texture.height; y += texture.height * zoom)
                    {
                        GUI.DrawTexture(new Rect(x + localRect.x, y + localRect.y, texture.width * zoom + 1, texture.height * zoom + 1), texture, ScaleMode.StretchToFill);
                    }
                }
            }
#endif
        }
Ejemplo n.º 3
0
        private void Com_Init(ICComRect position,
                              string label          = "", string tooltip = "", GUIStyle style = null,
                              GUIStyle defaultStyle = null)
        {
            position.Init(this);
            com_rect = ToDisplay(position.GetRect(margin));                //确定位置

            Style_Init(style, defaultStyle);

            com_content = new GUIContent(label, tooltip);
        }