private void SavePreset(Preset preset) { if (preset == null) { preset = new Preset(); } preset.Name = this.ParentSection.Name; preset.Abbreviation = this.ParentSection.Abbreviation; preset.ReadoutNames = this.ParentSection.ReadoutModuleNames; preset.IsHud = this.ParentSection.IsHud; preset.IsHudBackground = this.ParentSection.IsHudBackground; PresetLibrary.Save(preset); }
private void DrawPresets(Rect position, PresetLibrary curveLibrary) { if (!(curveLibrary == null) && curveLibrary.Count() != 0) { int num = curveLibrary.Count(); int num2 = Mathf.Min(num, 9); float num3 = (float)num2 * 30f + (float)(num2 - 1) * 10f; float num4 = (position.get_width() - num3) * 0.5f; float num5 = (position.get_height() - 15f) * 0.5f; float num6 = 3f; if (num4 > 0f) { num6 = num4; } GUI.BeginGroup(position); for (int i = 0; i < num2; i++) { if (i > 0) { num6 += 10f; } Rect rect = new Rect(num6, num5, 30f, 15f); this.m_TextContent.set_tooltip(curveLibrary.GetName(i)); if (GUI.Button(rect, this.m_TextContent, GUIStyle.get_none())) { IEnumerable <CurveWrapper> enumerable = this.m_CurveWrappers; if (this.m_CurveWrappers.Length > 1) { enumerable = from x in this.m_CurveWrappers where x.selected == 1 select x; } foreach (CurveWrapper current in enumerable) { AnimationCurve animationCurve = (AnimationCurve)curveLibrary.GetPreset(i); current.get_curve().set_keys((Keyframe[])animationCurve.get_keys().Clone()); current.set_changed(true); } } if (Event.get_current().get_type() == 7) { curveLibrary.Draw(rect, i); } num6 += 30f; } GUI.EndGroup(); } }
/// <summary> /// Draws the preset list drop down UI. /// </summary> private void DrawPresets() { Preset removePreset = null; foreach (var preset in PresetLibrary.Presets) { GUILayout.BeginHorizontal(); this.DrawPresetButton(preset); if (GUILayout.Button("<b>X</b>", this.categoryButtonStyle, GUILayout.Width(30.0f))) { removePreset = preset; } GUILayout.EndHorizontal(); } if (removePreset != null && PresetLibrary.Remove(removePreset)) { this.presetList.Resize = true; } this.DrawPresetSaveButton(); }
void DrawPresets(Rect position, PresetLibrary curveLibrary) { if (curveLibrary == null || curveLibrary.Count() == 0) { return; } const int maxNumPresets = 9; int numPresets = curveLibrary.Count(); int showNumPresets = Mathf.Min(numPresets, maxNumPresets); const float swatchWidth = 30; const float swatchHeight = 15; const float spaceBetweenSwatches = 10; float presetButtonsWidth = showNumPresets * swatchWidth + (showNumPresets - 1) * spaceBetweenSwatches; float flexWidth = (position.width - presetButtonsWidth) * 0.5f; // Preset swatch area float curY = (position.height - swatchHeight) * 0.5f; float curX = 3.0f; if (flexWidth > 0) { curX = flexWidth; } GUI.BeginGroup(position); for (int i = 0; i < showNumPresets; i++) { if (i > 0) { curX += spaceBetweenSwatches; } var swatchRect = new Rect(curX, curY, swatchWidth, swatchHeight); m_TextContent.tooltip = curveLibrary.GetName(i); if (GUI.Button(swatchRect, m_TextContent, GUIStyle.none)) { // if there is only 1, no need to specify IEnumerable <CurveWrapper> wrappers = m_CurveWrappers; if (m_CurveWrappers.Length > 1) { wrappers = m_CurveWrappers.Where(x => x.selected == CurveWrapper.SelectionMode.Selected); } foreach (var wrapper in wrappers) { var presetCurve = (AnimationCurve)curveLibrary.GetPreset(i); wrapper.curve.keys = (Keyframe[])presetCurve.keys.Clone(); wrapper.changed = true; } // case 1259902 - flushes internal selection caches preventing index out of range exceptions m_CurveEditor.SelectNone(); foreach (var wrapper in wrappers) { wrapper.selected = CurveWrapper.SelectionMode.Selected; } } if (Event.current.type == EventType.Repaint) { curveLibrary.Draw(swatchRect, i); } curX += swatchWidth; } GUI.EndGroup(); }