/// <summary> /// Get string representation of value and unit. Using current UI culture and two significant digits after radix. /// </summary> /// <param name="unit">Unit representation to use.</param> /// <returns>String representation.</returns> public string ToString(DurationUnit unit) { return(ToString(unit, null, 2)); }
private double ConvertFromNanos(double nanos) { return(nanos / DurationUnit.Convert(1, TimeUnit.Nanoseconds)); }
public static Duration From(double value, DurationUnit fromUnit)
public static string GetAbbreviation(DurationUnit unit) { return(GetAbbreviation(unit, null)); }
/// <summary> /// Dynamically convert from value and unit enum <see cref="DurationUnit" /> to <see cref="Duration" />. /// </summary> /// <param name="value">Value to convert from.</param> /// <param name="fromUnit">Unit to convert from.</param> /// <returns>Duration unit value.</returns> public static Duration?From(QuantityValue?value, DurationUnit fromUnit) { return(value.HasValue ? new Duration((double)value.Value, fromUnit) : default(Duration?)); }
public static string GetAbbreviation( DurationUnit unit, #if WINDOWS_UWP [CanBeNull] string cultureName)
public DurationStruct(int value, DurationUnit unit) { Value = value; Unit = unit; }
/// <summary> /// Get string representation of value and unit. Using two significant digits after radix. /// </summary> /// <param name="unit">Unit representation to use.</param> /// <param name="culture">Culture to use for localization and number formatting.</param> /// <returns>String representation.</returns> public string ToString(DurationUnit unit, [CanBeNull] Culture culture) { return(ToString(unit, culture, 2)); }
public static void HasConversion(this PropertyBuilder <Duration> propertyBuilder, DurationUnit unit) => propertyBuilder.HasConversion(v => v.As(unit), v => new Duration(v, unit));
public void ConstructorThrowsArgumentExceptionWithUndefinedUnits(LengthUnit length, MassUnit mass, DurationUnit time, ElectricCurrentUnit current, TemperatureUnit temperature, AmountOfSubstanceUnit amount, LuminousIntensityUnit luminousIntensity) { var baseUnits = new BaseUnits(length, mass, time, current, temperature, amount, luminousIntensity); Assert.Throws <ArgumentException>(() => new UnitSystem(baseUnits)); }
public static async Task <T> ObserveDurationAsync <T>(this IValueObserver observer, Func <Task <T> > method, DurationUnit unit = DurationUnit.Seconds) { var ts = Stopwatch.GetTimestamp(); try { return(await method().ConfigureAwait(false)); } finally { observer.Observe(GetDuration(ts, unit)); } }
public static T ObserveDuration <T>(this IValueObserver observer, Func <T> method, DurationUnit unit = DurationUnit.Seconds) { var ts = Stopwatch.GetTimestamp(); try { return(method()); } finally { observer.Observe(GetDuration(ts, unit)); } }
public static void ObserveDuration(this IValueObserver observer, Action method, DurationUnit unit = DurationUnit.Seconds) { var ts = Stopwatch.GetTimestamp(); try { method(); } finally { observer.Observe(GetDuration(ts, unit)); } }
private double ConvertFromNanoseconds(double value) { return(value / DurationUnit.Convert(1, TimeUnit.Nanoseconds)); }
/// <summary> /// Get string representation of value and unit. Using two significant digits after radix. /// </summary> /// <param name="unit">Unit representation to use.</param> /// <param name="cultureName">Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to <see cref="UnitSystem" />'s default culture.</param> /// <returns>String representation.</returns> public string ToString(DurationUnit unit, [CanBeNull] string cultureName) { return(ToString(unit, cultureName, 2)); }
// Token: 0x0600314E RID: 12622 RVA: 0x00123085 File Offset: 0x00121285 internal Work(float workAmount, DurationUnit workUnit) { this.workAmount = workAmount; this.workUnit = workUnit; }
public void SetDurationUnit(DurationUnit unit) => Preferences.Set(PreferenceKeys.DurationUnit, unit.ToString());
public static string GetAbbreviation(DurationUnit unit, [CanBeNull] Culture culture) { return(UnitSystem.GetCached(culture).GetDefaultAbbreviation(unit)); }
public static string ExerciseDuration(DurationUnit unit) => $"Exercise Time ({unit})";
/// <summary> /// Get string representation of value and unit. Using two significant digits after radix. /// </summary> /// <param name="unit">Unit representation to use.</param> /// <param name="provider">Format to use for localization and number formatting. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param> /// <returns>String representation.</returns> public string ToString(DurationUnit unit, [CanBeNull] IFormatProvider provider) { return(ToString(unit, provider, 2)); }
public static string Duration(DurationUnit unit) => $"Duration ({unit})";
Duration(double numericValue, DurationUnit unit) { _value = numericValue; _unit = unit; }
public static Dictionary <DurationUnit, double> GetDurationExpression(string val) { val = val.Substring(1); val = val.ToUpper(); if (val == "") { return(new Dictionary <DurationUnit, double>()); } bool istime = false; if (val[0] == 'T') { istime = true; val = val.Substring(1); } Dictionary <DurationUnit, double> ret = new Dictionary <DurationUnit, double>(); Regex regex = new Regex(@"(?<value>[^A-Z]+)(?<unit>[A-Z])"); MatchCollection matches = regex.Matches(val); foreach (Match match in matches) { double value = Convert.ToDouble(match.Groups["value"].Value.Trim(new char[] { '.' })); char unit = match.Groups["unit"].Value[0]; if (value == 0) { continue; } switch (unit) { case 'Y': if (!ret.ContainsKey(DurationUnit.YEAR)) { ret.Add(DurationUnit.YEAR, value); } else { ret[DurationUnit.YEAR] += value; } break; case 'D': if (!ret.ContainsKey(DurationUnit.DAY)) { ret.Add(DurationUnit.DAY, value); } else { ret[DurationUnit.DAY] += value; } break; case 'H': if (!ret.ContainsKey(DurationUnit.HOUR)) { ret.Add(DurationUnit.HOUR, value); } else { ret[DurationUnit.HOUR] += value; } break; case 'S': if (!ret.ContainsKey(DurationUnit.SECOND)) { ret.Add(DurationUnit.SECOND, value); } else { ret[DurationUnit.SECOND] += value; } break; case 'M': { DurationUnit u = (istime) ? DurationUnit.MINUTE : DurationUnit.MONTH; if (!ret.ContainsKey(u)) { ret.Add(u, value); } else { ret[u] += value; } break; } case 'W': if (!ret.ContainsKey(DurationUnit.WEEK)) { ret.Add(DurationUnit.WEEK, value); } else { ret[DurationUnit.WEEK] += value; } break; } } return(ret); }
public static Duration From(QuantityValue value, DurationUnit fromUnit) #endif { return(new Duration((double)value, fromUnit)); }
public static string GetAbbreviation(DurationUnit unit, CultureInfo culture = null) { return(UnitSystem.GetCached(culture).GetDefaultAbbreviation(unit)); }
/// <summary> /// Converts this Duration to another Duration with the unit representation <paramref name="unit" />. /// </summary> /// <returns>A Duration with the specified unit.</returns> public Duration ToUnit(DurationUnit unit) { var convertedValue = AsBaseNumericType(unit); return(new Duration(convertedValue, unit)); }
public string ToString(DurationUnit unit, CultureInfo culture = null, int significantDigitsAfterRadix = 2) { return(ToString(unit, culture, UnitFormatter.GetFormat(As(unit), significantDigitsAfterRadix))); }
internal double GetSlaDuration(DateTime dateStartingTime, DateTime dateEndingTime, DurationUnit durationUnit) { try { log.LogFunctionStart(); var nextDay = dateStartingTime.AddDays(1); var durationInMinutes = 0d; var dateStartingHours = dateStartingTime.Hour; var dateStartingMinutes = dateStartingTime.Minute; var dateEndingHours = dateEndingTime.Hour; var dateEndingMinutes = dateEndingTime.Minute; var vacations = GetVacations(dateStartingTime); var standardWorkingHours = GetStandardWorkingHours(); var exceptionalWorkingHoursCollection = GetExceptionalWorkingHours(); var nextdayWorkingHours = 0.0; if (dateStartingTime < dateEndingTime) { //For First Day var currentDayWorkingHours = GetDayWorkingHours(dateStartingTime, standardWorkingHours, exceptionalWorkingHoursCollection); if (currentDayWorkingHours.Contains("ldv_workinghours")) { nextdayWorkingHours = double.Parse(currentDayWorkingHours["ldv_workinghours"].ToString()); } if (currentDayWorkingHours.Contains("ldv_workinghoursend")) { //string hoursToText = ((Picklist)workingDays.Properties["ld_to"]).name; var hoursFromText = currentDayWorkingHours.FormattedValues["ldv_workinghoursstart"]; var hoursToText = currentDayWorkingHours.FormattedValues["ldv_workinghoursend"]; var hoursFromParts = hoursFromText.Split(' '); var hoursToParts = hoursToText.Split(' '); var hoursFrom = double.Parse(hoursFromParts[0].Split(':')[0]); var hoursTo = double.Parse(hoursToParts[0].Split(':')[0]); var minutesFrom = double.Parse(hoursFromParts[0].Split(':')[1]); var minutesTo = double.Parse(hoursToParts[0].Split(':')[1]); if (hoursFromParts[1].ToLower() == "pm" && hoursFrom != 12) { hoursFrom += 12; } if (minutesFrom == 30) { hoursFrom += 0.5; } if (hoursToParts[1].ToLower() == "pm" && hoursTo != 12) { hoursTo += 12; } if (minutesTo == 30) { hoursTo += 0.5; } if (!(IsVacation(dateStartingTime, currentDayWorkingHours, vacations))) { double sdt = (dateStartingHours * 60) + dateStartingMinutes; if (dateStartingTime.Day != dateEndingTime.Day || dateStartingTime.Month != dateEndingTime.Month || dateStartingTime.Year != dateEndingTime.Year) { if (sdt < (hoursFrom * 60)) { durationInMinutes += nextdayWorkingHours * 60; } else if (sdt <= (hoursTo * 60)) { durationInMinutes += ((hoursTo - dateStartingHours) * 60) + ((0 - dateStartingMinutes)); } } } } //For the next Days while (nextDay < dateEndingTime && ((nextDay.Day != dateEndingTime.Day && nextDay.Month == dateEndingTime.Month && nextDay.Year == dateEndingTime.Year) || (nextDay.Month != dateEndingTime.Month) || (nextDay.Year != dateEndingTime.Year))) { var nextDayWorkingHours = GetDayWorkingHours(nextDay, standardWorkingHours, exceptionalWorkingHoursCollection); while (IsVacation(nextDay, nextDayWorkingHours, vacations)) { nextDay = nextDay.AddDays(1); nextDayWorkingHours = GetDayWorkingHours(nextDay, standardWorkingHours, exceptionalWorkingHoursCollection); } if (nextDay < dateEndingTime && ((nextDay.Day != dateEndingTime.Day && nextDay.Month == dateEndingTime.Month && nextDay.Year == dateEndingTime.Year) || (nextDay.Month != dateEndingTime.Month) || (nextDay.Year != dateEndingTime.Year))) { if (nextDayWorkingHours.Contains("ldv_workinghours")) { nextdayWorkingHours = double.Parse(nextDayWorkingHours["ldv_workinghours"].ToString()); } durationInMinutes += nextdayWorkingHours * 60; nextDay = nextDay.AddDays(1); } } if (dateStartingTime.Day == dateEndingTime.Day && dateStartingTime.Month == dateEndingTime.Month && dateStartingTime.Year == dateEndingTime.Year) { currentDayWorkingHours = GetDayWorkingHours(dateStartingTime, standardWorkingHours, exceptionalWorkingHoursCollection); if (!(IsVacation(dateStartingTime, currentDayWorkingHours, vacations))) { if (currentDayWorkingHours.Contains("ldv_workinghours")) { nextdayWorkingHours = double.Parse(currentDayWorkingHours["ldv_workinghours"].ToString()); } if (currentDayWorkingHours.Contains("ldv_workinghoursstart") && currentDayWorkingHours.Contains("ldv_workinghoursend")) { //string hoursFromText = ((Picklist)workingDays.Properties["ld_from"]).name; var hoursFromText = currentDayWorkingHours.FormattedValues["ldv_workinghoursstart"]; var hoursToText = currentDayWorkingHours.FormattedValues["ldv_workinghoursend"]; var hoursFromParts = hoursFromText.Split(' '); var hoursToParts = hoursToText.Split(' '); var hoursFrom = double.Parse(hoursFromParts[0].Split(':')[0]); var hoursTo = double.Parse(hoursToParts[0].Split(':')[0]); var minutesFrom = double.Parse(hoursFromParts[0].Split(':')[1]); var minutesTo = double.Parse(hoursToParts[0].Split(':')[1]); if (hoursFromParts[1].ToLower() == "pm" && hoursFrom != 12) { hoursFrom += 12; } if (minutesFrom == 30) { hoursFrom += 0.5; } if (hoursToParts[1].ToLower() == "pm" && hoursTo != 12) { hoursTo += 12; } if (minutesTo == 30) { hoursTo += 0.5; } if (dateStartingTime.Day == dateEndingTime.Day && dateStartingTime.Month == dateEndingTime.Month && dateStartingTime.Year == dateEndingTime.Year) { double sdt = (dateStartingHours * 60) + dateStartingMinutes; double edt = (dateEndingHours * 60) + dateEndingMinutes; if (sdt > (hoursFrom * 60) && edt < (hoursTo * 60)) { durationInMinutes += ((dateEndingHours - dateStartingHours) * 60) + ((dateEndingMinutes - dateStartingMinutes)); } else if (sdt >= (hoursFrom * 60) && edt >= (hoursTo * 60)) { durationInMinutes += ((hoursTo - dateStartingHours) * 60) + ((0 - dateStartingMinutes)); } else if (sdt <= (hoursFrom * 60) && edt < (hoursTo * 60)) { durationInMinutes += ((dateEndingHours - hoursFrom) * 60) + ((dateEndingMinutes - 0)); } else if (sdt < (hoursFrom * 60) && edt >= (hoursTo * 60)) { durationInMinutes += nextdayWorkingHours * 60; } } else { double edt = (dateEndingHours * 60) + dateEndingMinutes; durationInMinutes += ((((edt >= (hoursTo * 60)) ? hoursTo : dateEndingHours) - hoursFrom) * 60) + ((edt >= (hoursTo * 60)) ? 0 : dateEndingMinutes); } } } } else if (nextDay.Day == dateEndingTime.Day && nextDay.Month == dateEndingTime.Month && nextDay.Year == dateEndingTime.Year) { //Last Day var lastDayWorkingHours = GetDayWorkingHours(nextDay, standardWorkingHours, exceptionalWorkingHoursCollection); if (!IsVacation(nextDay, lastDayWorkingHours, vacations)) { if (lastDayWorkingHours.Contains("ldv_workinghours")) { nextdayWorkingHours = double.Parse(lastDayWorkingHours["ldv_workinghours"].ToString()); } if (lastDayWorkingHours.Contains("ldv_workinghoursstart") && lastDayWorkingHours.Contains("ldv_workinghoursend")) { //string hoursFromText = ((Picklist)workingDays.Properties["ld_from"]).name; var hoursFromText = lastDayWorkingHours.FormattedValues["ldv_workinghoursstart"]; var hoursToText = lastDayWorkingHours.FormattedValues["ldv_workinghoursend"]; var hoursFromParts = hoursFromText.Split(' '); var hoursToParts = hoursToText.Split(' '); var hoursFrom = double.Parse(hoursFromParts[0].Split(':')[0]); var hoursTo = double.Parse(hoursToParts[0].Split(':')[0]); var minutesFrom = double.Parse(hoursFromParts[0].Split(':')[1]); var minutesTo = double.Parse(hoursToParts[0].Split(':')[1]); if (hoursFromParts[1].ToLower() == "pm" && hoursFrom != 12) { hoursFrom += 12; } if (minutesFrom == 30) { hoursFrom += 0.5; } if (hoursToParts[1].ToLower() == "pm" && hoursTo != 12) { hoursTo += 12; } if (minutesTo == 30) { hoursTo += 0.5; } if (dateStartingTime.Day == dateEndingTime.Day && dateStartingTime.Month == dateEndingTime.Month && dateStartingTime.Year == dateEndingTime.Year) { double sdt = (dateStartingHours * 60) + dateStartingMinutes; double edt = (dateEndingHours * 60) + dateEndingMinutes; if (sdt > (hoursFrom * 60) && edt < (hoursTo * 60)) { durationInMinutes += ((dateEndingHours - dateStartingHours) * 60) + ((dateEndingMinutes - dateStartingMinutes)); } else if (sdt >= (hoursFrom * 60) && edt >= (hoursTo * 60)) { durationInMinutes += ((hoursTo - dateStartingHours) * 60) + ((0 - dateStartingMinutes)); } else if (sdt <= (hoursFrom * 60) && edt < (hoursTo * 60)) { durationInMinutes += ((dateEndingHours - hoursFrom) * 60) + ((dateEndingMinutes - 0)); } else if (sdt < (hoursFrom * 60) && edt >= (hoursTo * 60)) { durationInMinutes += nextdayWorkingHours * 60; } } else { double edt = (dateEndingHours * 60) + dateEndingMinutes; durationInMinutes += ((((edt >= (hoursTo * 60)) ? hoursTo : dateEndingHours) - hoursFrom) * 60) + ((edt >= (hoursTo * 60)) ? 0 : dateEndingMinutes); } } } } } //To return the duration if (durationInMinutes == 0) { return(0); } var returnDuration = 0d; switch (durationUnit) { case DurationUnit.HOURS: returnDuration = durationInMinutes / 60.0; break; case DurationUnit.MINUTES: returnDuration = durationInMinutes; break; case DurationUnit.SECONDS: returnDuration = durationInMinutes * 60.0; break; } return(returnDuration < 0 ? 0 : returnDuration); } catch (Exception ex) { log.Log(ex); throw; } finally { log.LogFunctionEnd(); } }
public string ToString(DurationUnit unit, CultureInfo culture, string format, params object[] args) { return(string.Format(culture, format, UnitFormatter.GetFormatArgs(unit, As(unit), culture, args))); }
void OnGUI() { int i; bool shouldRepaint = false; //************************************************************* //******************* Zoom slider ***************************** GUILayout.Space( 10f ); EditorGUIUtility.labelWidth = 55f; int samplesPerPixel = _samplesPerPixel; _samplesPerPixel = EditorGUILayout.IntSlider( "Zoom: ", _samplesPerPixel, 2, 1000 ); if( samplesPerPixel != _samplesPerPixel ) { UpdateZoom(); } //************************************************************* //******************* ScrollView ***************************** Vector2 prevScroll = _scrollPos; _scrollPos = GUI.BeginScrollView( new Rect( 0f, 0f, this.position.width, this.position.height ), _scrollPos, new Rect( 0, 0, _scrollViewWidth ,200f )); if( prevScroll != _scrollPos ) shouldRepaint = true; //************************************************************* //******************* Mouse Events **************************** if( Event.current.isMouse ) { EventType eventType = Event.current.type; Vector2 mousePos = Event.current.mousePosition; if( eventType == EventType.MouseDown ) { _draggedHandle = null; foreach( EnvelopeHandle handle in _handles ) { if( handle.HitTest( mousePos ) ) { _draggedHandle = handle; break; } } if( _draggedHandle == null && _posHandle.HitTest( mousePos ) ) { _draggedHandle = _posHandle; } } else if( eventType == EventType.MouseUp ) { _draggedHandle = null; } else if( eventType == EventType.MouseDrag && _draggedHandle != null ) { if( _draggedHandle.Control == ControlType.Position ) { int posInSamples = _draggedHandle.EvaluatePosInSamples( mousePos.x ); int halfLength = _envelopeModule.Length / 2; if( posInSamples - halfLength < 0 ) { posInSamples = halfLength; } else if( posInSamples + halfLength > EnvelopeHandle.MaxSamples ) { posInSamples = EnvelopeHandle.MaxSamples - halfLength; } _handles[ 0 ].PosInSamples = posInSamples - halfLength; _handles[ 1 ].PosInSamples = _handles[ 0 ].PosInSamples + _envelopeModule.FadeIn; _handles[ 3 ].PosInSamples = posInSamples + halfLength; _handles[ 2 ].PosInSamples = _handles[ 3 ].PosInSamples - _envelopeModule.FadeOut; _posHandle.PosInSamples = posInSamples; _envelopeModule.Offset = _handles[0].PosInSamples; } else { _draggedHandle.Drag( mousePos.x ); if( _draggedHandle.Control == ControlType.AttackStart ) { _envelopeModule.Offset = _draggedHandle.PosInSamples; _envelopeModule.FadeIn = _handles[ 1 ].PosInSamples - _handles[ 0 ].PosInSamples; _envelopeModule.Length = _handles[ 3 ].PosInSamples - _handles[ 0 ].PosInSamples; UpdatePosHandle(); } else if( _draggedHandle.Control == ControlType.AttackEnd ) { _envelopeModule.FadeIn = _handles[ 1 ].PosInSamples - _handles[ 0 ].PosInSamples; } else if( _draggedHandle.Control == ControlType.ReleaseStart ) { _envelopeModule.FadeOut = _handles[ 3 ].PosInSamples - _handles[ 2 ].PosInSamples; } else //ReleaseEnd { _envelopeModule.FadeOut = _handles[ 3 ].PosInSamples - _handles[ 2 ].PosInSamples; _envelopeModule.Length = _handles[ 3 ].PosInSamples - _handles[ 0 ].PosInSamples; UpdatePosHandle(); } } shouldRepaint = true; } } //************************************************************* //******************* Drawing ********************************* for( i = 0; i < 4; i++ ) { _handles[ i ].DrawHandle(); } _posHandle.DrawHandle(); for( i = 0; i < 4; i++ ) { _linePoints[ i ] = _handles[ i ].Position; } Handles.color = Color.blue; Handles.DrawAAPolyLine( 2f, _linePoints ); Handles.color = Color.grey; Handles.DrawLine( _start, _end ); GUI.EndScrollView(); GUILayout.Space( 110f ); //************************************************************* //******************* Info ************************************ _durationUnit = ( DurationUnit )EditorGUILayout.EnumPopup( _durationUnit, GUILayout.Width( 60f ) ); GUILayoutOption labelWidth = GUILayout.Width( 90f ); GUILayout.BeginHorizontal(); GUILayout.Label( "Length: " + GetLengthStringForSamples( _envelopeModule.Length ), labelWidth ); GUILayout.Label( "Offset: " + GetLengthStringForSamples( _envelopeModule.Offset ), labelWidth ); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label( "Fade In: " + GetLengthStringForSamples( _envelopeModule.FadeIn ), labelWidth ); GUILayout.Label( "Fade Out: " + GetLengthStringForSamples( _envelopeModule.FadeOut ), labelWidth ); GUILayout.EndHorizontal(); GUILayout.Space( 10f ); _envelopeModule.Pulse = ( PulseModule )EditorGUILayout.ObjectField( _envelopeModule.Pulse, typeof( PulseModule ), true, GUILayout.Width( 130f ) ); GUI.enabled = _envelopeModule.Pulse != null; _envelopeModule.MapLengthToPulse = GUILayout.Toggle( _envelopeModule.MapLengthToPulse, "Map Length To Pulse", GUILayout.ExpandWidth( false ) ); GUI.enabled = true; if( _envelopeModule.Pulse != null && _envelopeModule.MapLengthToPulse ) { GUILayout.Label( "Length to Pulse ratio: " + _envelopeModule.LengthToPulseRatio.ToString( "0.00" ) ); _envelopeModule.LengthToPulseRatio = GUILayout.HorizontalSlider( _envelopeModule.LengthToPulseRatio, .1f, 8f, GUILayout.Width( 190f ) ); } //************************************************************************************ //*********************** ObjectPicker Messages Handling ***************************** if (Event.current.commandName == "ObjectSelectorUpdated") { GATSoundBank bank = EditorGUIUtility.GetObjectPickerObject() as GATSoundBank; if( bank != null ) { _selectedBankMax = bank.SizeOfLongestSample(); _selectedBankMin = bank.SizeOfShortestSample(); shouldRepaint = true; _selectedBank = bank; } } //************************************************************************************ //*********************** SoundBank Clamping ***************************** GUILayout.BeginArea( new Rect( 200f, 130f, 200f, 150f ) ); GUILayout.Label( "Max Length: " + GetLengthStringForSamples( EnvelopeHandle.MaxSamples ) ); EditorGUIUtility.labelWidth = 70f; _selectedBank = ( GATSoundBank )EditorGUILayout.ObjectField( "SoundBank:", _selectedBank, typeof( GATSoundBank ), false ); if( _selectedBank != null ) { if( GUILayout.Button( "Shortest sample:" + GetLengthStringForSamples( _selectedBankMin ), GUILayout.Width( 140f ) ) ) { EnvelopeHandle.MaxSamples = _selectedBankMin; UpdateZoom(); } if( GUILayout.Button( "Longest sample:" + GetLengthStringForSamples( _selectedBankMax ), GUILayout.Width( 140f ) ) ) { EnvelopeHandle.MaxSamples = _selectedBankMax; UpdateZoom(); } } else { EditorGUILayout.HelpBox( "Select a sound bank to easily map this envelope's max length to the bank's shortest or longest sample.", MessageType.Info ); } //************************************************************************************ //*********************** Reverse and Normalize ************************************** _envelopeModule.Reverse = GUILayout.Toggle( _envelopeModule.Reverse, "Reverse" ); GUILayout.BeginHorizontal(); _envelopeModule.Normalize = GUILayout.Toggle( _envelopeModule.Normalize, "Normalize", GUILayout.Width( 75f ) ); if( _envelopeModule.Normalize ) { GUILayout.Label( _envelopeModule.NormalizeValue.ToString("0.00") ); GUILayout.EndHorizontal(); _envelopeModule.NormalizeValue = GUILayout.HorizontalSlider( _envelopeModule.NormalizeValue, 0f, 1f ); } else GUILayout.EndHorizontal(); GUILayout.EndArea(); if( shouldRepaint ) Repaint(); }
void OnGUI() { int i; bool shouldRepaint = false; //************************************************************* //******************* Zoom slider ***************************** GUILayout.Space(10f); EditorGUIUtility.labelWidth = 55f; int samplesPerPixel = _samplesPerPixel; _samplesPerPixel = EditorGUILayout.IntSlider("Zoom: ", _samplesPerPixel, 2, 1000); if (samplesPerPixel != _samplesPerPixel) { UpdateZoom(); } //************************************************************* //******************* ScrollView ***************************** Vector2 prevScroll = _scrollPos; _scrollPos = GUI.BeginScrollView(new Rect(0f, 0f, this.position.width, this.position.height), _scrollPos, new Rect(0, 0, _scrollViewWidth, 200f)); if (prevScroll != _scrollPos) { shouldRepaint = true; } //************************************************************* //******************* Mouse Events **************************** if (Event.current.isMouse) { EventType eventType = Event.current.type; Vector2 mousePos = Event.current.mousePosition; if (eventType == EventType.MouseDown) { _draggedHandle = null; foreach (EnvelopeHandle handle in _handles) { if (handle.HitTest(mousePos)) { _draggedHandle = handle; break; } } if (_draggedHandle == null && _posHandle.HitTest(mousePos)) { _draggedHandle = _posHandle; } } else if (eventType == EventType.MouseUp) { _draggedHandle = null; } else if (eventType == EventType.MouseDrag && _draggedHandle != null) { if (_draggedHandle.Control == ControlType.Position) { int posInSamples = _draggedHandle.EvaluatePosInSamples(mousePos.x); int halfLength = _envelopeModule.Length / 2; if (posInSamples - halfLength < 0) { posInSamples = halfLength; } else if (posInSamples + halfLength > EnvelopeHandle.MaxSamples) { posInSamples = EnvelopeHandle.MaxSamples - halfLength; } _handles[0].PosInSamples = posInSamples - halfLength; _handles[1].PosInSamples = _handles[0].PosInSamples + _envelopeModule.FadeIn; _handles[3].PosInSamples = posInSamples + halfLength; _handles[2].PosInSamples = _handles[3].PosInSamples - _envelopeModule.FadeOut; _posHandle.PosInSamples = posInSamples; _envelopeModule.Offset = _handles[0].PosInSamples; } else { _draggedHandle.Drag(mousePos.x); if (_draggedHandle.Control == ControlType.AttackStart) { _envelopeModule.Offset = _draggedHandle.PosInSamples; _envelopeModule.FadeIn = _handles[1].PosInSamples - _handles[0].PosInSamples; _envelopeModule.Length = _handles[3].PosInSamples - _handles[0].PosInSamples; UpdatePosHandle(); } else if (_draggedHandle.Control == ControlType.AttackEnd) { _envelopeModule.FadeIn = _handles[1].PosInSamples - _handles[0].PosInSamples; } else if (_draggedHandle.Control == ControlType.ReleaseStart) { _envelopeModule.FadeOut = _handles[3].PosInSamples - _handles[2].PosInSamples; } else //ReleaseEnd { _envelopeModule.FadeOut = _handles[3].PosInSamples - _handles[2].PosInSamples; _envelopeModule.Length = _handles[3].PosInSamples - _handles[0].PosInSamples; UpdatePosHandle(); } } shouldRepaint = true; } } //************************************************************* //******************* Drawing ********************************* for (i = 0; i < 4; i++) { _handles[i].DrawHandle(); } _posHandle.DrawHandle(); for (i = 0; i < 4; i++) { _linePoints[i] = _handles[i].Position; } Handles.color = Color.blue; Handles.DrawAAPolyLine(2f, _linePoints); Handles.color = Color.grey; Handles.DrawLine(_start, _end); GUI.EndScrollView(); GUILayout.Space(110f); //************************************************************* //******************* Info ************************************ _durationUnit = ( DurationUnit )EditorGUILayout.EnumPopup(_durationUnit, GUILayout.Width(60f)); GUILayoutOption labelWidth = GUILayout.Width(90f); GUILayout.BeginHorizontal(); GUILayout.Label("Length: " + GetLengthStringForSamples(_envelopeModule.Length), labelWidth); GUILayout.Label("Offset: " + GetLengthStringForSamples(_envelopeModule.Offset), labelWidth); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Fade In: " + GetLengthStringForSamples(_envelopeModule.FadeIn), labelWidth); GUILayout.Label("Fade Out: " + GetLengthStringForSamples(_envelopeModule.FadeOut), labelWidth); GUILayout.EndHorizontal(); GUILayout.Space(10f); _envelopeModule.Pulse = ( PulseModule )EditorGUILayout.ObjectField(_envelopeModule.Pulse, typeof(PulseModule), true, GUILayout.Width(130f)); GUI.enabled = _envelopeModule.Pulse != null; _envelopeModule.MapLengthToPulse = GUILayout.Toggle(_envelopeModule.MapLengthToPulse, "Map Length To Pulse", GUILayout.ExpandWidth(false)); GUI.enabled = true; if (_envelopeModule.Pulse != null && _envelopeModule.MapLengthToPulse) { GUILayout.Label("Length to Pulse ratio: " + _envelopeModule.LengthToPulseRatio.ToString("0.00")); _envelopeModule.LengthToPulseRatio = GUILayout.HorizontalSlider(_envelopeModule.LengthToPulseRatio, .1f, 8f, GUILayout.Width(190f)); } //************************************************************************************ //*********************** ObjectPicker Messages Handling ***************************** if (Event.current.commandName == "ObjectSelectorUpdated") { GATSoundBank bank = EditorGUIUtility.GetObjectPickerObject() as GATSoundBank; if (bank != null) { _selectedBankMax = bank.SizeOfLongestSample(); _selectedBankMin = bank.SizeOfShortestSample(); shouldRepaint = true; _selectedBank = bank; } } //************************************************************************************ //*********************** SoundBank Clamping ***************************** GUILayout.BeginArea(new Rect(200f, 130f, 200f, 150f)); GUILayout.Label("Max Length: " + GetLengthStringForSamples(EnvelopeHandle.MaxSamples)); EditorGUIUtility.labelWidth = 70f; _selectedBank = ( GATSoundBank )EditorGUILayout.ObjectField("SoundBank:", _selectedBank, typeof(GATSoundBank), false); if (_selectedBank != null) { if (GUILayout.Button("Shortest sample:" + GetLengthStringForSamples(_selectedBankMin), GUILayout.Width(140f))) { EnvelopeHandle.MaxSamples = _selectedBankMin; UpdateZoom(); } if (GUILayout.Button("Longest sample:" + GetLengthStringForSamples(_selectedBankMax), GUILayout.Width(140f))) { EnvelopeHandle.MaxSamples = _selectedBankMax; UpdateZoom(); } } else { EditorGUILayout.HelpBox("Select a sound bank to easily map this envelope's max length to the bank's shortest or longest sample.", MessageType.Info); } //************************************************************************************ //*********************** Reverse and Normalize ************************************** _envelopeModule.Reverse = GUILayout.Toggle(_envelopeModule.Reverse, "Reverse"); GUILayout.BeginHorizontal(); _envelopeModule.Normalize = GUILayout.Toggle(_envelopeModule.Normalize, "Normalize", GUILayout.Width(75f)); if (_envelopeModule.Normalize) { GUILayout.Label(_envelopeModule.NormalizeValue.ToString("0.00")); GUILayout.EndHorizontal(); _envelopeModule.NormalizeValue = GUILayout.HorizontalSlider(_envelopeModule.NormalizeValue, 0f, 1f); } else { GUILayout.EndHorizontal(); } GUILayout.EndArea(); if (shouldRepaint) { Repaint(); } }