Esempio n. 1
0
        protected override void OnEnable()
        {
            base.OnEnable();

            rootVisualElement.styleSheets.Add((StyleSheet)EditorGUIUtility.Load("StyleSheets/SceneViewToolbarElements/SnapWindowsCommon.uss"));
            rootVisualElement.Add(new SnapSettingsHeader(L10n.Tr("Increment Snapping"), ResetValues));

            // Move
            m_MoveLinkedField = new LinkedVector3Field(L10n.Tr("Move"))
            {
                name = "Move"
            };
            m_MoveLinkedField.value  = EditorSnapSettings.move;
            m_MoveLinkedField.linked = Mathf.Approximately(m_MoveLinkedField.value.x, m_MoveLinkedField.value.y) &&
                                       Mathf.Approximately(m_MoveLinkedField.value.x, m_MoveLinkedField.value.z);
            rootVisualElement.Add(m_MoveLinkedField);

            EditorSnapSettings.moveChanged += (value) => m_MoveLinkedField.SetValueWithoutNotify(value);
            m_MoveLinkedField.RegisterValueChangedCallback(OnMoveValueChanged);

            // Rotate
            var rotate = new FloatField(L10n.Tr("Rotate"))
            {
                name = "Rotate"
            };

            rotate.value = EditorSnapSettings.rotate;
            rootVisualElement.Add(rotate);

            EditorSnapSettings.rotateChanged += (value) => rotate.SetValueWithoutNotify(value);
            rotate.RegisterValueChangedCallback(evt =>
            {
                EditorSnapSettings.rotate = evt.newValue;
                EditorSnapSettings.Save();
            });

            // Scale
            var scale = new FloatField(L10n.Tr("Scale"))
            {
                name = "Scale"
            };

            scale.value = EditorSnapSettings.scale;
            rootVisualElement.Add(scale);

            EditorSnapSettings.scaleChanged += (value) => scale.SetValueWithoutNotify(value);
            scale.RegisterValueChangedCallback(evt =>
            {
                EditorSnapSettings.scale = evt.newValue;
                EditorSnapSettings.Save();
            });
        }
Esempio n. 2
0
        protected override void OnEnable()
        {
            base.OnEnable();

            rootVisualElement.styleSheets.Add((StyleSheet)EditorGUIUtility.Load("StyleSheets/SceneViewToolbarElements/SnapWindowsCommon.uss"));

            rootVisualElement.Add(new SnapSettingsHeader(L10n.Tr("Grid Snapping"), ResetValues));

            m_GridSize = new LinkedVector3Field(L10n.Tr("Grid Size"))
            {
                name = "GridSize"
            };
            m_GridSize.value          = GridSettings.size;
            m_GridSize.linked         = Mathf.Approximately(m_GridSize.value.x, m_GridSize.value.y) && Mathf.Approximately(m_GridSize.value.x, m_GridSize.value.z);
            GridSettings.sizeChanged += (value) => m_GridSize.SetValueWithoutNotify(value);
            m_GridSize.RegisterValueChangedCallback(OnGridSizeChanged);
            rootVisualElement.Add(m_GridSize);

            // Align Selected
            var alignSelected = new VisualElement()
            {
                name = "AlignSelected"
            };

            alignSelected.style.flexDirection = FlexDirection.Row;

            alignSelected.Add(new Label(L10n.Tr("Align Selected")));

            var allAxis = new Button()
            {
                name = "AllAxes", text = L10n.Tr("All Axes")
            };

            allAxis.clicked += () =>
            {
                SnapSelectionToGrid();
            };

            var x = new Button()
            {
                name = "X", text = L10n.Tr("X")
            };

            x.clicked += () =>
            {
                SnapSelectionToGrid(SnapAxis.X);
            };

            var y = new Button()
            {
                name = "Y", text = L10n.Tr("Y")
            };

            y.clicked += () =>
            {
                SnapSelectionToGrid(SnapAxis.Y);
            };

            var z = new Button()
            {
                name = "Z", text = L10n.Tr("Z")
            };

            z.clicked += () =>
            {
                SnapSelectionToGrid(SnapAxis.Z);
            };

            alignSelected.Add(allAxis);
            alignSelected.Add(x);
            alignSelected.Add(y);
            alignSelected.Add(z);
            rootVisualElement.Add(alignSelected);
        }