First commit for private source control. Older commits available on Github.

This commit is contained in:
2026-03-26 12:52:52 +00:00
parent a04c602626
commit 2d449c4a17
2176 changed files with 408185 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
using UnityEngine;
using UnityEditor;
namespace NaughtyAttributes.Editor
{
public class MaxValuePropertyValidator : PropertyValidatorBase
{
public override void ValidateProperty(SerializedProperty property)
{
MaxValueAttribute maxValueAttribute = PropertyUtility.GetAttribute<MaxValueAttribute>(property);
if (property.propertyType == SerializedPropertyType.Integer)
{
if (property.intValue > maxValueAttribute.MaxValue)
{
property.intValue = (int)maxValueAttribute.MaxValue;
}
}
else if (property.propertyType == SerializedPropertyType.Float)
{
if (property.floatValue > maxValueAttribute.MaxValue)
{
property.floatValue = maxValueAttribute.MaxValue;
}
}
else if (property.propertyType == SerializedPropertyType.Vector2)
{
property.vector2Value = Vector2.Min(property.vector2Value, new Vector2(maxValueAttribute.MaxValue, maxValueAttribute.MaxValue));
}
else if (property.propertyType == SerializedPropertyType.Vector3)
{
property.vector3Value = Vector3.Min(property.vector3Value, new Vector3(maxValueAttribute.MaxValue, maxValueAttribute.MaxValue, maxValueAttribute.MaxValue));
}
else if (property.propertyType == SerializedPropertyType.Vector4)
{
property.vector4Value = Vector4.Min(property.vector4Value, new Vector4(maxValueAttribute.MaxValue, maxValueAttribute.MaxValue, maxValueAttribute.MaxValue, maxValueAttribute.MaxValue));
}
else if (property.propertyType == SerializedPropertyType.Vector2Int)
{
property.vector2IntValue = Vector2Int.Min(property.vector2IntValue, new Vector2Int((int)maxValueAttribute.MaxValue, (int)maxValueAttribute.MaxValue));
}
else if (property.propertyType == SerializedPropertyType.Vector3Int)
{
property.vector3IntValue = Vector3Int.Min(property.vector3IntValue, new Vector3Int((int)maxValueAttribute.MaxValue, (int)maxValueAttribute.MaxValue, (int)maxValueAttribute.MaxValue));
}
else
{
string warning = maxValueAttribute.GetType().Name + " can be used only on int, float, Vector or VectorInt fields";
Debug.LogWarning(warning, property.serializedObject.targetObject);
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 627b8e9e7bda6fa408c6f47fb8285665
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 129996
packageName: NaughtyAttributes
packageVersion: 2.1.4
assetPath: Assets/NaughtyAttributes/Scripts/Editor/PropertyValidators/MaxValuePropertyValidator.cs
uploadId: 480834

View File

@@ -0,0 +1,53 @@
using UnityEngine;
using UnityEditor;
namespace NaughtyAttributes.Editor
{
public class MinValuePropertyValidator : PropertyValidatorBase
{
public override void ValidateProperty(SerializedProperty property)
{
MinValueAttribute minValueAttribute = PropertyUtility.GetAttribute<MinValueAttribute>(property);
if (property.propertyType == SerializedPropertyType.Integer)
{
if (property.intValue < minValueAttribute.MinValue)
{
property.intValue = (int)minValueAttribute.MinValue;
}
}
else if (property.propertyType == SerializedPropertyType.Float)
{
if (property.floatValue < minValueAttribute.MinValue)
{
property.floatValue = minValueAttribute.MinValue;
}
}
else if (property.propertyType == SerializedPropertyType.Vector2)
{
property.vector2Value = Vector2.Max(property.vector2Value, new Vector2(minValueAttribute.MinValue, minValueAttribute.MinValue));
}
else if (property.propertyType == SerializedPropertyType.Vector3)
{
property.vector3Value = Vector3.Max(property.vector3Value, new Vector3(minValueAttribute.MinValue, minValueAttribute.MinValue, minValueAttribute.MinValue));
}
else if (property.propertyType == SerializedPropertyType.Vector4)
{
property.vector4Value = Vector4.Max(property.vector4Value, new Vector4(minValueAttribute.MinValue, minValueAttribute.MinValue, minValueAttribute.MinValue, minValueAttribute.MinValue));
}
else if (property.propertyType == SerializedPropertyType.Vector2Int)
{
property.vector2IntValue = Vector2Int.Max(property.vector2IntValue, new Vector2Int((int)minValueAttribute.MinValue, (int)minValueAttribute.MinValue));
}
else if (property.propertyType == SerializedPropertyType.Vector3Int)
{
property.vector3IntValue = Vector3Int.Max(property.vector3IntValue, new Vector3Int((int)minValueAttribute.MinValue, (int)minValueAttribute.MinValue, (int)minValueAttribute.MinValue));
}
else
{
string warning = minValueAttribute.GetType().Name + " can be used only on int, float, Vector or VectorInt fields";
Debug.LogWarning(warning, property.serializedObject.targetObject);
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 03dd23f6c0598074fb1b721dcd8fe023
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 129996
packageName: NaughtyAttributes
packageVersion: 2.1.4
assetPath: Assets/NaughtyAttributes/Scripts/Editor/PropertyValidators/MinValuePropertyValidator.cs
uploadId: 480834

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using UnityEditor;
namespace NaughtyAttributes.Editor
{
public abstract class PropertyValidatorBase
{
public abstract void ValidateProperty(SerializedProperty property);
}
public static class ValidatorAttributeExtensions
{
private static Dictionary<Type, PropertyValidatorBase> _validatorsByAttributeType;
static ValidatorAttributeExtensions()
{
_validatorsByAttributeType = new Dictionary<Type, PropertyValidatorBase>();
_validatorsByAttributeType[typeof(MinValueAttribute)] = new MinValuePropertyValidator();
_validatorsByAttributeType[typeof(MaxValueAttribute)] = new MaxValuePropertyValidator();
_validatorsByAttributeType[typeof(RequiredAttribute)] = new RequiredPropertyValidator();
_validatorsByAttributeType[typeof(ValidateInputAttribute)] = new ValidateInputPropertyValidator();
}
public static PropertyValidatorBase GetValidator(this ValidatorAttribute attr)
{
PropertyValidatorBase validator;
if (_validatorsByAttributeType.TryGetValue(attr.GetType(), out validator))
{
return validator;
}
else
{
return null;
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: f332c8e1c3627d742aa9158af7b02ccc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 129996
packageName: NaughtyAttributes
packageVersion: 2.1.4
assetPath: Assets/NaughtyAttributes/Scripts/Editor/PropertyValidators/PropertyValidatorBase.cs
uploadId: 480834

View File

@@ -0,0 +1,31 @@
using UnityEditor;
namespace NaughtyAttributes.Editor
{
public class RequiredPropertyValidator : PropertyValidatorBase
{
public override void ValidateProperty(SerializedProperty property)
{
RequiredAttribute requiredAttribute = PropertyUtility.GetAttribute<RequiredAttribute>(property);
if (property.propertyType == SerializedPropertyType.ObjectReference)
{
if (property.objectReferenceValue == null)
{
string errorMessage = property.name + " is required";
if (!string.IsNullOrEmpty(requiredAttribute.Message))
{
errorMessage = requiredAttribute.Message;
}
NaughtyEditorGUI.HelpBox_Layout(errorMessage, MessageType.Error, context: property.serializedObject.targetObject);
}
}
else
{
string warning = requiredAttribute.GetType().Name + " works only on reference types";
NaughtyEditorGUI.HelpBox_Layout(warning, MessageType.Warning, context: property.serializedObject.targetObject);
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 3a7e657ea45f6414682b5f41be9541b4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 129996
packageName: NaughtyAttributes
packageVersion: 2.1.4
assetPath: Assets/NaughtyAttributes/Scripts/Editor/PropertyValidators/RequiredPropertyValidator.cs
uploadId: 480834

View File

@@ -0,0 +1,76 @@
using UnityEditor;
using System.Reflection;
using System;
namespace NaughtyAttributes.Editor
{
public class ValidateInputPropertyValidator : PropertyValidatorBase
{
public override void ValidateProperty(SerializedProperty property)
{
ValidateInputAttribute validateInputAttribute = PropertyUtility.GetAttribute<ValidateInputAttribute>(property);
object target = PropertyUtility.GetTargetObjectWithProperty(property);
MethodInfo validationCallback = ReflectionUtility.GetMethod(target, validateInputAttribute.CallbackName);
if (validationCallback != null &&
validationCallback.ReturnType == typeof(bool))
{
ParameterInfo[] callbackParameters = validationCallback.GetParameters();
if (callbackParameters.Length == 0)
{
if (!(bool)validationCallback.Invoke(target, null))
{
if (string.IsNullOrEmpty(validateInputAttribute.Message))
{
NaughtyEditorGUI.HelpBox_Layout(
property.name + " is not valid", MessageType.Error, context: property.serializedObject.targetObject);
}
else
{
NaughtyEditorGUI.HelpBox_Layout(
validateInputAttribute.Message, MessageType.Error, context: property.serializedObject.targetObject);
}
}
}
else if (callbackParameters.Length == 1)
{
FieldInfo fieldInfo = ReflectionUtility.GetField(target, property.name);
Type fieldType = fieldInfo.FieldType;
Type parameterType = callbackParameters[0].ParameterType;
if (fieldType == parameterType)
{
if (!(bool)validationCallback.Invoke(target, new object[] { fieldInfo.GetValue(target) }))
{
if (string.IsNullOrEmpty(validateInputAttribute.Message))
{
NaughtyEditorGUI.HelpBox_Layout(
property.name + " is not valid", MessageType.Error, context: property.serializedObject.targetObject);
}
else
{
NaughtyEditorGUI.HelpBox_Layout(
validateInputAttribute.Message, MessageType.Error, context: property.serializedObject.targetObject);
}
}
}
else
{
string warning = "The field type is not the same as the callback's parameter type";
NaughtyEditorGUI.HelpBox_Layout(warning, MessageType.Warning, context: property.serializedObject.targetObject);
}
}
else
{
string warning =
validateInputAttribute.GetType().Name +
" needs a callback with boolean return type and an optional single parameter of the same type as the field";
NaughtyEditorGUI.HelpBox_Layout(warning, MessageType.Warning, context: property.serializedObject.targetObject);
}
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 5f6adf84ed53a7840a456e8b4dce38d9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 129996
packageName: NaughtyAttributes
packageVersion: 2.1.4
assetPath: Assets/NaughtyAttributes/Scripts/Editor/PropertyValidators/ValidateInputPropertyValidator.cs
uploadId: 480834