Esempio n. 1
0
        public static void DrawHandlesGuiTexture(Vector2 screenPoint, BGTransition.SwayTransition pointIndicatorTransition, Texture2D pointSelectedTexture)
        {
            pointIndicatorTransition.Tick();

            var shift = pointIndicatorTransition.Value * .5f;

            BGEditorUtility.HandlesGui(() =>
            {
                GUI.DrawTexture(
                    new Rect(screenPoint - new Vector2(shift, shift), new Vector2(pointIndicatorTransition.Value, pointIndicatorTransition.Value)),
                    pointSelectedTexture, ScaleMode.StretchToFill);
            });
        }
        private void Ui(Rect rect)
        {
            BGEditorUtility.HandlesGui(() =>
            {
                var size   = rect.size;
                var width  = Mathf.FloorToInt(Math.Abs(size.x));
                var height = Mathf.FloorToInt(Math.Abs(size.y));
                if (width == 0 || height == 0)
                {
                    return;
                }

                //------ back
                GUI.DrawTexture(rect, back, ScaleMode.StretchToFill);

                //------ borders
                //top
                DrawBorder(new Rect(rect)
                {
                    width = width, height = height == 1 ? 1 : 2
                }, false);
                if (height <= 2)
                {
                    return;
                }

                //bottom
                DrawBorder(new Rect(rect)
                {
                    y = rect.yMax - 2, width = width, height = 2
                }, false);

                if (width <= 4 || height <= 4)
                {
                    return;
                }

                //left
                DrawBorder(new Rect(rect)
                {
                    width = 2
                }, true);
                //right
                DrawBorder(new Rect(rect)
                {
                    x = rect.xMax - 2, width = 2
                }, true);
            });
        }
        // shows a message in the scene view
        public void OnSceneGui()
        {
            if (!showing)
            {
                return;
            }

            if (EditorApplication.timeSinceStartup - started > ShowTime)
            {
                showing = false;
            }

            BGEditorUtility.Assign(ref style, () => new GUIStyle("Label")
            {
                alignment = TextAnchor.MiddleCenter,
                richText  = true,
                normal    = { textColor = Color.white, background = BGEditorUtility.Texture1X1(new Color32(0, 0, 0, 100)) }
            });

            BGEditorUtility.HandlesGui(() => GUI.Label(rect, message, style));
        }
Esempio n. 4
0
        public void OnGui(Event currentEvent)
        {
            if (!Active)
            {
                return;
            }

            var mousePosition = currentEvent.mousePosition;

            if (onTransition == null && !targetRect.Contains(mousePosition))
            {
                Active = false;
                SceneView.RepaintAll();
                return;
            }

            BGEditorUtility.Assign(ref titleStyle, () => new GUIStyle("Label")
            {
                fontStyle = FontStyle.Bold,
                alignment = TextAnchor.MiddleCenter,
                normal    =
                {
                    textColor  = Color.white,
                    background = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGBoxWithBorder123)
                },
            });

            BGEditorUtility.HandlesGui(() =>
            {
                if (onTransition != null && !onTransition.Tick())
                {
                    //animating transition
                    GUI.DrawTexture(new Rect(Vector2.Lerp(Point2DPosition, targetRect.position, onTransition.Ratio), targetRect.size * onTransition.Ratio), backTexture, ScaleMode.StretchToFill);
                }
                else
                {
                    //ready
                    onTransition = null;

                    GUI.DrawTexture(targetRect, backTexture, ScaleMode.StretchToFill);
                    GUI.Label(new Rect(targetRect)
                    {
                        height = HeaderHeight
                    }, title, titleStyle);

                    ActiveItem = null;
                    var cursor = targetRect.x;

                    foreach (var item in items.Where(item => !item.Disabled))
                    {
                        var itemRect = new Rect(cursor, targetRect.y + HeaderHeight, item.Size.x, item.Size.y);
                        var selected = itemRect.Contains(mousePosition);

                        //if not separator
                        if (selected && item.Description != null)
                        {
                            ActiveItem = item;

                            if (!currentEvent.control && item is MenuItemButton)
                            {
                                ((MenuItemButton)item).Action();
                            }
                        }

                        //icon
                        if (item.Icon != null)
                        {
                            GUI.DrawTexture(itemRect, menuItemBackgroundTexture, ScaleMode.StretchToFill);

                            if (selected)
                            {
                                GUI.DrawTexture(itemRect, selectedTexture, ScaleMode.StretchToFill);
                            }

                            GUI.DrawTexture(itemRect, item.Icon, ScaleMode.StretchToFill);
                        }

                        if (item.Current)
                        {
                            GUI.DrawTexture(itemRect, currentTexture, ScaleMode.StretchToFill);
                        }

                        cursor += itemRect.width;
                    }
                }
            });

            if (!currentEvent.control)
            {
                Active = false;
            }
        }
        public void OnGui(Event currentEvent)
        {
            if (!Active)
            {
                return;
            }

            var mousePosition = currentEvent.mousePosition;

            if (onTransition == null && !targetRect.Contains(mousePosition))
            {
                Active = false;
                SceneView.RepaintAll();
                return;
            }

            BGEditorUtility.HandlesGui(() =>
            {
                if (onTransition != null && !onTransition.Tick())
                {
                    //animating transition
                    GUI.DrawTexture(new Rect(Vector2.Lerp(Point2DPosition, targetRect.position, onTransition.Ratio), targetRect.size * onTransition.Ratio), backTexture, ScaleMode.StretchToFill);
                }
                else
                {
                    //ready
                    onTransition = null;

                    GUI.DrawTexture(targetRect, backTexture, ScaleMode.StretchToFill);
                    GUI.Label(new Rect(targetRect)
                    {
                        height = HeaderHeight
                    }, title, TitleStyle);

                    ActiveItem = null;
                    var cursor = targetRect.x;

                    foreach (var item in items.Where(item => !item.Disabled))
                    {
                        var itemRect = new Rect(cursor, targetRect.y + HeaderHeight, item.Size.x, item.Size.y);
                        var selected = itemRect.Contains(mousePosition);

                        //if not separator
                        if (selected && item.Description != null)
                        {
                            ActiveItem = item;

                            if (!currentEvent.control && item is MenuItemButton)
                            {
                                ((MenuItemButton)item).Action();
                            }
                        }

                        //icon
                        if (item.Icon != null)
                        {
                            GUI.DrawTexture(itemRect, BGBinaryResources.BGMenuItemBackground123, ScaleMode.StretchToFill);

                            if (selected)
                            {
                                GUI.DrawTexture(itemRect, selectedTexture, ScaleMode.StretchToFill);
                            }

                            GUI.DrawTexture(itemRect, item.Icon, ScaleMode.StretchToFill);
                        }

                        if (item.Current)
                        {
                            GUI.DrawTexture(itemRect, currentTexture, ScaleMode.StretchToFill);
                        }

                        cursor += itemRect.width;
                    }
                }
            });

            if (!currentEvent.control)
            {
                Active = false;
            }
        }