Exemple #1
0
        public override void OnEnable()
        {
            base.OnEnable();

            transform = (Transform)target;
            SnapSettings.CleanUp();
        }
Exemple #2
0
        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()))
            {
                for (int i = 0; i < Selection.transforms.Length; i++)
                {
                    Transform selectedTransform = Selection.transforms[i];
                    SnapSettings.SetValue("Toggle" + buttonLabel + selectedTransform.GetInstanceID(), pressed);
                    EditorUtility.SetDirty(selectedTransform);
                }
            }

            EditorGUILayout.EndVertical();

            return(SnapSettings.GetValue <bool>("Toggle" + buttonLabel + transform.GetInstanceID()));
        }
Exemple #3
0
        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");

                for (int i = 0; i < Selection.transforms.Length; i++)
                {
                    Transform selectedTransform = Selection.transforms[i];
                    selectedTransform.Reset();
                    SnapSettings.DeleteKey("Toggle" + "Snap" + selectedTransform.GetInstanceID());
                    SnapSettings.DeleteKey("Toggle" + "Grid" + selectedTransform.GetInstanceID());
                    EditorUtility.SetDirty(selectedTransform);
                    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)))
            {
                for (int i = 0; i < Selection.transforms.Length; i++)
                {
                    Transform selectedTransform = Selection.transforms[i];
                    Undo.RegisterCreatedObjectUndo(selectedTransform.AddChild("New Child").gameObject, "New Child");
                    EditorUtility.SetDirty(selectedTransform);
                }
            }

            // 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");

                for (int i = 0; i < Selection.transforms.Length; i++)
                {
                    Transform selectedTransform = Selection.transforms[i];
                    selectedTransform.SortChildren();
                    EditorUtility.SetDirty(selectedTransform);
                }
            }

            EditorGUILayout.EndHorizontal();
        }
Exemple #4
0
 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");
 }