private void DrawLODLevelSlider(Rect sliderPosition, List <LODGroupGUI.LODInfo> lods)
        {
            int   controlID = GUIUtility.GetControlID(this.m_LODSliderId, FocusType.Passive);
            Event current   = Event.current;

            switch (current.GetTypeForControl(controlID))
            {
            case EventType.MouseDown:
            {
                Rect rect = sliderPosition;
                rect.x     -= 5f;
                rect.width += 10f;
                if (rect.Contains(current.mousePosition))
                {
                    current.Use();
                    GUIUtility.hotControl = controlID;
                    bool flag = false;
                    IOrderedEnumerable <LODGroupGUI.LODInfo> collection = from lod in lods
                                                                          where lod.ScreenPercent > 0.5f
                                                                          select lod into x
                                                                          orderby x.LODLevel descending
                                                                          select x;
                    IOrderedEnumerable <LODGroupGUI.LODInfo> collection2 = from lod in lods
                                                                           where lod.ScreenPercent <= 0.5f
                                                                           select lod into x
                                                                           orderby x.LODLevel
                                                                           select x;
                    List <LODGroupGUI.LODInfo> list = new List <LODGroupGUI.LODInfo>();
                    list.AddRange(collection);
                    list.AddRange(collection2);
                    foreach (LODGroupGUI.LODInfo current2 in list)
                    {
                        if (current2.m_ButtonPosition.Contains(current.mousePosition))
                        {
                            this.m_SelectedLODSlider = current2.LODLevel;
                            this.m_SelectedLODRange  = current2.LODLevel;
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        foreach (LODGroupGUI.LODInfo current3 in list)
                        {
                            if (current3.m_RangePosition.Contains(current.mousePosition))
                            {
                                this.m_SelectedLODSlider = -1;
                                this.m_SelectedLODRange  = current3.LODLevel;
                                break;
                            }
                        }
                    }
                }
                break;
            }

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID)
                {
                    GUIUtility.hotControl = 0;
                    current.Use();
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID && this.m_SelectedLODSlider >= 0 && lods[this.m_SelectedLODSlider] != null)
                {
                    current.Use();
                    float cameraPercent = LODGroupGUI.GetCameraPercent(current.mousePosition, sliderPosition);
                    LODGroupGUI.SetSelectedLODLevelPercentage(cameraPercent - 0.001f, this.m_SelectedLODSlider, lods);
                    this.m_LODSettings.GetArrayElementAtIndex(this.m_SelectedLODSlider).FindPropertyRelative("height").floatValue = lods[this.m_SelectedLODSlider].RawScreenPercent;
                }
                break;

            case EventType.Repaint:
                LODGroupGUI.DrawLODSlider(sliderPosition, lods, this.m_SelectedLODRange);
                break;
            }
        }
Exemple #2
0
        private void DrawLODLevelSlider(Rect sliderPosition, List <LODGroupGUI.LODInfo> lods)
        {
            int   sliderId = GUIUtility.GetControlID(m_LODSliderId, FocusType.Passive);
            Event evt      = Event.current;

            switch (evt.GetTypeForControl(sliderId))
            {
            case EventType.Repaint:
            {
                LODGroupGUI.DrawLODSlider(sliderPosition, lods, m_SelectedLODRange);
                break;
            }

            case EventType.MouseDown:
            {
                // Slightly grow position on the x because edge buttons overflow by 5 pixels
                var barPosition = sliderPosition;
                barPosition.x     -= 5;
                barPosition.width += 10;

                if (barPosition.Contains(evt.mousePosition))
                {
                    evt.Use();
                    GUIUtility.hotControl = sliderId;

                    // Check for button click
                    var clickedButton = false;

                    // case:464019 have to re-sort the LOD array for these buttons to get the overlaps in the right order...
                    var lodsLeft  = lods.Where(lod => lod.ScreenPercent > 0.5f).OrderByDescending(x => x.LODLevel);
                    var lodsRight = lods.Where(lod => lod.ScreenPercent <= 0.5f).OrderBy(x => x.LODLevel);

                    var lodButtonOrder = new List <LODGroupGUI.LODInfo>();
                    lodButtonOrder.AddRange(lodsLeft);
                    lodButtonOrder.AddRange(lodsRight);

                    foreach (var lod in lodButtonOrder)
                    {
                        if (lod.m_ButtonPosition.Contains(evt.mousePosition))
                        {
                            m_SelectedLODSlider = lod.LODLevel;
                            m_SelectedLODRange  = lod.LODLevel;
                            clickedButton       = true;
                            break;
                        }
                    }

                    if (!clickedButton)
                    {
                        // Check for range click
                        foreach (var lod in lodButtonOrder)
                        {
                            if (lod.m_RangePosition.Contains(evt.mousePosition))
                            {
                                m_SelectedLODSlider = -1;
                                m_SelectedLODRange  = lod.LODLevel;
                                break;
                            }
                        }
                    }
                }
                break;
            }

            case EventType.MouseUp:
            {
                if (GUIUtility.hotControl == sliderId)
                {
                    GUIUtility.hotControl = 0;
                    evt.Use();
                }
                break;
            }

            case EventType.MouseDrag:
            {
                if (GUIUtility.hotControl == sliderId && m_SelectedLODSlider >= 0 && lods[m_SelectedLODSlider] != null)
                {
                    evt.Use();

                    var cameraPercent = LODGroupGUI.GetCameraPercent(evt.mousePosition, sliderPosition);
                    // Bias by 0.1% so that there is no skipping when sliding
                    LODGroupGUI.SetSelectedLODLevelPercentage(cameraPercent - 0.001f, m_SelectedLODSlider, lods);
                    m_LODSettings.GetArrayElementAtIndex(m_SelectedLODSlider).FindPropertyRelative("height").floatValue = lods[m_SelectedLODSlider].RawScreenPercent;
                }
                break;
            }
            }
        }
        private void DrawLODLevelSlider(Rect sliderPosition, List <LODGroupGUI.LODInfo> lods)
        {
            int   controlId = GUIUtility.GetControlID(this.m_LODSliderId, FocusType.Passive);
            Event current1  = Event.current;

            switch (current1.GetTypeForControl(controlId))
            {
            case EventType.MouseDown:
                Rect rect = sliderPosition;
                rect.x     -= 5f;
                rect.width += 10f;
                if (!rect.Contains(current1.mousePosition))
                {
                    break;
                }
                current1.Use();
                GUIUtility.hotControl = controlId;
                IOrderedEnumerable <LODGroupGUI.LODInfo> orderedEnumerable1 = lods.Where <LODGroupGUI.LODInfo>((Func <LODGroupGUI.LODInfo, bool>)(lod => (double)lod.ScreenPercent > 0.5)).OrderByDescending <LODGroupGUI.LODInfo, int>((Func <LODGroupGUI.LODInfo, int>)(x => x.LODLevel));
                IOrderedEnumerable <LODGroupGUI.LODInfo> orderedEnumerable2 = lods.Where <LODGroupGUI.LODInfo>((Func <LODGroupGUI.LODInfo, bool>)(lod => (double)lod.ScreenPercent <= 0.5)).OrderBy <LODGroupGUI.LODInfo, int>((Func <LODGroupGUI.LODInfo, int>)(x => x.LODLevel));
                List <LODGroupGUI.LODInfo> lodInfoList = new List <LODGroupGUI.LODInfo>();
                lodInfoList.AddRange((IEnumerable <LODGroupGUI.LODInfo>)orderedEnumerable1);
                lodInfoList.AddRange((IEnumerable <LODGroupGUI.LODInfo>)orderedEnumerable2);
                using (List <LODGroupGUI.LODInfo> .Enumerator enumerator = lodInfoList.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        LODGroupGUI.LODInfo current2 = enumerator.Current;
                        if (current2.m_ButtonPosition.Contains(current1.mousePosition))
                        {
                            this.m_SelectedLODSlider = current2.LODLevel;
                            this.m_SelectedLODRange  = current2.LODLevel;
                            break;
                        }
                        if (current2.m_RangePosition.Contains(current1.mousePosition))
                        {
                            this.m_SelectedLODSlider = -1;
                            this.m_SelectedLODRange  = current2.LODLevel;
                            break;
                        }
                    }
                    break;
                }

            case EventType.MouseUp:
                if (GUIUtility.hotControl != controlId)
                {
                    break;
                }
                GUIUtility.hotControl = 0;
                current1.Use();
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl != controlId || this.m_SelectedLODSlider < 0 || lods[this.m_SelectedLODSlider] == null)
                {
                    break;
                }
                current1.Use();
                LODGroupGUI.SetSelectedLODLevelPercentage(Mathf.Clamp01((float)(1.0 - ((double)current1.mousePosition.x - (double)sliderPosition.x) / (double)sliderPosition.width)) - 1f / 1000f, this.m_SelectedLODSlider, lods);
                this.m_LODSettings.GetArrayElementAtIndex(this.m_SelectedLODSlider).FindPropertyRelative("height").floatValue = lods[this.m_SelectedLODSlider].RawScreenPercent;
                break;

            case EventType.Repaint:
                LODGroupGUI.DrawLODSlider(sliderPosition, (IList <LODGroupGUI.LODInfo>)lods, this.m_SelectedLODRange);
                break;
            }
        }