Esempio n. 1
0
        private void DoPointInspector()
        {
            ISelection selection = ShapeEditorCache.GetSelection();

            List <Vector3> positions     = new List <Vector3>();
            List <float>   heights       = new List <float>();
            List <float>   bevelCutoffs  = new List <float>();
            List <float>   bevelSizes    = new List <float>();
            List <int>     spriteIndices = new List <int>();
            List <bool>    corners       = new List <bool>();

            foreach (int index in selection)
            {
                positions.Add(m_Spline.GetPosition(index));
                heights.Add(m_Spline.GetHeight(index));
                bevelCutoffs.Add(m_Spline.GetBevelCutoff(index));
                bevelSizes.Add(m_Spline.GetBevelSize(index));
                spriteIndices.Add(m_Spline.GetSpriteIndex(index));
                corners.Add(m_Spline.GetCorner(index));
            }

            EditorGUIUtility.wideMode = true;

            EditorGUI.BeginChangeCheck();

            positions = MultiVector2Field(Contents.positionLabel, positions, 1.5f);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(m_CurrentEditor.target, "Undo Inspector");

                for (int index = 0; index < positions.Count; index++)
                {
                    m_Spline.SetPosition(selection.ElementAt(index), positions[index]);
                }
                SceneView.RepaintAll();
            }

            EditorGUIUtility.wideMode = false;

            bool mixedValue = EditorGUI.showMixedValue;

            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = !heights.All(v => Mathf.Approximately(v, heights.First()));
            float height = EditorGUILayout.Slider(Contents.heightLabel, heights[0], 0.1f, 2.0f);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(m_CurrentEditor.target, "Undo Inspector");

                foreach (int index in selection)
                {
                    m_Spline.SetHeight(index, height);
                }
            }

            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = !bevelCutoffs.All(v => Mathf.Approximately(v, bevelCutoffs.First()));
            float cornerTolerance = EditorGUILayout.Slider(Contents.bevelCutoffLabel, bevelCutoffs[0], 0, 180.0f);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(m_CurrentEditor.target, "Undo Inspector");

                foreach (int index in selection)
                {
                    m_Spline.SetBevelCutoff(index, cornerTolerance);
                }
            }

            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = !bevelSizes.All(v => Mathf.Approximately(v, bevelSizes.First()));
            float bevelLength = EditorGUILayout.Slider(Contents.bevelSizeLabel, bevelSizes[0], 0.0f, 0.5f);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(m_CurrentEditor.target, "Undo Inspector");

                foreach (int index in selection)
                {
                    m_Spline.SetBevelSize(index, bevelLength);
                }
            }

            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = !spriteIndices.All(v => (v == spriteIndices.First()));
            int spriteIndex = EditorGUILayout.IntSlider(Contents.spriteIndexLabel, spriteIndices[0], 0, 63);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(m_CurrentEditor.target, "Undo Inspector");

                foreach (int index in selection)
                {
                    m_Spline.SetSpriteIndex(index, spriteIndex);
                }
            }

            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = !corners.All(v => (v == corners.First()));
            int val = (int)EditorGUILayout.IntPopup(Contents.cornerLabel, corners[0] ? 1 : 0, Contents.cornerOptions, Contents.cornerValues);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(m_CurrentEditor.target, "Undo Inspector");

                foreach (int index in selection)
                {
                    m_Spline.SetCorner(index, (val > 0) ? true : false);
                }
            }

            EditorGUI.showMixedValue = mixedValue;
        }