private static void DropDownSpacingCoordinate(Rect position, SnapAxis axis) { s_DropDownSnapAxis = axis; var menu = new EditorMenu(); menu.AddCommand(TileLang.Text("Fraction of Cell Size")) .Checked(axis.GridType == SnapGridType.Fraction) .Action(DoSelectSpacingType, SnapGridType.Fraction); menu.AddCommand(TileLang.Text("Custom Size")) .Checked(axis.GridType == SnapGridType.Custom) .Action(DoSelectSpacingType, SnapGridType.Custom); menu.AddSeparator(); foreach (int fractionValue in new int[] { 1, 2, 4, 8, 16 }) { menu.AddCommand(string.Format("{0} \u2044 {1}", 1, fractionValue)) .Action(s_DropDownSnapAxis.SetFraction, fractionValue); } menu.AddSeparator(); foreach (float decimalValue in new float[] { 0.1f, 0.25f, 0.5f, 1f, 2f }) { menu.AddCommand(string.Format("{0}", decimalValue)) .Action(s_DropDownSnapAxis.SetCustomSize, decimalValue); } menu.ShowAsDropdown(position); }
private static ControlContent AlignmentContent(string label, SnapAxis axis) { Texture2D icon; string tip; switch (axis.Alignment) { default: case SnapAlignment.Points: icon = RotorzEditorStyles.Skin.SnapPoints; tip = TileLang.ParticularText("SnapAlignment", "Points"); break; case SnapAlignment.Cells: icon = RotorzEditorStyles.Skin.SnapCells; tip = TileLang.ParticularText("SnapAlignment", "Cells"); break; case SnapAlignment.Free: icon = label == "X" ? RotorzEditorStyles.Skin.SnapFreeX : RotorzEditorStyles.Skin.SnapFreeY; tip = TileLang.ParticularText("SnapAlignment", "Free"); break; } return(ControlContent.Basic(icon, tip)); }
public void SetFrom(SnapAxis other) { if (other == null) { throw new ArgumentNullException("other"); } this.Alignment = other.Alignment; this.GridType = other.GridType; this.FractionDenominator = other.FractionDenominator; this.CustomSize = other.CustomSize; }
private static void DropDownAlignment(Rect position, SnapAxis axis) { s_DropDownSnapAxis = axis; var menu = new EditorMenu(); menu.AddCommand(TileLang.ParticularText("SnapAlignment", "Free")) .Checked(axis.Alignment == SnapAlignment.Free) .Action(DoSelectSnapAlignment, SnapAlignment.Free); menu.AddCommand(TileLang.ParticularText("SnapAlignment", "Points")) .Checked(axis.Alignment == SnapAlignment.Points) .Action(DoSelectSnapAlignment, SnapAlignment.Points); menu.AddCommand(TileLang.ParticularText("SnapAlignment", "Cells")) .Checked(axis.Alignment == SnapAlignment.Cells) .Action(DoSelectSnapAlignment, SnapAlignment.Cells); menu.ShowAsDropdown(position); }
private static void SpacingCoordinateField(Rect position, string label, SnapAxis axis) { var fieldStyle = RotorzEditorStyles.Instance.TextFieldRoundEdge; var textStyle = RotorzEditorStyles.Instance.TransparentTextField; var buttonStyle = RotorzEditorStyles.Instance.TextFieldRoundEdgeCancelButtonEmpty; int controlID = EditorGUIUtility.GetControlID(s_SpacingCoordinateFieldHint, FocusType.Passive); int realTextControlID = controlID + 1; // Display prefix label? if (!string.IsNullOrEmpty(label)) { if (Event.current.type == EventType.Repaint) { EditorStyles.label.Draw(new Rect(position.x, position.y, 12, position.height), label, false, false, false, false); } position.x += 12; position.width -= 12; } // Display popup field for alignment selection. Rect alignmentPosition = position; alignmentPosition.y -= 1; alignmentPosition.width = 33; alignmentPosition.height += 1; using (var content = AlignmentContent(label, axis)) { if (EditorInternalUtility.DropdownMenu(alignmentPosition, content, RotorzEditorStyles.Instance.FlatButton)) { DropDownAlignment(alignmentPosition, axis); } } position.x += alignmentPosition.width; position.width -= alignmentPosition.width; EditorGUI.BeginDisabledGroup(axis.Alignment == SnapAlignment.Free); { // Add small amount of padding after control. Rect textPosition = position; textPosition.width -= 3; if (axis.Alignment == SnapAlignment.Free) { // Draw background for text field. if (Event.current.type == EventType.Repaint) { position.width -= buttonStyle.fixedWidth; fieldStyle.Draw(position, false, false, false, false); // Draw end of text field control. position.x += position.width; position.width = buttonStyle.fixedWidth; position.height = buttonStyle.fixedHeight; buttonStyle.Draw(position, false, false, false, false); } } else { using (var fieldPrefixContent = ControlContent.Basic( labelText: axis.GridType == SnapGridType.Fraction ? "1/" : " ", image: RotorzEditorStyles.Skin.DownArrow )) { // Draw background for text field. if (Event.current.type == EventType.Repaint) { position.width -= buttonStyle.fixedWidth; GUI.contentColor = EditorGUIUtility.isProSkin ? Color.black : new Color(0f, 0f, 0f, 0.5f); fieldStyle.Draw(position, fieldPrefixContent, realTextControlID); GUI.contentColor = Color.white; // Draw end of text field control. position.x += position.width; position.width = buttonStyle.fixedWidth; position.height = buttonStyle.fixedHeight; buttonStyle.Draw(position, false, false, false, false); } float prefixWidth = fieldStyle.CalcSize(fieldPrefixContent).x; if (Event.current.GetTypeForControl(controlID) == EventType.MouseDown) { Rect popupPosition = textPosition; popupPosition.width = prefixWidth; if (popupPosition.Contains(Event.current.mousePosition)) { Event.current.Use(); DropDownSpacingCoordinate(popupPosition, axis); } } // Draw actual text field. textPosition.x += prefixWidth; textPosition.y += 1; textPosition.width -= prefixWidth; switch (axis.GridType) { default: case SnapGridType.Fraction: axis.SetFraction(EditorGUI.IntField(textPosition, axis.FractionDenominator, textStyle)); break; case SnapGridType.Custom: axis.SetCustomSize(EditorGUI.FloatField(textPosition, axis.CustomSize, textStyle)); break; } } } } EditorGUI.EndDisabledGroup(); }