-
-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
close #269
- Loading branch information
Showing
9 changed files
with
132 additions
and
8 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
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
56 changes: 56 additions & 0 deletions
56
Packages/src/Runtime/Internal/Utilities/PowerRangeAttribute.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,56 @@ | ||
using System; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Coffee.UIEffectInternal | ||
{ | ||
[AttributeUsage(AttributeTargets.Field)] | ||
public sealed class PowerRangeAttribute : PropertyAttribute | ||
{ | ||
public readonly float min; | ||
public readonly float max; | ||
public readonly float power; | ||
|
||
public PowerRangeAttribute(float min, float max, float power) | ||
{ | ||
this.min = min; | ||
this.max = max; | ||
this.power = power; | ||
} | ||
} | ||
|
||
#if UNITY_EDITOR | ||
[CustomPropertyDrawer(typeof(PowerRangeAttribute))] | ||
internal sealed class RangeDrawer : PropertyDrawer | ||
{ | ||
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) | ||
{ | ||
var labelWidth = EditorGUIUtility.labelWidth; | ||
var attr = (PowerRangeAttribute)attribute; | ||
label = EditorGUI.BeginProperty(r, label, property); | ||
|
||
EditorGUI.BeginChangeCheck(); | ||
var rSlider = new Rect(r.x + labelWidth + 1, r.y, r.width - labelWidth - 57, r.height); | ||
var powValue = Mathf.Log(property.floatValue, attr.power); | ||
var powMin = Mathf.Log(attr.min, attr.power); | ||
var powMax = Mathf.Log(attr.max, attr.power); | ||
powValue = GUI.HorizontalSlider(rSlider, powValue, powMin, powMax); | ||
if (EditorGUI.EndChangeCheck()) | ||
{ | ||
property.floatValue = Mathf.Clamp(Mathf.Pow(attr.power, powValue), attr.min, attr.max); | ||
} | ||
|
||
EditorGUI.BeginChangeCheck(); | ||
EditorGUIUtility.labelWidth = r.width - 53; | ||
var newValue = EditorGUI.FloatField(r, label, property.floatValue); | ||
if (EditorGUI.EndChangeCheck()) | ||
{ | ||
property.floatValue = Mathf.Clamp(newValue, attr.min, attr.max); | ||
} | ||
|
||
EditorGUI.EndProperty(); | ||
EditorGUIUtility.labelWidth = labelWidth; | ||
} | ||
} | ||
#endif | ||
} |
11 changes: 11 additions & 0 deletions
11
Packages/src/Runtime/Internal/Utilities/PowerRangeAttribute.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
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
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