Esempio n. 1
0
        public virtual void On(Vector3 position)
        {
            if (Active)
            {
                return;
            }

            Active = true;

            onTransition    = new BGTransition.SimpleTransition(.2, false);
            Point3DPosition = position;
            Point2DPosition = BGEditorUtility.GetSceneViewPosition(Point3DPosition);

            //target size (go first)
            height = width = 0;
            foreach (var size in items.Where(item => !item.Disabled).Select(item => item.Size))
            {
                if (height < size.y * 2)
                {
                    height = size.y * 2;
                }
                width += size.x;
            }
            targetRect.size = new Vector2(width, height + HeaderHeight);


            //target position (go second)
            targetRect.x = Point2DPosition.x - targetRect.size.x * .5f;
            targetRect.y = Point2DPosition.y - targetRect.size.y * .75f;
        }
Esempio n. 2
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;
            }
        }