Example #1
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;
                }
            }
            public override void OnDrawingGizmosSelected()
            {
                if (GetScenePlayerMode(SceneEditor.Current.Scene) != PlayerMode.Trajectory)
                {
                    return;
                }

                wasSelected = Target;
                var influenceArea = getInfluenceArea(Target);

                if (influenceArea == null)
                {
                    return;
                }

                var boundaries = GetElementBoundaries(Target);
                var rect       = influenceArea.ScreenRect(boundaries);

                if (!influenceArea.hasInfluenceArea())
                {
                    rect.position -= new Vector2(20, 20);
                    rect.size      = boundaries.size + new Vector2(40, 40);
                }

                rect = rect.AdjustToViewport(SceneEditor.Current.Size.x, SceneEditor.Current.Size.y, SceneEditor.Current.Viewport);

                EditorGUI.BeginChangeCheck();
                var newRect = HandleUtil.HandleRect(influenceArea.GetHashCode() + 1, rect, 10f,
                                                    (polygon, over, active) =>
                {
                    HandleUtil.DrawPolyLine(polygon, true, Color.blue);
                    HandleUtil.DrawPolygon(polygon, new Color(0, 0, 1f, 0.3f));
                },
                                                    (point, over, active) => HandleUtil.DrawSquare(point, 6.5f, Color.yellow, Color.black));

                newRect = HandleUtil.HandleRectMovement(influenceArea.GetHashCode(), newRect);

                if (EditorGUI.EndChangeCheck())
                {
                    var original = newRect.ViewportToScreen(SceneEditor.Current.Size.x, SceneEditor.Current.Size.y, SceneEditor.Current.Viewport);

                    original.position -= boundaries.position;
                    var rectFixed = FixToBoundaries(new RectInt((int)original.x, (int)original.y, (int)original.width, (int)original.height), boundaries);
                    // And then we set the values in the reference
                    influenceArea.setInfluenceArea(rectFixed.x, rectFixed.y, rectFixed.width, rectFixed.height);
                }
            }