public override void OnDrawingGizmosSelected()
            {
                var elemRef = Target as ElementReferenceDataControl;
                var rect    = GetElementRect(elemRef);

                var newRect = HandleUtil.HandleFixedRatioRect(elemRef.GetHashCode() + 1, rect, rect.width / rect.height, 10f,
                                                              polygon => HandleUtil.DrawPolyLine(polygon, true, Color.red),
                                                              point => HandleUtil.DrawPoint(point, 4.5f, Color.blue, Color.black));

                if (newRect != rect)
                {
                    var original = newRect.ViewportToScreen(SceneEditor.Current.Size.x, SceneEditor.Current.Size.y, SceneEditor.Current.Viewport);
                    var unscaled = ScenesWindowElementReference.ReferenceComponent.GetUnscaledRect(Target);
                    // And then we rip the position
                    var position = original.center + new Vector2(0, original.height / 2f);
                    var scale    = original.size.magnitude / unscaled.size.magnitude;

                    // And then we set the values in the reference
                    elemRef.setElementPositionAndScale(Mathf.RoundToInt(position.x), Mathf.RoundToInt(position.y), scale);
                }

                EditorGUI.BeginChangeCheck();
                rect = HandleUtil.HandleRectMovement(elemRef.GetHashCode(), rect);
                if (EditorGUI.EndChangeCheck())
                {
                    var original = rect.ViewportToScreen(SceneEditor.Current.Size.x, SceneEditor.Current.Size.y, SceneEditor.Current.Viewport);
                    elemRef.setElementPosition(Mathf.RoundToInt(original.x + 0.5f * original.width), Mathf.RoundToInt(original.y + original.height));
                }
            }
Exemplo n.º 2
0
            public override void OnDrawingGizmosSelected()
            {
                var rect = ScenesWindowElementReference.ReferenceComponent.GetElementRect(Target);

                // Rect resizing
                EditorGUI.BeginChangeCheck();
                var newRect = HandleUtil.HandleFixedRatioRect(Target.GetHashCode() + 1, rect, rect.width / rect.height, 10f,
                                                              polygon => HandleUtil.DrawPolyLine(polygon, true, SceneEditor.GetColor(Color.red)),
                                                              point => HandleUtil.DrawPoint(point, 4.5f, SceneEditor.GetColor(Color.blue), SceneEditor.GetColor(Color.black)));

                if (EditorGUI.EndChangeCheck())
                {
                    var original = newRect.ViewportToScreen(SceneEditor.Current.Size.x, SceneEditor.Current.Size.y, SceneEditor.Current.Viewport);
                    var unscaled = ScenesWindowElementReference.ReferenceComponent.GetUnscaledRect(Target);
                    // And then we rip the position
                    var position = original.center + new Vector2(0, original.height / 2f);
                    var scale    = original.size.magnitude / unscaled.size.magnitude;

                    if (Target is PlayerDataControl)
                    {
                        var workingScene = Controller.Instance.SelectedChapterDataControl.getScenesList().getScenes()[
                            GameRources.GetInstance().selectedSceneIndex];
                        // And then we set the values in the reference
                        workingScene.setDefaultInitialPosition(Mathf.RoundToInt(position.x), Mathf.RoundToInt(position.y));
                        workingScene.setPlayerScale(scale);
                    }
                    else if (Target is NodeDataControl)
                    {
                        var node = Target as NodeDataControl;
                        node.setNode(Mathf.RoundToInt(position.x), Mathf.RoundToInt(position.y), scale);
                    }
                }

                // Rect movement
                EditorGUI.BeginChangeCheck();
                rect = HandleUtil.HandleRectMovement(Target.GetHashCode(), rect);
                if (EditorGUI.EndChangeCheck())
                {
                    var original = rect.ViewportToScreen(SceneEditor.Current.Size.x, SceneEditor.Current.Size.y, SceneEditor.Current.Viewport);
                    if (Target is PlayerDataControl)
                    {
                        var workingScene = Controller.Instance.SelectedChapterDataControl.getScenesList().getScenes()[GameRources.GetInstance().selectedSceneIndex];
                        workingScene.setDefaultInitialPosition(Mathf.RoundToInt(original.x + 0.5f * original.width), Mathf.RoundToInt(original.y + original.height));
                    }
                    else if (Target is NodeDataControl)
                    {
                        var node = Target as NodeDataControl;
                        node.setNode(Mathf.RoundToInt(original.x + 0.5f * original.width), Mathf.RoundToInt(original.y + original.height), node.getScale());
                    }
                }
            }
            public override void OnDrawingGizmos()
            {
                var trajectory = Target as TrajectoryDataControl;

                if (trajectory == null)
                {
                    return;
                }

                if (SceneEditor.Current.Disabled && pairing != null)
                {
                    pairing = null;
                }

                if (previousTrajectoryDataControl != trajectory)
                {
                    previousTrajectoryDataControl = trajectory;
                    pairing = null;
                }

                if (Event.current.type == EventType.MouseDown)
                {
                    var selected = SceneEditor.Current.SelectedElement;
                    var node     = selected as NodeDataControl;
                    var side     = selected as SideDataControl;

                    var isNode = node != null && trajectory.getNodes().Contains(node);
                    var isSide = side != null && trajectory.getSides().Contains(side);

                    switch (Action)
                    {
                    // Moving
                    case 1:
                        if (SceneEditor.Current.SelectedElement == null)
                        {
                            var pos = (Event.current.mousePosition - SceneEditor.Current.Viewport.position);
                            pos.x = (pos.x / SceneEditor.Current.Viewport.size.x) * SceneEditor.Current.Size.x;
                            pos.y = (pos.y / SceneEditor.Current.Viewport.size.y) * SceneEditor.Current.Size.y;
                            trajectory.addNode(Mathf.RoundToInt(pos.x), Mathf.RoundToInt(pos.y));
                        }
                        break;

                    // Pariring
                    case 2:
                        if (isNode)
                        {
                            if (pairing == null)
                            {
                                pairing = node;
                            }
                            else
                            {
                                var duplicated = trajectory.getSides().Find(s => IsPairingStartOrEnd(s, node)) != null;
                                if (!duplicated)
                                {
                                    trajectory.addSide(pairing, node);
                                }
                                pairing = null;
                            }
                        }
                        else
                        {
                            pairing = null;
                        }
                        break;

                    // Initial
                    case 3:
                        if (isNode)
                        {
                            trajectory.setInitialNode(node);
                        }
                        break;

                    // Deleting
                    case 4:
                        if ((isNode || isSide) && trajectory.deleteElement(selected, false))
                        {
                            SceneEditor.Current.SelectedElement = null;
                        }
                        break;
                    }
                }

                foreach (var node in trajectory.getNodes())
                {
                    HandleUtil.DrawPoint(GetPivot(node), 10f, SceneEditor.GetColor(node.isInitial() ? Color.red : Color.blue), SceneEditor.GetColor(Color.black));
                }

                if (pairing != null)
                {
                    HandleUtil.DrawPolyLine(new Vector2[] { GetPivot(pairing), Event.current.mousePosition }, false, SceneEditor.GetColor(Color.white), 3f);
                }
            }
Exemplo n.º 4
0
            public override void OnDrawingGizmosSelected()
            {
                var elemRef = Target as ElementReferenceDataControl;
                var rect    = GetElementRect(elemRef);

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

                var newRect = HandleUtil.HandleFixedRatioRect(id, rect, rect.width / rect.height, 10f,
                                                              (polygon, over, active) => HandleUtil.DrawPolyLine(polygon, true, Color.red, over && MouseOverTexture(elemRef, rect) || active ? 4f : 2f),
                                                              (point, over, active) => HandleUtil.DrawPoint(point, 4.5f, Color.blue, over || active ? 2f : 1f, SceneEditor.GetColor(over || active ? Color.red : Color.black)));

                if (newRect != rect)
                {
                    var original = newRect.ViewportToScreen(SceneEditor.Current.Size.x, SceneEditor.Current.Size.y, SceneEditor.Current.Viewport);
                    var unscaled = ScenesWindowElementReference.ReferenceComponent.GetUnscaledRect(Target);
                    // And then we rip the position
                    var position = original.center + new Vector2(0, original.height / 2f);
                    var scale    = original.size.magnitude / unscaled.size.magnitude;

                    // And then we set the values in the reference
                    elemRef.setElementPositionAndScale(Mathf.RoundToInt(position.x), Mathf.RoundToInt(position.y), scale);
                }

                var movementId = GUIUtility.GetControlID(GetHashCode() + 1, FocusType.Passive);

                EditorGUI.BeginChangeCheck();
                rect = HandleUtil.HandleRectMovement(movementId, rect);
                if (EditorGUI.EndChangeCheck())
                {
                    var original = rect.ViewportToScreen(SceneEditor.Current.Size.x, SceneEditor.Current.Size.y, SceneEditor.Current.Viewport);
                    elemRef.setElementPosition(Mathf.RoundToInt(original.x + 0.5f * original.width), Mathf.RoundToInt(original.y + original.height));
                }
            }
        public override void OnDrawingGizmosSelected()
        {
            Handles.BeginGUI();

            Color lineColor     = Color.red;
            var   rectangleArea = Target as RectangleArea;


            var points = WorldToViewport(GetPoints(rectangleArea), SceneEditor.Current.Viewport, SceneEditor.Current.Size.x, SceneEditor.Current.Size.y);

            switch (Event.current.type)
            {
            case EventType.Repaint: HandleUtil.DrawPolyLine(points, true, lineColor, 5f); break;
            }

            bool pointsChanged = false;

            int index             = 1;
            int rectCornerChanged = -1;

            foreach (var point in points)
            {
                var pointControlId = GUIUtility.GetControlID("Rectangle Point".GetHashCode(), FocusType.Passive, new Rect(point, new Vector2(10, 10)));
                switch (Event.current.GetTypeForControl(pointControlId))
                {
                case EventType.Repaint: if (rectangleArea.isRectangular())
                    {
                        HandleUtil.DrawSquare(point, 10f, Color.yellow, Color.black);
                    }
                    else
                    {
                        HandleUtil.DrawPoint(point, 4.5f, Color.cyan, Color.black);
                    } break;

                case EventType.MouseDown:
                    switch (ActionSelected)
                    {
                    case 0:
                        if (GUIUtility.hotControl == 0 && (point - Event.current.mousePosition).magnitude < 10)
                        {
                            GUIUtility.hotControl = pointControlId;
                            Event.current.Use();
                        }
                        break;

                    case 2:
                        if ((point - Event.current.mousePosition).magnitude < 10)
                        {
                            rectangleArea.deletePoint(rectangleArea.getPoints()[index - 1]);
                            Event.current.Use();
                        }
                        break;
                    }
                    break;

                case EventType.MouseDrag:
                    if (GUIUtility.hotControl == pointControlId)
                    {
                        points[index - 1].x += Event.current.delta.x;
                        points[index - 1].y += Event.current.delta.y;
                        pointsChanged        = true;
                        rectCornerChanged    = index - 1;
                        Event.current.Use();
                    }
                    break;

                case EventType.MouseUp:
                    if (GUIUtility.hotControl == pointControlId)
                    {
                        GUIUtility.hotControl = 0;
                        Event.current.Use();
                    }
                    break;
                }
                index++;
            }

            var rectangleControlID = GUIUtility.GetControlID("Rectangle".GetHashCode(), FocusType.Passive);

            switch (Event.current.GetTypeForControl(rectangleControlID))
            {
            case EventType.MouseDown:
                switch (ActionSelected)
                {
                case 0:
                    if (GUIUtility.hotControl == 0 && points.Inside(Event.current.mousePosition))
                    {
                        GUIUtility.hotControl = rectangleControlID;
                        Event.current.Use();
                    }
                    break;

                case 1:
                    var point = Event.current.mousePosition;         //ViewportToWorld(Event.current.mousePosition, SceneEditor.Current.Viewport, new Vector2(800f, 600f));

                    var pointlist = points.ToList();
                    pointlist.Insert(FindInsertPos(points, point), point);
                    points = pointlist.ToArray();

                    pointsChanged = true;
                    Event.current.Use();
                    break;
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == rectangleControlID)
                {
                    points        = points.Select(p => p + Event.current.delta).ToArray();
                    pointsChanged = true;
                    Event.current.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == rectangleControlID)
                {
                    GUIUtility.hotControl = 0;
                    Event.current.Use();
                }
                break;

            case EventType.Repaint:
                if (ActionSelected == 1)
                {
                    var pos = FindInsertPos(points, Event.current.mousePosition);
                    Handles.DrawLine(points[(points.Length + pos - 1) % points.Length], Event.current.mousePosition);
                    Handles.DrawLine(Event.current.mousePosition, points[pos % points.Length]);
                }

                break;
            }


            if (pointsChanged)
            {
                this.Repaint();
                // Update points in the selection
                if (rectangleArea.isRectangular())
                {
                    switch (rectCornerChanged)
                    {
                    case 0: points[3].x += Event.current.delta.x; points[1].y += Event.current.delta.y; break;

                    case 1: points[2].x += Event.current.delta.x; points[0].y += Event.current.delta.y; break;

                    case 2: points[1].x += Event.current.delta.x; points[3].y += Event.current.delta.y; break;

                    case 3: points[0].x += Event.current.delta.x; points[2].y += Event.current.delta.y; break;
                    }

                    var rect = ViewportToWorld(points, SceneEditor.Current.Viewport, SceneEditor.Current.Size.x, SceneEditor.Current.Size.y).ToRect();
                    rectangleArea.getRectangle().setValues(
                        Mathf.RoundToInt(rect.x),
                        Mathf.RoundToInt(rect.y),
                        Mathf.RoundToInt(rect.width),
                        Mathf.RoundToInt(rect.height));
                }
                else
                {
                    rectangleArea.getPoints().Clear();
                    rectangleArea.getPoints().AddRange(ViewportToWorld(points, SceneEditor.Current.Viewport, SceneEditor.Current.Size.x, SceneEditor.Current.Size.y));
                }
            }

            Handles.EndGUI();
        }
Exemplo n.º 6
0
            private void DrawIconInventory(AdventureDataControl adventureData, Matrix4x4 matrix)
            {
                if (icon != null)
                {
                    var scale = adventureData.getInventoryScale();
                    var pos   = matrix.MultiplyPoint3x4(adventureData.getInventoryCoords());

                    var textureSize     = matrix.MultiplyVector(new Vector2(icon.width, icon.height));
                    var inventorySize   = textureSize * scale;
                    var inventoryCorner = pos - new Vector3(inventorySize.x / 2f, inventorySize.y);

                    var inventoryRect = new Rect(inventoryCorner, inventorySize);
                    GUI.DrawTexture(inventoryRect, icon);

                    EditorGUI.BeginChangeCheck();
                    var inventoryId = GUIUtility.GetControlID("SizeId".GetHashCode(), FocusType.Passive, inventoryRect);
                    var newRect     = HandleUtil.HandleFixedRatioRect(inventoryId, inventoryRect, icon.width / (float)icon.height, 10f,
                                                                      (polygon, over, active) => HandleUtil.DrawPolyLine(polygon, true, Color.red, over || active ? 4f : 2f),
                                                                      (point, over, active) => HandleUtil.DrawPoint(point, 4.5f, Color.blue, over || active ? 2f : 1f, over || active ? Color.red : Color.black));

                    if (EditorGUI.EndChangeCheck())
                    {
                        var newScale  = newRect.width / (float)textureSize.x;
                        var newCoords = InverseMultiplyPoint(matrix, newRect.center + new Vector2(0, newRect.height / 2f));

                        adventureData.setInventoryCoords(newCoords);
                        adventureData.setInventoryScale(newScale);
                    }

                    EditorGUI.BeginChangeCheck();
                    var inventoryMovementId = GUIUtility.GetControlID("MovementId".GetHashCode(), FocusType.Passive, inventoryRect);
                    newRect = HandleUtil.HandleRectMovement(inventoryMovementId, newRect);
                    if (EditorGUI.EndChangeCheck())
                    {
                        var newCoords = InverseMultiplyPoint(matrix, newRect.center + new Vector2(0, newRect.height / 2f));
                        adventureData.setInventoryCoords(newCoords);
                    }
                }
            }
Exemplo n.º 7
0
            void OnGUI()
            {
                if (guiMap == null)
                {
                    guiMap = new GUIMap();
                }


                debugWindowRect = GUI.Window(12341234, debugWindowRect, (id) =>
                {
                    var mapRect = new Rect(2, 18, 196, 180);
                    using (new GUILayout.AreaScope(mapRect))
                    {
                        guiMap.Center = GeoExtension.Instance.Location;
                        guiMap.Zoom   = 17;
                        guiMap.DrawMap(new Rect(0, 0, 196, 180));
                        // Calculate the player pixel relative to the map
                        var playerMeters        = MapzenGo.Helpers.GM.LatLonToMeters(GeoExtension.Instance.Location);
                        var playerPixel         = MapzenGo.Helpers.GM.MetersToPixels(playerMeters, guiMap.Zoom);
                        var playerPixelRelative = playerPixel + guiMap.PATR;

                        // Do the point handling
                        var pointControl = GUIUtility.GetControlID("PlayerPosition".GetHashCode(), FocusType.Passive);
                        EditorGUI.BeginChangeCheck();
                        var newPlayerPixel = HandleUtil.HandlePointMovement(pointControl, playerPixelRelative.ToVector2(), 10,
                                                                            (point, isOver, isActive) => HandleUtil.DrawPoint(point, 4, Color.cyan,
                                                                                                                              Color.black), MouseCursor.MoveArrow);
                        if (EditorGUI.EndChangeCheck())
                        {
                            // If changed, restore the point to the geochar
                            playerPixel  = newPlayerPixel.ToVector2d() - guiMap.PATR;
                            playerMeters = MapzenGo.Helpers.GM.PixelsToMeters(playerPixel, guiMap.Zoom);
                            GeoExtension.Instance.Location = MapzenGo.Helpers.GM.MetersToLatLon(playerMeters);
                        }

                        guiMap.ProcessEvents(mapRect);
                    }
                    GUI.DragWindow();
                },
                                             "DebugWindow");
            }