UnityEditor.ShadowCascadeSplitGUI.HandleCascadeSliderGUI C# (CSharp) Method

HandleCascadeSliderGUI() public static method

public static HandleCascadeSliderGUI ( float &normalizedCascadePartitions ) : void
normalizedCascadePartitions float
return void
        public static void HandleCascadeSliderGUI(ref float[] normalizedCascadePartitions)
        {
            GUILayout.Label("Cascade splits", new GUILayoutOption[0]);
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Height(28f), GUILayout.ExpandWidth(true) };
            Rect position = GUILayoutUtility.GetRect(GUIContent.none, s_CascadeSliderBG, options);
            GUI.Box(position, GUIContent.none);
            float x = position.x;
            float y = position.y + 2f;
            float num3 = position.width - (normalizedCascadePartitions.Length * 2);
            Color color = GUI.color;
            Color backgroundColor = GUI.backgroundColor;
            int index = -1;
            float[] destinationArray = new float[normalizedCascadePartitions.Length + 1];
            Array.Copy(normalizedCascadePartitions, destinationArray, normalizedCascadePartitions.Length);
            destinationArray[destinationArray.Length - 1] = 1f - Enumerable.Sum(normalizedCascadePartitions);
            int controlID = GUIUtility.GetControlID(s_CascadeSliderId, FocusType.Passive);
            Event current = Event.current;
            int activePartition = -1;
            for (int i = 0; i < destinationArray.Length; i++)
            {
                float num8 = destinationArray[i];
                index = (index + 1) % kCascadeColors.Length;
                GUI.backgroundColor = kCascadeColors[index];
                float width = num3 * num8;
                Rect rect2 = new Rect(x, y, width, 24f);
                GUI.Box(rect2, GUIContent.none, s_CascadeSliderBG);
                x += width;
                GUI.color = Color.white;
                Rect rect3 = rect2;
                string t = string.Format("{0}\n{1:F1}%", i, num8 * 100f);
                GUI.Label(rect3, GUIContent.Temp(t, t), s_TextCenteredStyle);
                if (i == (destinationArray.Length - 1))
                {
                    break;
                }
                GUI.backgroundColor = Color.black;
                Rect rect4 = rect2;
                rect4.x = x;
                rect4.width = 2f;
                GUI.Box(rect4, GUIContent.none, s_CascadeSliderBG);
                Rect rect5 = rect4;
                rect5.xMin -= 2f;
                rect5.xMax += 2f;
                if (rect5.Contains(current.mousePosition))
                {
                    activePartition = i;
                }
                if (s_DragCache == null)
                {
                    EditorGUIUtility.AddCursorRect(rect5, MouseCursor.ResizeHorizontal, controlID);
                }
                x += 2f;
            }
            GUI.color = color;
            GUI.backgroundColor = backgroundColor;
            EventType typeForControl = current.GetTypeForControl(controlID);
            if (typeForControl == EventType.MouseDown)
            {
                if (activePartition >= 0)
                {
                    s_DragCache = new DragCache(activePartition, normalizedCascadePartitions[activePartition], current.mousePosition);
                    if (GUIUtility.hotControl == 0)
                    {
                        GUIUtility.hotControl = controlID;
                    }
                    current.Use();
                    if (s_RestoreSceneView == null)
                    {
                        s_RestoreSceneView = SceneView.lastActiveSceneView;
                        if (s_RestoreSceneView != null)
                        {
                            s_OldSceneDrawMode = s_RestoreSceneView.renderMode;
                            s_OldSceneLightingMode = s_RestoreSceneView.m_SceneLighting;
                            s_RestoreSceneView.renderMode = DrawCameraMode.ShadowCascades;
                        }
                    }
                }
            }
            else if (typeForControl == EventType.MouseUp)
            {
                if (GUIUtility.hotControl == controlID)
                {
                    GUIUtility.hotControl = 0;
                    current.Use();
                }
                s_DragCache = null;
                if (s_RestoreSceneView != null)
                {
                    s_RestoreSceneView.renderMode = s_OldSceneDrawMode;
                    s_RestoreSceneView.m_SceneLighting = s_OldSceneLightingMode;
                    s_RestoreSceneView = null;
                }
            }
            else if ((typeForControl == EventType.MouseDrag) && (GUIUtility.hotControl == controlID))
            {
                Vector2 vector = current.mousePosition - s_DragCache.m_LastCachedMousePosition;
                float num10 = vector.x / num3;
                bool flag = (destinationArray[s_DragCache.m_ActivePartition] + num10) > 0f;
                bool flag2 = (destinationArray[s_DragCache.m_ActivePartition + 1] - num10) > 0f;
                if (flag && flag2)
                {
                    s_DragCache.m_NormalizedPartitionSize += num10;
                    normalizedCascadePartitions[s_DragCache.m_ActivePartition] = s_DragCache.m_NormalizedPartitionSize;
                    if (s_DragCache.m_ActivePartition < (normalizedCascadePartitions.Length - 1))
                    {
                        normalizedCascadePartitions[s_DragCache.m_ActivePartition + 1] -= num10;
                    }
                    GUI.changed = true;
                }
                s_DragCache.m_LastCachedMousePosition = current.mousePosition;
                current.Use();
            }
        }

Usage Example

示例#1
0
        private void DrawCascadeSplitGUI <T>(ref SerializedProperty shadowCascadeSplit)
        {
            float[] array          = null;
            Type    typeFromHandle = typeof(T);

            if (typeFromHandle == typeof(float))
            {
                array = new float[]
                {
                    shadowCascadeSplit.floatValue
                };
            }
            else if (typeFromHandle == typeof(Vector3))
            {
                Vector3 vector3Value = shadowCascadeSplit.vector3Value;
                array = new float[]
                {
                    Mathf.Clamp(vector3Value[0], 0f, 1f),
                    Mathf.Clamp(vector3Value[1] - vector3Value[0], 0f, 1f),
                    Mathf.Clamp(vector3Value[2] - vector3Value[1], 0f, 1f)
                };
            }
            if (array != null)
            {
                EditorGUI.BeginChangeCheck();
                ShadowCascadeSplitGUI.HandleCascadeSliderGUI(ref array);
                if (EditorGUI.EndChangeCheck())
                {
                    if (typeFromHandle == typeof(float))
                    {
                        shadowCascadeSplit.floatValue = array[0];
                    }
                    else
                    {
                        Vector3 vector3Value2 = default(Vector3);
                        vector3Value2[0] = array[0];
                        vector3Value2[1] = vector3Value2[0] + array[1];
                        vector3Value2[2] = vector3Value2[1] + array[2];
                        shadowCascadeSplit.vector3Value = vector3Value2;
                    }
                }
            }
        }
All Usage Examples Of UnityEditor.ShadowCascadeSplitGUI::HandleCascadeSliderGUI