Beispiel #1
0
        public static Rect GetCulledBox(Rect totalRect, float previousLODPercentage)
        {
            Rect result = LODGroupGUI.CalcLODRange(totalRect, previousLODPercentage, 0f);

            result.height -= 2f;
            result.width  -= 1f;
            result.center += new Vector2(0f, 1f);
            return(result);
        }
Beispiel #2
0
        internal List <LODGroupGUI.LODInfo> GetLODInfoArray(Rect area)
        {
            int lodCount = m_LODSettings.arraySize;

            return(LODGroupGUI.CreateLODInfos(
                       lodCount, area,
                       i => i == lodCount - 1 && (target as SpeedTreeImporter).hasBillboard ? "Billboard" : String.Format("LOD {0}", i),
                       i => m_LODSettings.GetArrayElementAtIndex(i).FindPropertyRelative("height").floatValue));
        }
 public static void DrawLODSlider(Rect area, IList <LODGroupGUI.LODInfo> lods, int selectedLevel)
 {
     LODGroupGUI.Styles.m_LODSliderBG.Draw(area, GUIContent.none, false, false, false, false);
     for (int i = 0; i < lods.Count; i++)
     {
         LODGroupGUI.LODInfo currentLOD = lods[i];
         LODGroupGUI.DrawLODRange(currentLOD, (i != 0) ? lods[i - 1].RawScreenPercent : 1f, i == selectedLevel);
         LODGroupGUI.DrawLODButton(currentLOD);
     }
     LODGroupGUI.DrawCulledRange(area, (lods.Count <= 0) ? 1f : lods[lods.Count - 1].RawScreenPercent);
 }
 public static void DrawLODSlider(Rect area, IList <LODGroupGUI.LODInfo> lods, int selectedLevel)
 {
     LODGroupGUI.Styles.m_LODSliderBG.Draw(area, GUIContent.none, false, false, false, false);
     for (int index = 0; index < lods.Count; ++index)
     {
         LODGroupGUI.LODInfo lod = lods[index];
         LODGroupGUI.DrawLODRange(lod, index != 0 ? lods[index - 1].RawScreenPercent : 1f, index == selectedLevel);
         LODGroupGUI.DrawLODButton(lod);
     }
     LODGroupGUI.DrawCulledRange(area, lods.Count <= 0 ? 1f : lods[lods.Count - 1].RawScreenPercent);
 }
 private static void DrawCulledRange(Rect totalRect, float previousLODPercentage)
 {
     if (!Mathf.Approximately(previousLODPercentage, 0f))
     {
         Rect  culledBox = LODGroupGUI.GetCulledBox(totalRect, LODGroupGUI.DelinearizeScreenPercentage(previousLODPercentage));
         Color color     = GUI.color;
         GUI.color = LODGroupGUI.kCulledLODColor;
         LODGroupGUI.Styles.m_LODSliderRange.Draw(culledBox, GUIContent.none, false, false, false, false);
         GUI.color = color;
         string text = string.Format("Culled\n{0:0}%", previousLODPercentage * 100f);
         LODGroupGUI.Styles.m_LODSliderText.Draw(culledBox, text, false, false, false, false);
     }
 }
        public static List <LODGroupGUI.LODInfo> CreateLODInfos(int numLODs, Rect area, Func <int, string> nameGen, Func <int, float> heightGen)
        {
            List <LODGroupGUI.LODInfo> lodInfoList = new List <LODGroupGUI.LODInfo>();

            for (int lodLevel = 0; lodLevel < numLODs; ++lodLevel)
            {
                LODGroupGUI.LODInfo lodInfo = new LODGroupGUI.LODInfo(lodLevel, nameGen(lodLevel), heightGen(lodLevel));
                lodInfo.m_ButtonPosition = LODGroupGUI.CalcLODButton(area, lodInfo.ScreenPercent);
                float startPercent = lodLevel != 0 ? lodInfoList[lodLevel - 1].ScreenPercent : 1f;
                lodInfo.m_RangePosition = LODGroupGUI.CalcLODRange(area, startPercent, lodInfo.ScreenPercent);
                lodInfoList.Add(lodInfo);
            }
            return(lodInfoList);
        }
        public static List <LODGroupGUI.LODInfo> CreateLODInfos(int numLODs, Rect area, Func <int, string> nameGen, Func <int, float> heightGen)
        {
            List <LODGroupGUI.LODInfo> list = new List <LODGroupGUI.LODInfo>();

            for (int i = 0; i < numLODs; i++)
            {
                LODGroupGUI.LODInfo lODInfo = new LODGroupGUI.LODInfo(i, nameGen(i), heightGen(i));
                lODInfo.m_ButtonPosition = LODGroupGUI.CalcLODButton(area, lODInfo.ScreenPercent);
                float startPercent = (i != 0) ? list[i - 1].ScreenPercent : 1f;
                lODInfo.m_RangePosition = LODGroupGUI.CalcLODRange(area, startPercent, lODInfo.ScreenPercent);
                list.Add(lODInfo);
            }
            return(list);
        }
 internal List <LODGroupGUI.LODInfo> GetLODInfoArray(Rect area)
 {
     // ISSUE: object of a compiler-generated type is created
     // ISSUE: variable of a compiler-generated type
     SpeedTreeImporterInspector.\u003CGetLODInfoArray\u003Ec__AnonStorey7F arrayCAnonStorey7F = new SpeedTreeImporterInspector.\u003CGetLODInfoArray\u003Ec__AnonStorey7F();
     // ISSUE: reference to a compiler-generated field
     arrayCAnonStorey7F.\u003C\u003Ef__this = this;
     // ISSUE: reference to a compiler-generated field
     arrayCAnonStorey7F.lodCount = this.m_LODSettings.arraySize;
     // ISSUE: reference to a compiler-generated field
     // ISSUE: reference to a compiler-generated method
     // ISSUE: reference to a compiler-generated method
     return(LODGroupGUI.CreateLODInfos(arrayCAnonStorey7F.lodCount, area, new Func <int, string>(arrayCAnonStorey7F.\u003C\u003Em__12E), new Func <int, float>(arrayCAnonStorey7F.\u003C\u003Em__12F)));
 }
        public static void DrawMixedValueLODSlider(Rect area)
        {
            LODGroupGUI.Styles.m_LODSliderBG.Draw(area, GUIContent.none, false, false, false, false);
            Rect  culledBox = LODGroupGUI.GetCulledBox(area, 1f);
            Color color     = GUI.color;

            GUI.color = LODGroupGUI.kLODColors[1] * 0.6f;
            LODGroupGUI.Styles.m_LODSliderRange.Draw(culledBox, GUIContent.none, false, false, false, false);
            GUI.color = color;
            GUIStyle style = new GUIStyle(EditorStyles.whiteLargeLabel)
            {
                alignment = TextAnchor.MiddleCenter
            };

            GUI.Label(area, "---", style);
        }
        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;
            }
        }
 private void ShowLODGUI()
 {
     this.m_ShowSmoothLODOptions.target      = (this.m_EnableSmoothLOD.hasMultipleDifferentValues || this.m_EnableSmoothLOD.boolValue);
     this.m_ShowCrossFadeWidthOptions.target = (this.m_AnimateCrossFading.hasMultipleDifferentValues || !this.m_AnimateCrossFading.boolValue);
     GUILayout.Label(SpeedTreeImporterInspector.Styles.LODHeader, EditorStyles.boldLabel, new GUILayoutOption[0]);
     EditorGUILayout.PropertyField(this.m_EnableSmoothLOD, SpeedTreeImporterInspector.Styles.SmoothLOD, new GUILayoutOption[0]);
     EditorGUI.indentLevel++;
     if (EditorGUILayout.BeginFadeGroup(this.m_ShowSmoothLODOptions.faded))
     {
         EditorGUILayout.PropertyField(this.m_AnimateCrossFading, SpeedTreeImporterInspector.Styles.AnimateCrossFading, new GUILayoutOption[0]);
         if (EditorGUILayout.BeginFadeGroup(this.m_ShowCrossFadeWidthOptions.faded))
         {
             EditorGUILayout.Slider(this.m_BillboardTransitionCrossFadeWidth, 0f, 1f, SpeedTreeImporterInspector.Styles.CrossFadeWidth, new GUILayoutOption[0]);
             EditorGUILayout.Slider(this.m_FadeOutWidth, 0f, 1f, SpeedTreeImporterInspector.Styles.FadeOutWidth, new GUILayoutOption[0]);
         }
         EditorGUILayout.EndFadeGroup();
     }
     EditorGUILayout.EndFadeGroup();
     EditorGUI.indentLevel--;
     EditorGUILayout.Space();
     if (this.HasSameLODConfig())
     {
         EditorGUILayout.Space();
         Rect rect = GUILayoutUtility.GetRect(0f, 30f, new GUILayoutOption[]
         {
             GUILayout.ExpandWidth(true)
         });
         List <LODGroupGUI.LODInfo> lODInfoArray = this.GetLODInfoArray(rect);
         this.DrawLODLevelSlider(rect, lODInfoArray);
         EditorGUILayout.Space();
         EditorGUILayout.Space();
         if (this.m_SelectedLODRange != -1 && lODInfoArray.Count > 0)
         {
             EditorGUILayout.LabelField(lODInfoArray[this.m_SelectedLODRange].LODName + " Options", EditorStyles.boldLabel, new GUILayoutOption[0]);
             bool flag = this.m_SelectedLODRange == lODInfoArray.Count - 1 && this.importers[0].hasBillboard;
             EditorGUILayout.PropertyField(this.m_LODSettings.GetArrayElementAtIndex(this.m_SelectedLODRange).FindPropertyRelative("castShadows"), SpeedTreeImporterInspector.Styles.CastShadows, new GUILayoutOption[0]);
             EditorGUILayout.PropertyField(this.m_LODSettings.GetArrayElementAtIndex(this.m_SelectedLODRange).FindPropertyRelative("receiveShadows"), SpeedTreeImporterInspector.Styles.ReceiveShadows, new GUILayoutOption[0]);
             SerializedProperty serializedProperty = this.m_LODSettings.GetArrayElementAtIndex(this.m_SelectedLODRange).FindPropertyRelative("useLightProbes");
             EditorGUILayout.PropertyField(serializedProperty, SpeedTreeImporterInspector.Styles.UseLightProbes, new GUILayoutOption[0]);
             if (!serializedProperty.hasMultipleDifferentValues && serializedProperty.boolValue && flag)
             {
                 EditorGUILayout.HelpBox("Enabling Light Probe for billboards breaks batched rendering and may cause performance problem.", MessageType.Warning);
             }
             EditorGUILayout.PropertyField(this.m_LODSettings.GetArrayElementAtIndex(this.m_SelectedLODRange).FindPropertyRelative("enableBump"), SpeedTreeImporterInspector.Styles.EnableBump, new GUILayoutOption[0]);
             EditorGUILayout.PropertyField(this.m_LODSettings.GetArrayElementAtIndex(this.m_SelectedLODRange).FindPropertyRelative("enableHue"), SpeedTreeImporterInspector.Styles.EnableHue, new GUILayoutOption[0]);
             int num = this.importers.Min((SpeedTreeImporter im) => im.bestWindQuality);
             if (num > 0)
             {
                 if (flag)
                 {
                     num = ((num < 1) ? 0 : 1);
                 }
                 EditorGUILayout.Popup(this.m_LODSettings.GetArrayElementAtIndex(this.m_SelectedLODRange).FindPropertyRelative("windQuality"), (from s in SpeedTreeImporter.windQualityNames.Take(num + 1)
                                                                                                                                                select new GUIContent(s)).ToArray <GUIContent>(), SpeedTreeImporterInspector.Styles.WindQuality, new GUILayoutOption[0]);
             }
         }
     }
     else
     {
         if (this.CanUnifyLODConfig())
         {
             EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
             GUILayout.FlexibleSpace();
             Rect rect2 = GUILayoutUtility.GetRect(SpeedTreeImporterInspector.Styles.ResetLOD, EditorStyles.miniButton);
             if (GUI.Button(rect2, SpeedTreeImporterInspector.Styles.ResetLOD, EditorStyles.miniButton))
             {
                 GenericMenu genericMenu = new GenericMenu();
                 foreach (SpeedTreeImporter current in base.targets.Cast <SpeedTreeImporter>())
                 {
                     string text = string.Format("{0}: {1}", Path.GetFileNameWithoutExtension(current.assetPath), string.Join(" | ", (from height in current.LODHeights
                                                                                                                                      select string.Format("{0:0}%", height * 100f)).ToArray <string>()));
                     genericMenu.AddItem(new GUIContent(text), false, new GenericMenu.MenuFunction2(this.OnResetLODMenuClick), current);
                 }
                 genericMenu.DropDown(rect2);
             }
             EditorGUILayout.EndHorizontal();
         }
         Rect rect3 = GUILayoutUtility.GetRect(0f, 30f, new GUILayoutOption[]
         {
             GUILayout.ExpandWidth(true)
         });
         if (Event.current.type == EventType.Repaint)
         {
             LODGroupGUI.DrawMixedValueLODSlider(rect3);
         }
     }
     EditorGUILayout.Space();
 }
        internal List <LODGroupGUI.LODInfo> GetLODInfoArray(Rect area)
        {
            int lodCount = this.m_LODSettings.arraySize;

            return(LODGroupGUI.CreateLODInfos(lodCount, area, (int i) => (i != lodCount - 1 || !(this.target as SpeedTreeImporter).hasBillboard) ? string.Format("LOD {0}", i) : "Billboard", (int i) => this.m_LODSettings.GetArrayElementAtIndex(i).FindPropertyRelative("height").floatValue));
        }
		private static void DrawLODRange(LODGroupGUI.LODInfo currentLOD, float previousLODPercentage, bool isSelected)
		{
			Color backgroundColor = GUI.backgroundColor;
			string text = string.Format("{0}\n{1:0}%", currentLOD.LODName, previousLODPercentage * 100f);
			if (isSelected)
			{
				Rect rangePosition = currentLOD.m_RangePosition;
				rangePosition.width -= 6f;
				rangePosition.height -= 6f;
				rangePosition.center += new Vector2(3f, 3f);
				LODGroupGUI.Styles.m_LODSliderRangeSelected.Draw(currentLOD.m_RangePosition, GUIContent.none, false, false, false, false);
				GUI.backgroundColor = LODGroupGUI.kLODColors[currentLOD.LODLevel];
				if (rangePosition.width > 0f)
				{
					LODGroupGUI.Styles.m_LODSliderRange.Draw(rangePosition, GUIContent.none, false, false, false, false);
				}
				LODGroupGUI.Styles.m_LODSliderText.Draw(currentLOD.m_RangePosition, text, false, false, false, false);
			}
			else
			{
				GUI.backgroundColor = LODGroupGUI.kLODColors[currentLOD.LODLevel];
				GUI.backgroundColor *= 0.6f;
				LODGroupGUI.Styles.m_LODSliderRange.Draw(currentLOD.m_RangePosition, GUIContent.none, false, false, false, false);
				LODGroupGUI.Styles.m_LODSliderText.Draw(currentLOD.m_RangePosition, text, false, false, false, false);
			}
			GUI.backgroundColor = backgroundColor;
		}
		private static void DrawLODButton(LODGroupGUI.LODInfo currentLOD)
		{
			EditorGUIUtility.AddCursorRect(currentLOD.m_ButtonPosition, MouseCursor.ResizeHorizontal);
		}
        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;
            }
        }
Beispiel #16
0
        private void ShowLODGUI()
        {
            m_ShowSmoothLODOptions.target      = m_EnableSmoothLOD.hasMultipleDifferentValues || m_EnableSmoothLOD.boolValue;
            m_ShowCrossFadeWidthOptions.target = m_AnimateCrossFading.hasMultipleDifferentValues || !m_AnimateCrossFading.boolValue;

            GUILayout.Label(Styles.LODHeader, EditorStyles.boldLabel);

            EditorGUILayout.PropertyField(m_EnableSmoothLOD, Styles.SmoothLOD);

            EditorGUI.indentLevel++;
            if (EditorGUILayout.BeginFadeGroup(m_ShowSmoothLODOptions.faded))
            {
                EditorGUILayout.PropertyField(m_AnimateCrossFading, Styles.AnimateCrossFading);
                if (EditorGUILayout.BeginFadeGroup(m_ShowCrossFadeWidthOptions.faded))
                {
                    EditorGUILayout.Slider(m_BillboardTransitionCrossFadeWidth, 0.0f, 1.0f, Styles.CrossFadeWidth);
                    EditorGUILayout.Slider(m_FadeOutWidth, 0.0f, 1.0f, Styles.FadeOutWidth);
                }
                EditorGUILayout.EndFadeGroup();
            }
            EditorGUILayout.EndFadeGroup();
            EditorGUI.indentLevel--;

            EditorGUILayout.Space();
            if (HasSameLODConfig())
            {
                EditorGUILayout.Space();

                var area = GUILayoutUtility.GetRect(0, LODGroupGUI.kSliderBarHeight, GUILayout.ExpandWidth(true));
                var lods = GetLODInfoArray(area);
                DrawLODLevelSlider(area, lods);

                EditorGUILayout.Space();
                EditorGUILayout.Space();

                if (m_SelectedLODRange != -1 && lods.Count > 0)
                {
                    EditorGUILayout.LabelField(lods[m_SelectedLODRange].LODName + " Options", EditorStyles.boldLabel);
                    bool isBillboard = (m_SelectedLODRange == lods.Count - 1) && importers.First().hasBillboard;

                    EditorGUILayout.PropertyField(m_LODSettings.GetArrayElementAtIndex(m_SelectedLODRange).FindPropertyRelative("castShadows"), Styles.CastShadows);
                    EditorGUILayout.PropertyField(m_LODSettings.GetArrayElementAtIndex(m_SelectedLODRange).FindPropertyRelative("receiveShadows"), Styles.ReceiveShadows);

                    var useLightProbes = m_LODSettings.GetArrayElementAtIndex(m_SelectedLODRange).FindPropertyRelative("useLightProbes");
                    EditorGUILayout.PropertyField(useLightProbes, Styles.UseLightProbes);
                    if (!useLightProbes.hasMultipleDifferentValues && useLightProbes.boolValue && isBillboard)
                    {
                        EditorGUILayout.HelpBox("Enabling Light Probe for billboards breaks batched rendering and may cause performance problem.", MessageType.Warning);
                    }

                    // TODO: reflection probe support when PBS is implemented
                    //EditorGUILayout.PropertyField(m_LODSettings.GetArrayElementAtIndex(m_SelectedLODRange).FindPropertyRelative("useReflectionProbes"), Styles.UseReflectionProbes);

                    EditorGUILayout.PropertyField(m_LODSettings.GetArrayElementAtIndex(m_SelectedLODRange).FindPropertyRelative("enableBump"), Styles.EnableBump);
                    EditorGUILayout.PropertyField(m_LODSettings.GetArrayElementAtIndex(m_SelectedLODRange).FindPropertyRelative("enableHue"), Styles.EnableHue);

                    if (m_AllAreV8)
                    {
                        EditorGUILayout.PropertyField(m_LODSettings.GetArrayElementAtIndex(m_SelectedLODRange).FindPropertyRelative("enableSubsurface"), Styles.EnableSubsurface);
                    }

                    int bestWindQuality = importers.Min(im => im.bestWindQuality);
                    if (bestWindQuality > 0)
                    {
                        if (isBillboard)
                        {
                            bestWindQuality = 1; // billboard has only one level of wind quality
                        }

                        EditorGUILayout.Popup(
                            m_LODSettings.GetArrayElementAtIndex(m_SelectedLODRange).FindPropertyRelative("windQuality"),
                            SpeedTreeImporter.windQualityNames.Take(bestWindQuality + 1).Select(s => new GUIContent(s)).ToArray(),
                            Styles.WindQuality);
                    }
                }
            }
            else
            {
                if (CanUnifyLODConfig())
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();
                    Rect buttonRect = GUILayoutUtility.GetRect(Styles.ResetLOD, EditorStyles.miniButton);
                    if (GUI.Button(buttonRect, Styles.ResetLOD, EditorStyles.miniButton))
                    {
                        var dropDownMenu = new GenericMenu();
                        foreach (var importer in targets.Cast <SpeedTreeImporter>())
                        {
                            var menuText = String.Format("{0}: {1}",
                                                         Path.GetFileNameWithoutExtension(importer.assetPath),
                                                         String.Join(" | ", importer.LODHeights.Select(height => UnityString.Format("{0:0}%", height * 100)).ToArray()));
                            dropDownMenu.AddItem(new GUIContent(menuText), false, OnResetLODMenuClick, importer);
                        }
                        dropDownMenu.DropDown(buttonRect);
                    }
                    EditorGUILayout.EndHorizontal();
                }
                var area = GUILayoutUtility.GetRect(0, LODGroupGUI.kSliderBarHeight, GUILayout.ExpandWidth(true));
                if (Event.current.type == EventType.Repaint)
                {
                    LODGroupGUI.DrawMixedValueLODSlider(area);
                }
            }

            EditorGUILayout.Space();
        }
Beispiel #17
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;
            }
            }
        }
        public static float GetCameraPercent(Vector2 position, Rect sliderRect)
        {
            float percentage = Mathf.Clamp(1f - (position.x - sliderRect.x) / sliderRect.width, 0.01f, 1f);

            return(LODGroupGUI.LinearizeScreenPercentage(percentage));
        }