コード例 #1
0
        protected Color GetColor(NamedFace name, Element element)
        {
            switch (element)
            {
            default:
            case Element.Face: return(faceColors[monochromeFace ? 0 : (int)name]);

            case Element.SelectedFace: return(faceColorsSelected[monochromeSelectedFace ? 0 : (int)name]);

            case Element.Handle: return(handleColors[monochromeHandle ? 0 : (int)name]);
            }
        }
コード例 #2
0
        public void DrawHandle()
        {
            for (int i = 0, count = m_ControlIDs.Length; i < count; ++i)
            {
                m_ControlIDs[i] = GUIUtility.GetControlID(GetHashCode(), FocusType.Passive);
            }

            EditorGUI.BeginChangeCheck();

            Vector3 leftPosition   = center + size.x * .5f * Vector3.left;
            Vector3 rightPosition  = center + size.x * .5f * Vector3.right;
            Vector3 topPosition    = center + size.y * .5f * Vector3.up;
            Vector3 bottomPosition = center + size.y * .5f * Vector3.down;
            Vector3 frontPosition  = center + size.z * .5f * Vector3.forward;
            Vector3 backPosition   = center + size.z * .5f * Vector3.back;

            float     snapScale      = (float)k_scale.GetValue(null, null);
            NamedFace theChangedFace = NamedFace.None;

            EditorGUI.BeginChangeCheck();
            Slider1D(m_ControlIDs[(int)NamedFace.Left], ref leftPosition, Vector3.left, snapScale, GetColor(NamedFace.Left, Element.Handle));
            if (EditorGUI.EndChangeCheck() && allHandleControledByOne)
            {
                theChangedFace = NamedFace.Left;
            }

            EditorGUI.BeginChangeCheck();
            using (new Handles.DrawingScope(GetColor(NamedFace.Right, Element.Handle)))
                Slider1D(m_ControlIDs[(int)NamedFace.Right], ref rightPosition, Vector3.right, snapScale, GetColor(NamedFace.Right, Element.Handle));
            if (EditorGUI.EndChangeCheck() && allHandleControledByOne)
            {
                theChangedFace = NamedFace.Right;
            }

            EditorGUI.BeginChangeCheck();
            Slider1D(m_ControlIDs[(int)NamedFace.Top], ref topPosition, Vector3.up, snapScale, GetColor(NamedFace.Top, Element.Handle));
            if (EditorGUI.EndChangeCheck() && allHandleControledByOne)
            {
                theChangedFace = NamedFace.Top;
            }

            EditorGUI.BeginChangeCheck();
            Slider1D(m_ControlIDs[(int)NamedFace.Bottom], ref bottomPosition, Vector3.down, snapScale, GetColor(NamedFace.Bottom, Element.Handle));
            if (EditorGUI.EndChangeCheck() && allHandleControledByOne)
            {
                theChangedFace = NamedFace.Bottom;
            }

            EditorGUI.BeginChangeCheck();
            Slider1D(m_ControlIDs[(int)NamedFace.Front], ref frontPosition, Vector3.forward, snapScale, GetColor(NamedFace.Front, Element.Handle));
            if (EditorGUI.EndChangeCheck() && allHandleControledByOne)
            {
                theChangedFace = NamedFace.Front;
            }

            EditorGUI.BeginChangeCheck();
            Slider1D(m_ControlIDs[(int)NamedFace.Back], ref backPosition, Vector3.back, snapScale, GetColor(NamedFace.Back, Element.Handle));
            if (EditorGUI.EndChangeCheck() && allHandleControledByOne)
            {
                theChangedFace = NamedFace.Back;
            }

            if (EditorGUI.EndChangeCheck())
            {
                if (allHandleControledByOne)
                {
                    float decal = 0f;
                    switch (theChangedFace)
                    {
                    case NamedFace.Left:
                        decal = (leftPosition - center - size.x * .5f * Vector3.left).x;
                        break;

                    case NamedFace.Right:
                        decal = -(rightPosition - center - size.x * .5f * Vector3.right).x;
                        break;

                    case NamedFace.Top:
                        decal = -(topPosition - center - size.y * .5f * Vector3.up).y;
                        break;

                    case NamedFace.Bottom:
                        decal = (bottomPosition - center - size.y * .5f * Vector3.down).y;
                        break;

                    case NamedFace.Front:
                        decal = -(frontPosition - center - size.z * .5f * Vector3.forward).z;
                        break;

                    case NamedFace.Back:
                        decal = (backPosition - center - size.z * .5f * Vector3.back).z;
                        break;
                    }

                    Vector3 tempSize = size - Vector3.one * decal;
                    for (int axis = 0; axis < 3; ++axis)
                    {
                        if (tempSize[axis] < 0)
                        {
                            decal   += tempSize[axis];
                            tempSize = size - Vector3.one * decal;
                        }
                    }

                    size = tempSize;
                }
                else
                {
                    Vector3 max = new Vector3(rightPosition.x, topPosition.y, frontPosition.z);
                    Vector3 min = new Vector3(leftPosition.x, bottomPosition.y, backPosition.z);

                    //ensure that the box face are still facing outside
                    for (int axis = 0; axis < 3; ++axis)
                    {
                        if (min[axis] > max[axis])
                        {
                            if (GUIUtility.hotControl == m_ControlIDs[axis])
                            {
                                max[axis] = min[axis];
                            }
                            else
                            {
                                min[axis] = max[axis];
                            }
                        }
                    }

                    center = (max + min) * .5f;
                    size   = max - min;
                }
            }
        }
コード例 #3
0
 Color GetHandleColor(NamedFace name)
 {
     return(monoHandle ? m_MonochromeHandleColor : m_PolychromeHandleColor[(int)name]);
 }