public override void OnEnable() { base.OnEnable(); transform = (Transform)target; SnapSettings.CleanUp(); }
bool ShowToggleButton(string buttonLabel, string tooltip, GUIStyle buttonStyle) { bool pressed = SnapSettings.GetValue <bool>("Toggle" + buttonLabel + transform.GetInstanceID()); float width = buttonLabel.GetWidth(EditorStyles.miniFont) + 12; int spacing = buttonStyle == EditorStyles.miniButtonLeft ? -6 : 0; Rect position = EditorGUILayout.BeginVertical(GUILayout.Width(buttonLabel.GetWidth(EditorStyles.miniFont) + 16 + spacing), GUILayout.Height(EditorGUIUtility.singleLineHeight)); EditorGUILayout.Space(); pressed = EditorGUI.Toggle(new Rect(position.x + 4, position.y + 2, width, position.height - 1), pressed, buttonStyle); if (pressed) { EditorGUI.LabelField(new Rect(position.x + 8, position.y + 1, width, position.height - 1), new GUIContent(buttonLabel, tooltip), EditorStyles.whiteMiniLabel); } else { EditorGUI.LabelField(new Rect(position.x + 8, position.y + 1, width, position.height - 1), new GUIContent(buttonLabel, tooltip), EditorStyles.miniLabel); } if (pressed != SnapSettings.GetValue <bool>("Toggle" + buttonLabel + transform.GetInstanceID())) { foreach (Transform t in Selection.transforms) { SnapSettings.SetValue("Toggle" + buttonLabel + t.GetInstanceID(), pressed); EditorUtility.SetDirty(t); } } EditorGUILayout.EndVertical(); return(SnapSettings.GetValue <bool>("Toggle" + buttonLabel + transform.GetInstanceID())); }
static void CreateSnapSettingsWindow() { if (Instance == null) { Instance = (SnapSettings)EditorWindow.GetWindow <SnapSettings>("Snap Settings", true); Instance.position = new Rect(Screen.currentResolution.width / 2 - 121, Screen.currentResolution.height / 2 - 167, 275, 176); Instance.minSize = new Vector2(275, 176); } }
void GetSnapSettings() { moveX = SnapSettings.GetValue <float>("moveX"); moveY = SnapSettings.GetValue <float>("moveY"); moveZ = SnapSettings.GetValue <float>("moveZ"); rotation = SnapSettings.GetValue <float>("rotation"); scale = SnapSettings.GetValue <float>("scale"); gridSize = SnapSettings.GetValue <int>("gridSize"); showCubes = SnapSettings.GetValue <bool>("showCubes"); showLines = SnapSettings.GetValue <bool>("showLines"); }
void ShowUtilityButtons() { EditorGUILayout.BeginHorizontal(); // Reset Button if (GUILayout.Button(new GUIContent(". Reset .", "Resets the transform to it's original state."), EditorStyles.miniButton, GUILayout.Width("Reset".GetWidth(EditorStyles.miniFont) + 12))) { Undo.RegisterCompleteObjectUndo(targets, "Transform Reset"); foreach (Transform t in Selection.transforms) { t.Reset(); SnapSettings.DeleteKey("Toggle" + "Snap" + t.GetInstanceID()); SnapSettings.DeleteKey("Toggle" + "Grid" + t.GetInstanceID()); EditorUtility.SetDirty(t); deleteBreak = true; } return; } Separator(false); // Snap Button snap = ShowToggleButton("Snap", "Toggles the snapping of the transform to the grid. See Magicolo's Tools/Snap Settings to change the snap settings.", EditorStyles.miniButtonLeft); EditorGUI.BeginChangeCheck(); grid = ShowToggleButton("Grid", "Toggles the display of the grid. See Magicolo's Tools/Snap Settings to change the grid display settings.", EditorStyles.miniButtonRight); if (EditorGUI.EndChangeCheck()) { SceneView.RepaintAll(); } // Add Button if (GUILayout.Button(new GUIContent(". Add .", "Adds a child to the transform."), EditorStyles.miniButtonLeft, GUILayout.Width("Add".GetWidth(EditorStyles.miniFont) + 12))) { foreach (Transform t in Selection.transforms) { Undo.RegisterCreatedObjectUndo(t.AddChild("New Child").gameObject, "New Child"); EditorUtility.SetDirty(t); } } // Sort Button if (GUILayout.Button(new GUIContent(". Sort .", "Sorts the immediate children of the transform alphabetically."), EditorStyles.miniButtonRight, GUILayout.Width("Sort".GetWidth(EditorStyles.miniFont) + 12))) { Undo.RegisterCompleteObjectUndo(targets, "Transform Sort"); foreach (Transform t in Selection.transforms) { t.SortChildren(); EditorUtility.SetDirty(t); } } EditorGUILayout.EndHorizontal(); }