This repository has been archived by the owner on Aug 24, 2024. It is now read-only.
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.
Merge remote-tracking branch 'origin/main' into feature/refactoring
# Conflicts: # Assets/BetterValidation/Editor/EditorAddons/Handlers/ClampWrapper.cs # Assets/BetterValidation/Editor/EditorAddons/Handlers/ClampWrapper.cs.meta # Assets/BetterValidation/Editor/EditorAddons/Handlers/MaxWrapper.cs # Assets/BetterValidation/Editor/EditorAddons/Handlers/MaxWrapper.cs.meta # Assets/BetterValidation/Editor/EditorAddons/Utility/ValidationAttributeBinder.cs
- Loading branch information
Showing
22 changed files
with
193 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 2 additions & 1 deletion
3
...s/Handlers/ValidationWrapperExtensions.cs → ...Extensions/ValidationWrapperExtensions.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
File renamed without changes.
55 changes: 55 additions & 0 deletions
55
Assets/BetterValidation/Editor/EditorAddons/Handlers/ClampWrapper.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,55 @@ | ||
using System; | ||
using Better.Commons.EditorAddons.Extensions; | ||
using Better.Validation.Runtime.Attributes; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Better.Validation.EditorAddons.Handlers | ||
{ | ||
public class ClampWrapper : PropertyValidationHandler | ||
{ | ||
public override bool IsSupported() | ||
{ | ||
return Property.propertyType is SerializedPropertyType.Integer or SerializedPropertyType.Float; | ||
} | ||
|
||
public override ValidationValue<string> Validate() | ||
{ | ||
var clampAttribute = (ClampAttribute)Attribute; | ||
var minValue = clampAttribute.Min; | ||
var maxValue = clampAttribute.Max; | ||
float value; | ||
switch (Property.propertyType) | ||
{ | ||
case SerializedPropertyType.Float: | ||
value = Property.floatValue; | ||
break; | ||
case SerializedPropertyType.Integer: | ||
value = Property.intValue; | ||
break; | ||
default: | ||
return GetNotValidValue($"Property: {Property.displayName} has invalid type: {Property.propertyType}"); | ||
} | ||
|
||
if (value >= minValue && value <= maxValue) | ||
{ | ||
return GetClearValue(); | ||
} | ||
|
||
value = Mathf.Clamp(value, minValue, maxValue); | ||
switch (Property.propertyType) | ||
{ | ||
case SerializedPropertyType.Float: | ||
Property.SetValue(value); | ||
break; | ||
case SerializedPropertyType.Integer: | ||
Property.SetValue((int)value); | ||
break; | ||
} | ||
|
||
EditorUtility.SetDirty(Property.serializedObject.targetObject); | ||
Property.serializedObject.ApplyModifiedProperties(); | ||
return GetClearValue(); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/BetterValidation/Editor/EditorAddons/Handlers/ClampWrapper.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
52 changes: 52 additions & 0 deletions
52
Assets/BetterValidation/Editor/EditorAddons/Handlers/MaxWrapper.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,52 @@ | ||
using System; | ||
using Better.Commons.EditorAddons.Extensions; | ||
using Better.Validation.Runtime.Attributes; | ||
using UnityEditor; | ||
|
||
namespace Better.Validation.EditorAddons.Handlers | ||
{ | ||
public class MaxWrapper : PropertyValidationHandler | ||
{ | ||
public override bool IsSupported() | ||
{ | ||
return Property.propertyType is SerializedPropertyType.Integer or SerializedPropertyType.Float; | ||
} | ||
|
||
public override ValidationValue<string> Validate() | ||
{ | ||
var maxAttribute = (MaxAttribute)Attribute; | ||
var maxValue = maxAttribute.Max; | ||
bool isValid; | ||
switch (Property.propertyType) | ||
{ | ||
case SerializedPropertyType.Float: | ||
isValid = Property.floatValue <= maxValue; | ||
break; | ||
case SerializedPropertyType.Integer: | ||
isValid = Property.intValue <= maxValue; | ||
break; | ||
default: | ||
return GetNotValidValue($"Property: {Property.displayName} has invalid type: {Property.propertyType}"); | ||
} | ||
|
||
if (isValid) | ||
{ | ||
return GetClearValue(); | ||
} | ||
|
||
switch (Property.propertyType) | ||
{ | ||
case SerializedPropertyType.Float: | ||
Property.SetValue(maxValue); | ||
break; | ||
case SerializedPropertyType.Integer: | ||
Property.SetValue((int)maxValue); | ||
break; | ||
} | ||
|
||
EditorUtility.SetDirty(Property.serializedObject.targetObject); | ||
Property.serializedObject.ApplyModifiedProperties(); | ||
return GetClearValue(); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/BetterValidation/Editor/EditorAddons/Handlers/MaxWrapper.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
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
20 changes: 20 additions & 0 deletions
20
Assets/BetterValidation/Runtime/Attributes/ClampAttribute.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 System.Diagnostics; | ||
using Better.Internal.Core.Runtime; | ||
|
||
namespace Better.Validation.Runtime.Attributes | ||
{ | ||
[Conditional(Defines.Editor)] | ||
[AttributeUsage(AttributeTargets.Field)] | ||
public class ClampAttribute : ValidationAttribute | ||
{ | ||
public float Min { get; } | ||
public float Max { get; } | ||
|
||
public ClampAttribute(float min, float max) | ||
{ | ||
Min = min; | ||
Max = max; | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/BetterValidation/Runtime/Attributes/ClampAttribute.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
Assets/BetterValidation/Runtime/Attributes/MaxAttribute.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,18 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using Better.Internal.Core.Runtime; | ||
|
||
namespace Better.Validation.Runtime.Attributes | ||
{ | ||
[Conditional(Defines.Editor)] | ||
[AttributeUsage(AttributeTargets.Field)] | ||
public class MaxAttribute : ValidationAttribute | ||
{ | ||
public float Max { get; } | ||
|
||
public MaxAttribute(float max) | ||
{ | ||
Max = max; | ||
} | ||
} | ||
} |
Oops, something went wrong.