generated from techno-dwarf-works/unity-package-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
196 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
Assets/BetterCommons/Editor/Extensions/BaseSliderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using UnityEditor; | ||
using UnityEditor.UIElements; | ||
using UnityEngine.UIElements; | ||
|
||
namespace Better.Commons.EditorAddons.Extensions | ||
{ | ||
public static class BaseSliderExtensions | ||
{ | ||
public static void SetupFromProperty<T>(this BaseSlider<T> self, SerializedProperty property) | ||
where T : IComparable<T> | ||
{ | ||
self.label = property.displayName; | ||
self.direction = SliderDirection.Horizontal; | ||
self.showInputField = true; | ||
self.BindProperty(property); | ||
self.AddToClassList("unity-base-field__aligned"); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/BetterCommons/Editor/Extensions/BaseSliderExtensions.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
Assets/BetterCommons/Runtime/DataStructures/SerializedTypes/SerializedRange.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using System; | ||
using UnityEngine; | ||
using Better.Commons.Runtime.DataStructures.Ranges; | ||
|
||
namespace Better.Commons.Runtime.DataStructures.SerializedTypes | ||
{ | ||
/// <summary> | ||
/// Represents a range with minimum and maximum values of a generic type. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the values defining the range.</typeparam> | ||
[Serializable] | ||
public class SerializedRange<T> : Range<T> | ||
{ | ||
[SerializeField] private T _min; | ||
[SerializeField] private T _max; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the Range class with default minimum and maximum values. | ||
/// </summary> | ||
public SerializedRange() | ||
{ | ||
_min = default; | ||
_max = default; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the Range class by copying another range. | ||
/// </summary> | ||
/// <param name="range">The range to copy.</param> | ||
public SerializedRange(Range<T> range) | ||
{ | ||
_min = range.Min; | ||
_max = range.Max; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the Range class with specified minimum and maximum values. | ||
/// </summary> | ||
/// <param name="min">The minimum value of the range.</param> | ||
/// <param name="max">The maximum value of the range.</param> | ||
public SerializedRange(T min, T max) | ||
{ | ||
_min = min; | ||
_max = max; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the minimum value of the range. | ||
/// </summary> | ||
public override T Min => _min; | ||
|
||
/// <summary> | ||
/// Gets the maximum value of the range. | ||
/// </summary> | ||
public override T Max => _max; | ||
|
||
/// <summary> | ||
/// Creates a new instance of the Range that is a copy of the current Range. | ||
/// </summary> | ||
/// <returns>A new Range instance that is a copy of this Range.</returns> | ||
public override Range<T> Clone() | ||
{ | ||
return new SerializedRange<T>(_min, _max); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance of the Range with the same minimum value as this instance and a new maximum value. | ||
/// </summary> | ||
/// <param name="maxValue">The new maximum value for the range.</param> | ||
/// <returns>A new Range instance with the updated maximum value while retaining the original minimum value.</returns> | ||
public SerializedRange<T> CopyWithMax(T maxValue) | ||
{ | ||
return new SerializedRange<T>(_min, maxValue); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance of the Range with the same maximum value as this instance and a new minimum value. | ||
/// </summary> | ||
/// <param name="minValue">The new minimum value for the range.</param> | ||
/// <returns>A new Range instance with the updated minimum value while retaining the original maximum value.</returns> | ||
public SerializedRange<T> CopyWithMin(T minValue) | ||
{ | ||
return new SerializedRange<T>(minValue, _max); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/BetterCommons/Runtime/DataStructures/SerializedTypes/SerializedRange.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
Assets/BetterCommons/Runtime/UIElements/RangeSliderFloat.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Better.Commons.Runtime.DataStructures.Ranges; | ||
using UnityEngine.UIElements; | ||
|
||
namespace Better.Commons.Runtime.UIElements | ||
{ | ||
public class RangeSliderFloat : Slider | ||
{ | ||
private Range<float> _range; | ||
|
||
public RangeSliderFloat() | ||
{ | ||
|
||
} | ||
|
||
public RangeSliderFloat(Range<float> sliderRange) : this() | ||
{ | ||
SetRange(sliderRange); | ||
RefreshRange(); | ||
} | ||
|
||
public void SetRange(Range<float> sliderRange) | ||
{ | ||
_range = sliderRange; | ||
} | ||
|
||
public void RefreshRange() | ||
{ | ||
if(_range == null) return; | ||
lowValue = _range.Min; | ||
highValue = _range.Max; | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/BetterCommons/Runtime/UIElements/RangeSliderFloat.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Better.Commons.Runtime.DataStructures.Ranges; | ||
using UnityEngine.UIElements; | ||
|
||
namespace Better.Commons.Runtime.UIElements | ||
{ | ||
public class RangeSliderInt : SliderInt | ||
{ | ||
private Range<int> _range; | ||
|
||
public RangeSliderInt() | ||
{ | ||
|
||
} | ||
|
||
public RangeSliderInt(Range<int> sliderRange) : this() | ||
{ | ||
SetRange(sliderRange); | ||
RefreshRange(); | ||
} | ||
|
||
public void SetRange(Range<int> sliderRange) | ||
{ | ||
_range = sliderRange; | ||
} | ||
|
||
public void RefreshRange() | ||
{ | ||
if(_range == null) return; | ||
lowValue = _range.Min; | ||
highValue = _range.Max; | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/BetterCommons/Runtime/UIElements/RangeSliderInt.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.