示例#1
0
            public override void OnDrawingGizmos()
            {
                var gameplayArea = Target as GameplayAreaDataControl;

                if (!gameplayArea.UsesGameplayArea)
                {
                    return;
                }

                var viewRect         = MapEditor.Current.ScreenRect.ToPoints();
                var gameplayAreaRect = MapEditor.Current.ToRelative(MapEditor.Current.LatLonToPixels(gameplayArea.BoundingBox.ToPoints())).ToRectD().ToRect().ToPoints();

                var points = new Vector2[]
                {
                    // TopLeft
                    viewRect[0],
                    gameplayAreaRect[0],
                    // TopCenter
                    new Vector2(gameplayAreaRect[0].x, viewRect[0].y),
                    gameplayAreaRect[1],
                    // TopRight
                    new Vector2(gameplayAreaRect[1].x, viewRect[0].y),
                    new Vector2(viewRect[1].x, gameplayAreaRect[1].y),
                    // MiddleRight
                    gameplayAreaRect[1],
                    new Vector2(viewRect[1].x, gameplayAreaRect[2].y),
                    // BottomRight
                    gameplayAreaRect[2],
                    viewRect[2],
                    // BottomCenter
                    gameplayAreaRect[3],
                    new Vector2(gameplayAreaRect[2].x, viewRect[2].y),
                    // BottomLeft
                    new Vector2(viewRect[3].x, gameplayAreaRect[3].y),
                    new Vector2(gameplayAreaRect[3].x, viewRect[3].y),
                    // MiddleLeft
                    new Vector2(viewRect[0].x, gameplayAreaRect[0].y),
                    gameplayAreaRect[3]
                };

                for (int i = 0; i < points.Length; i += 2)
                {
                    var rect = new Rect(points[i], points[i + 1] - points[i]);
                    if (rect.width > 0 || rect.height > 0)
                    {
                        Handles.BeginGUI();
                        Handles.color = MapEditor.GetColor(new Color(0, 0, 0, 0.5f));
                        Handles.DrawAAConvexPolygon(rect.ToPoints3());
                        Handles.EndGUI();
                    }
                }
            }
示例#2
0
            public override void OnDrawingGizmosSelected()
            {
                var gameplayArea = Target as GameplayAreaDataControl;

                if (!gameplayArea.UsesGameplayArea)
                {
                    return;
                }

                var gameplayAreaRect = MapEditor.Current.ToRelative(MapEditor.Current.LatLonToPixels(gameplayArea.BoundingBox.ToPoints()))
                                       .ToRectD().ToRect();


                var handleRectID = GUIUtility.GetControlID(GetHashCode(), FocusType.Passive);

                EditorGUI.BeginChangeCheck();
                Handles.BeginGUI();
                var newRect = HandleUtil.HandleRect(handleRectID, gameplayAreaRect, 10, (_, __, ___) => { },
                                                    (p, hover, active) => HandleUtil.DrawSquare(p, 10, MapEditor.GetColor(Color.yellow),
                                                                                                hover ? MapEditor.GetColor(Color.red) : MapEditor.GetColor(Color.black)));

                Handles.EndGUI();
                if (EditorGUI.EndChangeCheck())
                {
                    var latLonRect = MapEditor.Current
                                     .PixelsToLatLon(MapEditor.Current.FromRelative(newRect.ToRectD().ToPoints())).ToRectD();
                    gameplayArea.BoundingBox = latLonRect;
                }
            }