Esempio n. 1
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);
                    }
                }
            }