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));
                }
            }
Beispiel #2
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()
            {
                var rect = ScenesWindowElementReference.ReferenceComponent.GetElementRect(Target);

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

                EditorGUI.BeginChangeCheck();
                var newRect = HandleUtil.HandleFixedRatioRect(id, rect, rect.width / rect.height, 10f,
                                                              (polygon, over, active) => HandleUtil.DrawPolyLine(polygon, true, SceneEditor.GetColor(Color.red)),
                                                              (point, over, active) => 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
                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);
                    var rectBase = original.Base();
                    if (Target is PlayerDataControl)
                    {
                        var workingScene = Controller.Instance.SelectedChapterDataControl.getScenesList().getScenes()[GameRources.GetInstance().selectedSceneIndex];
                        workingScene.setDefaultInitialPosition(Mathf.RoundToInt(rectBase.x), Mathf.RoundToInt(rectBase.y));
                    }
                    else if (Target is NodeDataControl)
                    {
                        var node = Target as NodeDataControl;
                        node.setNode(Mathf.RoundToInt(rectBase.x), Mathf.RoundToInt(rectBase.y), node.getScale());
                    }
                }
            }
Beispiel #4
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);
                    }
                }
            }