From 763d530a5e67809dc835ec1c2e6310e613f01ff4 Mon Sep 17 00:00:00 2001 From: Ricardo Date: Wed, 31 May 2023 13:12:35 +0100 Subject: [PATCH] Added custom attributes --- Assets/RicUtils/Editor/AttributeDrawer.meta | 8 + .../ConstantSelectorAttributeDrawer.cs | 114 +++++++ .../ConstantSelectorAttributeDrawer.cs.meta | 11 + .../MaxValueAttributeDrawer.cs | 34 +++ .../MaxValueAttributeDrawer.cs.meta | 11 + .../MinValueAttributeDrawer.cs | 34 +++ .../MinValueAttributeDrawer.cs.meta | 11 + .../MustBeAssignedAttributeDrawer.cs | 110 +++++++ .../MustBeAssignedAttributeDrawer.cs.meta | 11 + .../NegativeValueOnlyAttributeDrawer.cs | 27 ++ .../NegativeValueOnlyAttributeDrawer.cs.meta | 11 + .../PositiveValueOnlyAttributeDrawer.cs | 27 ++ .../PositiveValueOnlyAttributeDrawer.cs.meta | 11 + .../ReadOnlyAttributeDrawer.cs | 30 ++ .../ReadOnlyAttributeDrawer.cs.meta | 11 + .../CreateScriptableObjectContextMenu.cs | 2 - .../CustomScriptableObjectCustomEditor.cs | 2 - .../Settings/RicUtils_EditorSettings.cs | 2 - .../Editor/Settings/ScriptableEditor.cs | 2 - .../RicUtils/Editor/UIElements/AdvButton.cs | 3 - .../DoCreateAvailableAsset.cs | 4 +- .../DoCreateAvailableAsset.cs.meta | 0 .../DoCreateEditorAsset.cs | 4 +- .../DoCreateEditorAsset.cs.meta | 0 .../Editor/Utilities/DoCreateScriptAsset.cs | 7 +- .../Editor/Utilities/EditorContainer.cs | 9 + .../Editor/Utilities/EditorGUIHelper.cs | 23 +- .../Editor/Utilities/FileUtilities.cs | 1 - .../Editor/Utilities/ToolUtilities.cs | 3 - .../CreateScriptableObjectEditorWindow.cs | 13 +- .../Editor/Windows/GenericEditorWindow.cs | 10 +- .../Editor/Windows/ProjectsSettingsDrawer.cs | 3 - .../RicUtils/Runtime/Scripts/Attributes.meta | 8 + .../Attributes/ConstantSelectorAttribute.cs | 8 + .../ConstantSelectorAttribute.cs.meta | 11 + .../Scripts/Attributes/MaxValueAttribute.cs | 31 ++ .../Attributes/MaxValueAttribute.cs.meta | 11 + .../Scripts/Attributes/MinValueAttribute.cs | 31 ++ .../Attributes/MinValueAttribute.cs.meta | 11 + .../Attributes/MustBeAssignedAttribute.cs | 9 + .../MustBeAssignedAttribute.cs.meta | 11 + .../Attributes/NegativeValueOnlyAttribute.cs | 8 + .../NegativeValueOnlyAttribute.cs.meta | 11 + .../Attributes/PositiveValueOnlyAttribute.cs | 8 + .../PositiveValueOnlyAttribute.cs.meta | 11 + .../Scripts/Attributes/ReadOnlyAttribute.cs | 26 ++ .../Attributes/ReadOnlyAttribute.cs.meta | 11 + Assets/RicUtils/Runtime/Scripts/Billboard.cs | 31 ++ .../Runtime/Scripts/Billboard.cs.meta | 11 + .../Scripts/Managers/DataGenericManager.cs | 3 - .../Scripts/Managers/GenericManager.cs | 2 - .../Scripts/Managers/SingletonCreation.cs | 2 - .../Managers/SingletonGenericManager.cs | 2 - .../RicUtils/Runtime/Scripts/PathConstants.cs | 3 - .../AvailableScriptableObject.cs | 1 - .../DataManagerScriptableObject.cs | 2 - .../GenericScriptableObject.cs | 2 - .../Settings/RicUtils_RuntimeSettings.cs | 2 - .../Scripts/Settings/SingletonManager.cs | 4 - .../Scripts/Utilities/ReflectionUtilities.cs | 2 - .../Runtime/Scripts/Utilities/RicUtilities.cs | 2 - .../Utilities/SerializedPropertyUtilities.cs | 282 ++++++++++++++++++ .../SerializedPropertyUtilities.cs.meta | 11 + 63 files changed, 1039 insertions(+), 78 deletions(-) create mode 100644 Assets/RicUtils/Editor/AttributeDrawer.meta create mode 100644 Assets/RicUtils/Editor/AttributeDrawer/ConstantSelectorAttributeDrawer.cs create mode 100644 Assets/RicUtils/Editor/AttributeDrawer/ConstantSelectorAttributeDrawer.cs.meta create mode 100644 Assets/RicUtils/Editor/AttributeDrawer/MaxValueAttributeDrawer.cs create mode 100644 Assets/RicUtils/Editor/AttributeDrawer/MaxValueAttributeDrawer.cs.meta create mode 100644 Assets/RicUtils/Editor/AttributeDrawer/MinValueAttributeDrawer.cs create mode 100644 Assets/RicUtils/Editor/AttributeDrawer/MinValueAttributeDrawer.cs.meta create mode 100644 Assets/RicUtils/Editor/AttributeDrawer/MustBeAssignedAttributeDrawer.cs create mode 100644 Assets/RicUtils/Editor/AttributeDrawer/MustBeAssignedAttributeDrawer.cs.meta create mode 100644 Assets/RicUtils/Editor/AttributeDrawer/NegativeValueOnlyAttributeDrawer.cs create mode 100644 Assets/RicUtils/Editor/AttributeDrawer/NegativeValueOnlyAttributeDrawer.cs.meta create mode 100644 Assets/RicUtils/Editor/AttributeDrawer/PositiveValueOnlyAttributeDrawer.cs create mode 100644 Assets/RicUtils/Editor/AttributeDrawer/PositiveValueOnlyAttributeDrawer.cs.meta create mode 100644 Assets/RicUtils/Editor/AttributeDrawer/ReadOnlyAttributeDrawer.cs create mode 100644 Assets/RicUtils/Editor/AttributeDrawer/ReadOnlyAttributeDrawer.cs.meta rename Assets/RicUtils/Editor/{ContextMenu => Utilities}/DoCreateAvailableAsset.cs (80%) rename Assets/RicUtils/Editor/{ContextMenu => Utilities}/DoCreateAvailableAsset.cs.meta (100%) rename Assets/RicUtils/Editor/{ContextMenu => Utilities}/DoCreateEditorAsset.cs (85%) rename Assets/RicUtils/Editor/{ContextMenu => Utilities}/DoCreateEditorAsset.cs.meta (100%) create mode 100644 Assets/RicUtils/Runtime/Scripts/Attributes.meta create mode 100644 Assets/RicUtils/Runtime/Scripts/Attributes/ConstantSelectorAttribute.cs create mode 100644 Assets/RicUtils/Runtime/Scripts/Attributes/ConstantSelectorAttribute.cs.meta create mode 100644 Assets/RicUtils/Runtime/Scripts/Attributes/MaxValueAttribute.cs create mode 100644 Assets/RicUtils/Runtime/Scripts/Attributes/MaxValueAttribute.cs.meta create mode 100644 Assets/RicUtils/Runtime/Scripts/Attributes/MinValueAttribute.cs create mode 100644 Assets/RicUtils/Runtime/Scripts/Attributes/MinValueAttribute.cs.meta create mode 100644 Assets/RicUtils/Runtime/Scripts/Attributes/MustBeAssignedAttribute.cs create mode 100644 Assets/RicUtils/Runtime/Scripts/Attributes/MustBeAssignedAttribute.cs.meta create mode 100644 Assets/RicUtils/Runtime/Scripts/Attributes/NegativeValueOnlyAttribute.cs create mode 100644 Assets/RicUtils/Runtime/Scripts/Attributes/NegativeValueOnlyAttribute.cs.meta create mode 100644 Assets/RicUtils/Runtime/Scripts/Attributes/PositiveValueOnlyAttribute.cs create mode 100644 Assets/RicUtils/Runtime/Scripts/Attributes/PositiveValueOnlyAttribute.cs.meta create mode 100644 Assets/RicUtils/Runtime/Scripts/Attributes/ReadOnlyAttribute.cs create mode 100644 Assets/RicUtils/Runtime/Scripts/Attributes/ReadOnlyAttribute.cs.meta create mode 100644 Assets/RicUtils/Runtime/Scripts/Billboard.cs create mode 100644 Assets/RicUtils/Runtime/Scripts/Billboard.cs.meta create mode 100644 Assets/RicUtils/Runtime/Scripts/Utilities/SerializedPropertyUtilities.cs create mode 100644 Assets/RicUtils/Runtime/Scripts/Utilities/SerializedPropertyUtilities.cs.meta diff --git a/Assets/RicUtils/Editor/AttributeDrawer.meta b/Assets/RicUtils/Editor/AttributeDrawer.meta new file mode 100644 index 0000000..9ad4fb8 --- /dev/null +++ b/Assets/RicUtils/Editor/AttributeDrawer.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f1378a72fe72fbe4cae5905bb9ae9832 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RicUtils/Editor/AttributeDrawer/ConstantSelectorAttributeDrawer.cs b/Assets/RicUtils/Editor/AttributeDrawer/ConstantSelectorAttributeDrawer.cs new file mode 100644 index 0000000..f8936a1 --- /dev/null +++ b/Assets/RicUtils/Editor/AttributeDrawer/ConstantSelectorAttributeDrawer.cs @@ -0,0 +1,114 @@ +using RicUtils.Attributes; +using RicUtils.Editor.Utilities; +using System; +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +namespace RicUtils.Editor.AttributeDrawer +{ + [CustomPropertyDrawer(typeof(ConstantSelectorAttribute))] + public class ConstantSelectorAttributeDrawer : PropertyDrawer + { + private ConstantSelectorAttribute cachedProperty; + private Type targetType; + private string[] names; + private object[] values; + private int selectedIndex; + private bool foundValue; + + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) + { + return EditorGUI.GetPropertyHeight(property, label); + } + + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + CacheProperty(property); + + if (values == null || values.Length == 0) + { + EditorGUI.PropertyField(position, property, label); + return; + } + + if (targetType != fieldInfo.FieldType) + { + EditorGUI.HelpBox(position, $"[ConstantSelector] '{targetType}' is not the same as '{fieldInfo.FieldType}'", MessageType.Error); + return; + } + + if (!foundValue && selectedIndex == 0) + { + EditorGUIHelper.DrawBox(position, Color.yellow); + } + + EditorGUI.BeginChangeCheck(); + selectedIndex = EditorGUI.Popup(position, label.text, selectedIndex, names); + if (EditorGUI.EndChangeCheck()) + { + fieldInfo.SetValue(property.serializedObject.targetObject, values[selectedIndex]); + property.serializedObject.ApplyModifiedProperties(); + EditorUtility.SetDirty(property.serializedObject.targetObject); + } + } + + private void CacheProperty(SerializedProperty property) + { + if (cachedProperty == null) + { + cachedProperty = attribute as ConstantSelectorAttribute; + + targetType = fieldInfo.FieldType; + + var fields = targetType.GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.FlattenHierarchy); + var properties = targetType.GetProperties(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.FlattenHierarchy); + + List names = new List(); + List values = new List(); + + foreach (var field in fields) + { + if ((field.IsInitOnly || field.IsLiteral) && field.FieldType == targetType) + { + names.Add(field.Name); + values.Add(field.GetValue(null)); + } + } + + foreach (var p in properties) + { + if (p.PropertyType == targetType) + { + names.Add(p.Name); + values.Add(p.GetValue(null)); + } + } + + var currentValue = fieldInfo.GetValue(property.serializedObject.targetObject); + if (currentValue != null) + { + for (int i = 0; i < values.Count; i++) + { + if (currentValue.Equals(values[i])) + { + foundValue = true; + selectedIndex = i; + } + } + } + + if (!foundValue) + { + var value = fieldInfo.GetValue(property.serializedObject.targetObject); + var valueString = value == null ? "NULL" : value.ToString(); + names.Add("ERROR: NO " + valueString); + values.Add(value); + } + + this.names = names.ToArray(); + this.values = values.ToArray(); + } + } + } +} diff --git a/Assets/RicUtils/Editor/AttributeDrawer/ConstantSelectorAttributeDrawer.cs.meta b/Assets/RicUtils/Editor/AttributeDrawer/ConstantSelectorAttributeDrawer.cs.meta new file mode 100644 index 0000000..290fdba --- /dev/null +++ b/Assets/RicUtils/Editor/AttributeDrawer/ConstantSelectorAttributeDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 27bfd9e945e6b61449142a074964b558 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RicUtils/Editor/AttributeDrawer/MaxValueAttributeDrawer.cs b/Assets/RicUtils/Editor/AttributeDrawer/MaxValueAttributeDrawer.cs new file mode 100644 index 0000000..945bc27 --- /dev/null +++ b/Assets/RicUtils/Editor/AttributeDrawer/MaxValueAttributeDrawer.cs @@ -0,0 +1,34 @@ +using RicUtils.Attributes; +using RicUtils.Utilities; +using UnityEditor; +using UnityEngine; + +namespace RicUtils.Editor.AttributeDrawer +{ + [CustomPropertyDrawer(typeof(MaxValueAttribute))] + public class MaxValueAttributeDrawer : PropertyDrawer + { + private MaxValueAttribute cachedAttribute; + + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) + { + return EditorGUI.GetPropertyHeight(property, label); + } + + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + if (cachedAttribute == null) cachedAttribute = attribute as MaxValueAttribute; + + if (!property.IsNumerical() && !property.IsVector()) + { + EditorGUI.HelpBox(position, "[MaxValue] used with non-numeric property", MessageType.Warning); + return; + } + if ((property.IsNumerical() && property.HandleMaxNumericalValues(cachedAttribute.X)) || + (property.IsVectorInt() && property.HandleMaxVectorIntValues(new Vector3Int((int)cachedAttribute.X, (int)cachedAttribute.Y, (int)cachedAttribute.Z))) || + (property.IsVectorFloat() && property.HandleMaxVectorValues(new Vector4(cachedAttribute.X, cachedAttribute.Y, cachedAttribute.Z, cachedAttribute.W)))) + property.serializedObject.ApplyModifiedProperties(); + EditorGUI.PropertyField(position, property, label, true); + } + } +} diff --git a/Assets/RicUtils/Editor/AttributeDrawer/MaxValueAttributeDrawer.cs.meta b/Assets/RicUtils/Editor/AttributeDrawer/MaxValueAttributeDrawer.cs.meta new file mode 100644 index 0000000..a28e501 --- /dev/null +++ b/Assets/RicUtils/Editor/AttributeDrawer/MaxValueAttributeDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7b8de04bfadf8e04ba10548296f3d14e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RicUtils/Editor/AttributeDrawer/MinValueAttributeDrawer.cs b/Assets/RicUtils/Editor/AttributeDrawer/MinValueAttributeDrawer.cs new file mode 100644 index 0000000..687dd08 --- /dev/null +++ b/Assets/RicUtils/Editor/AttributeDrawer/MinValueAttributeDrawer.cs @@ -0,0 +1,34 @@ +using RicUtils.Attributes; +using RicUtils.Utilities; +using UnityEditor; +using UnityEngine; + +namespace RicUtils.Editor +{ + [CustomPropertyDrawer(typeof(MinValueAttribute))] + public class MinValueAttributeDrawer : PropertyDrawer + { + private MinValueAttribute cachedAttribute; + + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) + { + return EditorGUI.GetPropertyHeight(property, label); + } + + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + if (cachedAttribute == null) cachedAttribute = attribute as MinValueAttribute; + + if (!property.IsNumerical() && !property.IsVector()) + { + EditorGUI.HelpBox(position, "[MinValue] used with non-numeric property", MessageType.Warning); + return; + } + if ((property.IsNumerical() && property.HandleMinNumericalValues(cachedAttribute.X)) || + (property.IsVectorInt() && property.HandleMinVectorIntValues(new Vector3Int((int)cachedAttribute.X, (int)cachedAttribute.Y, (int)cachedAttribute.Z))) || + (property.IsVectorFloat() && property.HandleMinVectorValues(new Vector4(cachedAttribute.X, cachedAttribute.Y, cachedAttribute.Z, cachedAttribute.W)))) + property.serializedObject.ApplyModifiedProperties(); + EditorGUI.PropertyField(position, property, label, true); + } + } +} diff --git a/Assets/RicUtils/Editor/AttributeDrawer/MinValueAttributeDrawer.cs.meta b/Assets/RicUtils/Editor/AttributeDrawer/MinValueAttributeDrawer.cs.meta new file mode 100644 index 0000000..91e4bd0 --- /dev/null +++ b/Assets/RicUtils/Editor/AttributeDrawer/MinValueAttributeDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e43b8bf3ce1a0cc48bfc7ce3df862e30 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RicUtils/Editor/AttributeDrawer/MustBeAssignedAttributeDrawer.cs b/Assets/RicUtils/Editor/AttributeDrawer/MustBeAssignedAttributeDrawer.cs new file mode 100644 index 0000000..cead3b9 --- /dev/null +++ b/Assets/RicUtils/Editor/AttributeDrawer/MustBeAssignedAttributeDrawer.cs @@ -0,0 +1,110 @@ +using RicUtils.Attributes; +using RicUtils.Editor.Utilities; +using System.Reflection; +using UnityEditor; +using UnityEngine; + +namespace RicUtils.Editor.AttributeDrawer +{ + [CustomPropertyDrawer(typeof(MustBeAssignedAttribute))] + public class MustBeAssignedAttributeDrawer : PropertyDrawer + { + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + if (MustBeAssignedCheck.GetError(fieldInfo, property.serializedObject.targetObject) > 0) + { + EditorGUIHelper.DrawBox(position, Color.red); + } + + EditorGUI.PropertyField(position, property, label); + } + } + + [InitializeOnLoad] + internal class MustBeAssignedCheck : UnityEditor.AssetModificationProcessor + { + static MustBeAssignedCheck() + { + Assert(); + } + + public static string[] OnWillSaveAssets(string[] paths) + { + if (paths.Length == 1 && (paths[0] == null || paths[0].EndsWith(".prefab"))) return paths; + + Assert(); + + return paths; + } + + private static void Assert() + { + var behaviours = Object.FindObjectsOfType(true); + + foreach (var behaviour in behaviours) + { + if (behaviour == null) continue; + + var objType = behaviour.GetType(); + var fields = objType.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); + + foreach (var field in fields) + { + if (!field.IsDefined(typeof(MustBeAssignedAttribute), false) && !field.IsDefined(typeof(SerializeField), false)) continue; + + var error = GetError(field, behaviour); + + switch (error) + { + case 1: + Debug.LogError($"{objType.Name}: '{field.Name}' is Value Type with default value", behaviour); + break; + case 2: + Debug.LogError($"{objType.Name}: '{field.Name}' not assigned (null value)", behaviour); + break; + case 3: + Debug.LogError($"{objType.Name}: '{field.Name}' not assigned (empty string)", behaviour); + break; + case 4: + Debug.LogError($"{objType.Name}: '{field.Name}' not assigned (empty array)", behaviour); + break; + } + } + } + } + + public static int GetError(FieldInfo field, Object targetObject) + { + var value = field.GetValue(targetObject); + bool valueTypeWithDefaultValue = field.FieldType.IsValueType && System.Activator.CreateInstance(field.FieldType).Equals(value); + if (valueTypeWithDefaultValue) + { + return 1; + } + + + bool nullReferenceType = value == null || value.Equals(null); + if (nullReferenceType) + { + return 2; + } + + + bool emptyString = field.FieldType == typeof(string) && (string)value == string.Empty; + if (emptyString) + { + return 3; + } + + + var arr = value as System.Array; + bool emptyArray = arr != null && arr.Length == 0; + if (emptyArray) + { + return 4; + } + + return 0; + } + } +} diff --git a/Assets/RicUtils/Editor/AttributeDrawer/MustBeAssignedAttributeDrawer.cs.meta b/Assets/RicUtils/Editor/AttributeDrawer/MustBeAssignedAttributeDrawer.cs.meta new file mode 100644 index 0000000..5ea1951 --- /dev/null +++ b/Assets/RicUtils/Editor/AttributeDrawer/MustBeAssignedAttributeDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1c2456fe1938f164cb8217f172ec7288 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RicUtils/Editor/AttributeDrawer/NegativeValueOnlyAttributeDrawer.cs b/Assets/RicUtils/Editor/AttributeDrawer/NegativeValueOnlyAttributeDrawer.cs new file mode 100644 index 0000000..608bf59 --- /dev/null +++ b/Assets/RicUtils/Editor/AttributeDrawer/NegativeValueOnlyAttributeDrawer.cs @@ -0,0 +1,27 @@ +using RicUtils.Attributes; +using RicUtils.Utilities; +using UnityEditor; +using UnityEngine; + +namespace RicUtils.Editor.AttributeDrawer +{ + [CustomPropertyDrawer(typeof(NegativeValueOnlyAttribute))] + public class NegativeValueOnlyAttributeDrawer : PropertyDrawer + { + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) + { + return EditorGUI.GetPropertyHeight(property, label); + } + + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + if (!property.IsNumerical() && !property.IsVector()) + { + EditorGUI.HelpBox(position, "[NegativeValueOnly] used with non-numeric property", MessageType.Warning); + return; + } + if (property.HandleMaxValues(0)) property.serializedObject.ApplyModifiedProperties(); + EditorGUI.PropertyField(position, property, label, true); + } + } +} diff --git a/Assets/RicUtils/Editor/AttributeDrawer/NegativeValueOnlyAttributeDrawer.cs.meta b/Assets/RicUtils/Editor/AttributeDrawer/NegativeValueOnlyAttributeDrawer.cs.meta new file mode 100644 index 0000000..6d6f738 --- /dev/null +++ b/Assets/RicUtils/Editor/AttributeDrawer/NegativeValueOnlyAttributeDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 40ccbe663aba0664b91e47e8f3945b19 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RicUtils/Editor/AttributeDrawer/PositiveValueOnlyAttributeDrawer.cs b/Assets/RicUtils/Editor/AttributeDrawer/PositiveValueOnlyAttributeDrawer.cs new file mode 100644 index 0000000..273f1f2 --- /dev/null +++ b/Assets/RicUtils/Editor/AttributeDrawer/PositiveValueOnlyAttributeDrawer.cs @@ -0,0 +1,27 @@ +using RicUtils.Attributes; +using RicUtils.Utilities; +using UnityEditor; +using UnityEngine; + +namespace RicUtils.Editor.AttributeDrawer +{ + [CustomPropertyDrawer(typeof(PositiveValueOnlyAttribute))] + public class PositiveValueOnlyAttributeDrawer : PropertyDrawer + { + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) + { + return EditorGUI.GetPropertyHeight(property, label); + } + + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + if (!property.IsNumerical() && !property.IsVector()) + { + EditorGUI.HelpBox(position, "[PositiveValueOnly] used with non-numeric property", MessageType.Warning); + return; + } + if (property.HandleMinValues(0)) property.serializedObject.ApplyModifiedProperties(); + EditorGUI.PropertyField(position, property, label, true); + } + } +} diff --git a/Assets/RicUtils/Editor/AttributeDrawer/PositiveValueOnlyAttributeDrawer.cs.meta b/Assets/RicUtils/Editor/AttributeDrawer/PositiveValueOnlyAttributeDrawer.cs.meta new file mode 100644 index 0000000..a93d038 --- /dev/null +++ b/Assets/RicUtils/Editor/AttributeDrawer/PositiveValueOnlyAttributeDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7bca4f56ada8d034ba09bf58073b262b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RicUtils/Editor/AttributeDrawer/ReadOnlyAttributeDrawer.cs b/Assets/RicUtils/Editor/AttributeDrawer/ReadOnlyAttributeDrawer.cs new file mode 100644 index 0000000..73860e9 --- /dev/null +++ b/Assets/RicUtils/Editor/AttributeDrawer/ReadOnlyAttributeDrawer.cs @@ -0,0 +1,30 @@ +using RicUtils.Attributes; +using UnityEditor; +using UnityEngine; + +namespace RicUtils.Editor.AttributeDrawer +{ + [CustomPropertyDrawer(typeof(ReadOnlyAttribute))] + public class ReadOnlyAttributeDrawer : PropertyDrawer + { + private ReadOnlyAttribute cachedAttribute; + + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) + { + return EditorGUI.GetPropertyHeight(property, label); + } + + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + if (cachedAttribute == null) cachedAttribute = attribute as ReadOnlyAttribute; + + var enabled = cachedAttribute.PlayMode == AvailableMode.All + || ((EditorApplication.isPlaying && cachedAttribute.PlayMode == AvailableMode.Play) + || (!EditorApplication.isPlaying && cachedAttribute.PlayMode == AvailableMode.Editor)); + + GUI.enabled = !enabled; + EditorGUI.PropertyField(position, property, label, true); + GUI.enabled = true; + } + } +} diff --git a/Assets/RicUtils/Editor/AttributeDrawer/ReadOnlyAttributeDrawer.cs.meta b/Assets/RicUtils/Editor/AttributeDrawer/ReadOnlyAttributeDrawer.cs.meta new file mode 100644 index 0000000..773d66b --- /dev/null +++ b/Assets/RicUtils/Editor/AttributeDrawer/ReadOnlyAttributeDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 43efa2f08a0f69849987b76d748bd06f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RicUtils/Editor/ContextMenu/CreateScriptableObjectContextMenu.cs b/Assets/RicUtils/Editor/ContextMenu/CreateScriptableObjectContextMenu.cs index ff0a928..b92137a 100644 --- a/Assets/RicUtils/Editor/ContextMenu/CreateScriptableObjectContextMenu.cs +++ b/Assets/RicUtils/Editor/ContextMenu/CreateScriptableObjectContextMenu.cs @@ -1,6 +1,4 @@ using RicUtils.Editor.Windows; -using System.Collections; -using System.Collections.Generic; using UnityEditor; using UnityEngine; diff --git a/Assets/RicUtils/Editor/CustomEditor/CustomScriptableObjectCustomEditor.cs b/Assets/RicUtils/Editor/CustomEditor/CustomScriptableObjectCustomEditor.cs index f14af93..fac8321 100644 --- a/Assets/RicUtils/Editor/CustomEditor/CustomScriptableObjectCustomEditor.cs +++ b/Assets/RicUtils/Editor/CustomEditor/CustomScriptableObjectCustomEditor.cs @@ -1,7 +1,5 @@ using RicUtils.Editor.Utilities; using RicUtils.ScriptableObjects; -using System.Collections; -using System.Collections.Generic; using UnityEditor; using UnityEngine; diff --git a/Assets/RicUtils/Editor/Settings/RicUtils_EditorSettings.cs b/Assets/RicUtils/Editor/Settings/RicUtils_EditorSettings.cs index d540db9..b3d100f 100644 --- a/Assets/RicUtils/Editor/Settings/RicUtils_EditorSettings.cs +++ b/Assets/RicUtils/Editor/Settings/RicUtils_EditorSettings.cs @@ -1,6 +1,4 @@ using RicUtils.Utilities; -using System.Collections; -using System.Collections.Generic; using UnityEditor; using UnityEngine; diff --git a/Assets/RicUtils/Editor/Settings/ScriptableEditor.cs b/Assets/RicUtils/Editor/Settings/ScriptableEditor.cs index 43458b3..570dba4 100644 --- a/Assets/RicUtils/Editor/Settings/ScriptableEditor.cs +++ b/Assets/RicUtils/Editor/Settings/ScriptableEditor.cs @@ -1,8 +1,6 @@ using RicUtils.Editor.Windows; using RicUtils.ScriptableObjects; using TypeReferences; -using UnityEditor; -using UnityEngine; namespace RicUtils.Editor.Settings { diff --git a/Assets/RicUtils/Editor/UIElements/AdvButton.cs b/Assets/RicUtils/Editor/UIElements/AdvButton.cs index 2e9ed66..0197547 100644 --- a/Assets/RicUtils/Editor/UIElements/AdvButton.cs +++ b/Assets/RicUtils/Editor/UIElements/AdvButton.cs @@ -1,6 +1,3 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; using UnityEngine.Scripting; using UnityEngine.UIElements; diff --git a/Assets/RicUtils/Editor/ContextMenu/DoCreateAvailableAsset.cs b/Assets/RicUtils/Editor/Utilities/DoCreateAvailableAsset.cs similarity index 80% rename from Assets/RicUtils/Editor/ContextMenu/DoCreateAvailableAsset.cs rename to Assets/RicUtils/Editor/Utilities/DoCreateAvailableAsset.cs index b6f6bbe..c26a229 100644 --- a/Assets/RicUtils/Editor/ContextMenu/DoCreateAvailableAsset.cs +++ b/Assets/RicUtils/Editor/Utilities/DoCreateAvailableAsset.cs @@ -1,6 +1,4 @@ -using RicUtils.Editor.Utilities; - -namespace RicUtils.Editor.ContextMenu +namespace RicUtils.Editor.Utilities { internal class DoCreateAvailableAsset : DoCreateScriptAsset { diff --git a/Assets/RicUtils/Editor/ContextMenu/DoCreateAvailableAsset.cs.meta b/Assets/RicUtils/Editor/Utilities/DoCreateAvailableAsset.cs.meta similarity index 100% rename from Assets/RicUtils/Editor/ContextMenu/DoCreateAvailableAsset.cs.meta rename to Assets/RicUtils/Editor/Utilities/DoCreateAvailableAsset.cs.meta diff --git a/Assets/RicUtils/Editor/ContextMenu/DoCreateEditorAsset.cs b/Assets/RicUtils/Editor/Utilities/DoCreateEditorAsset.cs similarity index 85% rename from Assets/RicUtils/Editor/ContextMenu/DoCreateEditorAsset.cs rename to Assets/RicUtils/Editor/Utilities/DoCreateEditorAsset.cs index 44a0617..784487f 100644 --- a/Assets/RicUtils/Editor/ContextMenu/DoCreateEditorAsset.cs +++ b/Assets/RicUtils/Editor/Utilities/DoCreateEditorAsset.cs @@ -1,6 +1,4 @@ -using RicUtils.Editor.Utilities; - -namespace RicUtils.Editor.ContextMenu +namespace RicUtils.Editor.Utilities { internal class DoCreateEditorAsset : DoCreateScriptAsset { diff --git a/Assets/RicUtils/Editor/ContextMenu/DoCreateEditorAsset.cs.meta b/Assets/RicUtils/Editor/Utilities/DoCreateEditorAsset.cs.meta similarity index 100% rename from Assets/RicUtils/Editor/ContextMenu/DoCreateEditorAsset.cs.meta rename to Assets/RicUtils/Editor/Utilities/DoCreateEditorAsset.cs.meta diff --git a/Assets/RicUtils/Editor/Utilities/DoCreateScriptAsset.cs b/Assets/RicUtils/Editor/Utilities/DoCreateScriptAsset.cs index 8e60714..c8a9584 100644 --- a/Assets/RicUtils/Editor/Utilities/DoCreateScriptAsset.cs +++ b/Assets/RicUtils/Editor/Utilities/DoCreateScriptAsset.cs @@ -1,9 +1,4 @@ -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using System.Text.RegularExpressions; -using UnityEditor; -using UnityEditor.Compilation; +using UnityEditor; using UnityEditor.ProjectWindowCallback; using UnityEngine; diff --git a/Assets/RicUtils/Editor/Utilities/EditorContainer.cs b/Assets/RicUtils/Editor/Utilities/EditorContainer.cs index e529dea..d164d57 100644 --- a/Assets/RicUtils/Editor/Utilities/EditorContainer.cs +++ b/Assets/RicUtils/Editor/Utilities/EditorContainer.cs @@ -7,6 +7,15 @@ public sealed class EditorContainer public static implicit operator TValueType(EditorContainer value) { return value.Value; } public static explicit operator EditorContainer(TValueType value) { return new EditorContainer() { Value = value }; } + public EditorContainer() : this(default) + { + } + + public EditorContainer(TValueType value) + { + Value = value; + } + public bool IsNull() { return Value == null; diff --git a/Assets/RicUtils/Editor/Utilities/EditorGUIHelper.cs b/Assets/RicUtils/Editor/Utilities/EditorGUIHelper.cs index af5741a..74186f9 100644 --- a/Assets/RicUtils/Editor/Utilities/EditorGUIHelper.cs +++ b/Assets/RicUtils/Editor/Utilities/EditorGUIHelper.cs @@ -1,7 +1,4 @@ using RicUtils.Editor.UIElements; -using System.Collections; -using System.Linq; -using System.Reflection; using UnityEditor; using UnityEditor.UIElements; using UnityEngine; @@ -412,5 +409,25 @@ public static void AddCommonStylesheet(this VisualElement root) { root.AddStylesheet("RicUtils/Common.uss"); } + + public static void ToggleClass(this VisualElement root, string className, bool value) + { + if (value) + { + root.AddToClassList(className); + } + else + { + root.RemoveFromClassList(className); + } + } + + public static void DrawBox(Rect rect, Color color) + { + var backgroundColor = GUI.backgroundColor; + GUI.backgroundColor = color; + GUI.Box(rect, ""); + GUI.backgroundColor = backgroundColor; + } } } diff --git a/Assets/RicUtils/Editor/Utilities/FileUtilities.cs b/Assets/RicUtils/Editor/Utilities/FileUtilities.cs index 4c51e41..2572b60 100644 --- a/Assets/RicUtils/Editor/Utilities/FileUtilities.cs +++ b/Assets/RicUtils/Editor/Utilities/FileUtilities.cs @@ -1,4 +1,3 @@ -using System.Collections; using System.Collections.Generic; using System.IO; using System.Reflection; diff --git a/Assets/RicUtils/Editor/Utilities/ToolUtilities.cs b/Assets/RicUtils/Editor/Utilities/ToolUtilities.cs index 3f86c5a..cd404b8 100644 --- a/Assets/RicUtils/Editor/Utilities/ToolUtilities.cs +++ b/Assets/RicUtils/Editor/Utilities/ToolUtilities.cs @@ -2,12 +2,9 @@ using RicUtils.ScriptableObjects; using RicUtils.Utilities; using System.Collections.Generic; -using System.ComponentModel; -using System.IO; using System.Reflection; using UnityEditor; using UnityEditor.Callbacks; -using UnityEditor.ProjectWindowCallback; using UnityEngine; using UnityEngine.UIElements; diff --git a/Assets/RicUtils/Editor/Windows/CreateScriptableObjectEditorWindow.cs b/Assets/RicUtils/Editor/Windows/CreateScriptableObjectEditorWindow.cs index a5eecc7..0aa4bf0 100644 --- a/Assets/RicUtils/Editor/Windows/CreateScriptableObjectEditorWindow.cs +++ b/Assets/RicUtils/Editor/Windows/CreateScriptableObjectEditorWindow.cs @@ -1,8 +1,5 @@ -using RicUtils.Editor.ContextMenu; using RicUtils.Editor.Settings; using RicUtils.Editor.Utilities; -using RicUtils.ScriptableObjects; -using System.Collections; using System.Collections.Generic; using System.IO; using UnityEditor; @@ -10,7 +7,6 @@ using UnityEditor.Compilation; using UnityEngine; using UnityEngine.UIElements; -using static UnityEngine.GraphicsBuffer; namespace RicUtils.Editor.Windows { @@ -173,14 +169,7 @@ private void CreateAssets() private void ToggleWarning(bool visible) { - if (visible) - { - emptyFieldWarningContainer.RemoveFromClassList("hidden"); - } - else - { - emptyFieldWarningContainer.AddToClassList("hidden"); - } + emptyFieldWarningContainer.ToggleClass("hidden", !visible); } [DidReloadScripts] diff --git a/Assets/RicUtils/Editor/Windows/GenericEditorWindow.cs b/Assets/RicUtils/Editor/Windows/GenericEditorWindow.cs index e659f80..dbb7493 100644 --- a/Assets/RicUtils/Editor/Windows/GenericEditorWindow.cs +++ b/Assets/RicUtils/Editor/Windows/GenericEditorWindow.cs @@ -1,10 +1,8 @@ using RicUtils.Editor.Utilities; using RicUtils.ScriptableObjects; using RicUtils.Utilities; -using System.Collections; using System.Collections.Generic; using UnityEditor; -using UnityEditor.Callbacks; using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements; @@ -228,7 +226,7 @@ private void CheckCompletion() saveButton.tooltip = tooltip; } - protected void RegisterCheckCompletion(INotifyValueChanged control) + public void RegisterCheckCompletion(INotifyValueChanged control) { control.RegisterValueChangedCallback(callback => { @@ -236,7 +234,7 @@ protected void RegisterCheckCompletion(INotifyValueChanged(BaseField element, EditorContainer editorContainer) + public void RegisterLoadChange(BaseField element, EditorContainer editorContainer) { onLoad += () => { @@ -244,7 +242,7 @@ protected void RegisterLoadChange(BaseField element, Edi }; } - protected void RegisterLoadChange(BaseField element, EditorContainer editorContainer) where TValueType : System.Enum + public void RegisterLoadChange(BaseField element, EditorContainer editorContainer) where TValueType : System.Enum { onLoad += () => { @@ -252,7 +250,7 @@ protected void RegisterLoadChange(BaseField element, Ed }; } - protected void RegisterLoadChange(ObjectField element, EditorContainer editorContainer) where TValueType : Object + public void RegisterLoadChange(ObjectField element, EditorContainer editorContainer) where TValueType : Object { onLoad += () => { diff --git a/Assets/RicUtils/Editor/Windows/ProjectsSettingsDrawer.cs b/Assets/RicUtils/Editor/Windows/ProjectsSettingsDrawer.cs index b49b360..c96d126 100644 --- a/Assets/RicUtils/Editor/Windows/ProjectsSettingsDrawer.cs +++ b/Assets/RicUtils/Editor/Windows/ProjectsSettingsDrawer.cs @@ -1,11 +1,8 @@ -using Codice.CM.Common; using RicUtils.Editor.Settings; -using RicUtils.Editor.Utilities; using RicUtils.Managers; using RicUtils.ScriptableObjects; using RicUtils.Settings; using RicUtils.Utilities; -using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEditorInternal; diff --git a/Assets/RicUtils/Runtime/Scripts/Attributes.meta b/Assets/RicUtils/Runtime/Scripts/Attributes.meta new file mode 100644 index 0000000..10ebab4 --- /dev/null +++ b/Assets/RicUtils/Runtime/Scripts/Attributes.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: cef59fcad9aafc24780690acf758c2da +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RicUtils/Runtime/Scripts/Attributes/ConstantSelectorAttribute.cs b/Assets/RicUtils/Runtime/Scripts/Attributes/ConstantSelectorAttribute.cs new file mode 100644 index 0000000..518b8d2 --- /dev/null +++ b/Assets/RicUtils/Runtime/Scripts/Attributes/ConstantSelectorAttribute.cs @@ -0,0 +1,8 @@ +using UnityEngine; + +namespace RicUtils.Attributes +{ + public class ConstantSelectorAttribute : PropertyAttribute + { + } +} diff --git a/Assets/RicUtils/Runtime/Scripts/Attributes/ConstantSelectorAttribute.cs.meta b/Assets/RicUtils/Runtime/Scripts/Attributes/ConstantSelectorAttribute.cs.meta new file mode 100644 index 0000000..b3545fd --- /dev/null +++ b/Assets/RicUtils/Runtime/Scripts/Attributes/ConstantSelectorAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5182945001e491e4bad2a27e3ed83fe9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RicUtils/Runtime/Scripts/Attributes/MaxValueAttribute.cs b/Assets/RicUtils/Runtime/Scripts/Attributes/MaxValueAttribute.cs new file mode 100644 index 0000000..7e2824d --- /dev/null +++ b/Assets/RicUtils/Runtime/Scripts/Attributes/MaxValueAttribute.cs @@ -0,0 +1,31 @@ +using UnityEngine; + +namespace RicUtils.Attributes +{ + public class MaxValueAttribute : PropertyAttribute + { + public readonly float X, Y, Z, W; + + public MaxValueAttribute(float value) : this(value, value, value, value) + { + + } + + public MaxValueAttribute(float x, float y) : this(x, y, 0) + { + + } + + public MaxValueAttribute(float x, float y, float z) : this(x, y, z, 0) + { + } + + public MaxValueAttribute(float x, float y, float z, float w) + { + this.X = x; + this.Y = y; + this.Z = z; + this.W = w; + } + } +} diff --git a/Assets/RicUtils/Runtime/Scripts/Attributes/MaxValueAttribute.cs.meta b/Assets/RicUtils/Runtime/Scripts/Attributes/MaxValueAttribute.cs.meta new file mode 100644 index 0000000..8ae2cfc --- /dev/null +++ b/Assets/RicUtils/Runtime/Scripts/Attributes/MaxValueAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d124b43cf17e68145aaa37c7cc9c74ce +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RicUtils/Runtime/Scripts/Attributes/MinValueAttribute.cs b/Assets/RicUtils/Runtime/Scripts/Attributes/MinValueAttribute.cs new file mode 100644 index 0000000..1076761 --- /dev/null +++ b/Assets/RicUtils/Runtime/Scripts/Attributes/MinValueAttribute.cs @@ -0,0 +1,31 @@ +using UnityEngine; + +namespace RicUtils.Attributes +{ + public class MinValueAttribute : PropertyAttribute + { + public readonly float X, Y, Z, W; + + public MinValueAttribute(float value) : this(value, value, value, value) + { + + } + + public MinValueAttribute(float x, float y) : this(x, y, 0) + { + + } + + public MinValueAttribute(float x, float y, float z) : this(x, y, z, 0) + { + } + + public MinValueAttribute(float x, float y, float z, float w) + { + this.X = x; + this.Y = y; + this.Z = z; + this.W = w; + } + } +} diff --git a/Assets/RicUtils/Runtime/Scripts/Attributes/MinValueAttribute.cs.meta b/Assets/RicUtils/Runtime/Scripts/Attributes/MinValueAttribute.cs.meta new file mode 100644 index 0000000..14a2908 --- /dev/null +++ b/Assets/RicUtils/Runtime/Scripts/Attributes/MinValueAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 59bd0da683742fb4ebbef80ae1c35d7c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RicUtils/Runtime/Scripts/Attributes/MustBeAssignedAttribute.cs b/Assets/RicUtils/Runtime/Scripts/Attributes/MustBeAssignedAttribute.cs new file mode 100644 index 0000000..52905c7 --- /dev/null +++ b/Assets/RicUtils/Runtime/Scripts/Attributes/MustBeAssignedAttribute.cs @@ -0,0 +1,9 @@ +using UnityEngine; + +namespace RicUtils.Attributes +{ + public class MustBeAssignedAttribute : PropertyAttribute + { + + } +} diff --git a/Assets/RicUtils/Runtime/Scripts/Attributes/MustBeAssignedAttribute.cs.meta b/Assets/RicUtils/Runtime/Scripts/Attributes/MustBeAssignedAttribute.cs.meta new file mode 100644 index 0000000..f943e19 --- /dev/null +++ b/Assets/RicUtils/Runtime/Scripts/Attributes/MustBeAssignedAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8b3308b970f6d514aa537eed7bb947ad +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RicUtils/Runtime/Scripts/Attributes/NegativeValueOnlyAttribute.cs b/Assets/RicUtils/Runtime/Scripts/Attributes/NegativeValueOnlyAttribute.cs new file mode 100644 index 0000000..59d2292 --- /dev/null +++ b/Assets/RicUtils/Runtime/Scripts/Attributes/NegativeValueOnlyAttribute.cs @@ -0,0 +1,8 @@ +using UnityEngine; + +namespace RicUtils.Attributes +{ + public class NegativeValueOnlyAttribute : PropertyAttribute + { + } +} diff --git a/Assets/RicUtils/Runtime/Scripts/Attributes/NegativeValueOnlyAttribute.cs.meta b/Assets/RicUtils/Runtime/Scripts/Attributes/NegativeValueOnlyAttribute.cs.meta new file mode 100644 index 0000000..7248d49 --- /dev/null +++ b/Assets/RicUtils/Runtime/Scripts/Attributes/NegativeValueOnlyAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e7076fbfe6363cb40907a18e658ebbe8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RicUtils/Runtime/Scripts/Attributes/PositiveValueOnlyAttribute.cs b/Assets/RicUtils/Runtime/Scripts/Attributes/PositiveValueOnlyAttribute.cs new file mode 100644 index 0000000..a156b83 --- /dev/null +++ b/Assets/RicUtils/Runtime/Scripts/Attributes/PositiveValueOnlyAttribute.cs @@ -0,0 +1,8 @@ +using UnityEngine; + +namespace RicUtils.Attributes +{ + public class PositiveValueOnlyAttribute : PropertyAttribute + { + } +} diff --git a/Assets/RicUtils/Runtime/Scripts/Attributes/PositiveValueOnlyAttribute.cs.meta b/Assets/RicUtils/Runtime/Scripts/Attributes/PositiveValueOnlyAttribute.cs.meta new file mode 100644 index 0000000..97d2292 --- /dev/null +++ b/Assets/RicUtils/Runtime/Scripts/Attributes/PositiveValueOnlyAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8901cdc97bd27af4aa68d20dd9178cab +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RicUtils/Runtime/Scripts/Attributes/ReadOnlyAttribute.cs b/Assets/RicUtils/Runtime/Scripts/Attributes/ReadOnlyAttribute.cs new file mode 100644 index 0000000..9f1dc7b --- /dev/null +++ b/Assets/RicUtils/Runtime/Scripts/Attributes/ReadOnlyAttribute.cs @@ -0,0 +1,26 @@ +using UnityEngine; + +namespace RicUtils.Attributes +{ + public class ReadOnlyAttribute : PropertyAttribute + { + public readonly AvailableMode PlayMode; + + public ReadOnlyAttribute(AvailableMode playMode) + { + this.PlayMode = playMode; + } + + public ReadOnlyAttribute() : this(AvailableMode.All) + { + + } + } + + public enum AvailableMode + { + All, + Editor, + Play, + } +} diff --git a/Assets/RicUtils/Runtime/Scripts/Attributes/ReadOnlyAttribute.cs.meta b/Assets/RicUtils/Runtime/Scripts/Attributes/ReadOnlyAttribute.cs.meta new file mode 100644 index 0000000..eed246f --- /dev/null +++ b/Assets/RicUtils/Runtime/Scripts/Attributes/ReadOnlyAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2459a8bf21f427b42a164a730967fef0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RicUtils/Runtime/Scripts/Billboard.cs b/Assets/RicUtils/Runtime/Scripts/Billboard.cs new file mode 100644 index 0000000..b1f9af3 --- /dev/null +++ b/Assets/RicUtils/Runtime/Scripts/Billboard.cs @@ -0,0 +1,31 @@ +using UnityEngine; + +namespace RicUtils +{ + public class Billboard : MonoBehaviour + { + public Transform lookAtTarget; + public bool inverseLookAt; + + private static Camera activeCamera; + + private void Update() + { + if (activeCamera == null) activeCamera = FindObjectOfType(); + + Transform target = lookAtTarget; + if (target == null && activeCamera != null) target = activeCamera.transform; + + if (target == null) return; + + var position = target.position; + + if (inverseLookAt) + { + position = transform.position * 2 - target.position; + } + + transform.LookAt(position); + } + } +} diff --git a/Assets/RicUtils/Runtime/Scripts/Billboard.cs.meta b/Assets/RicUtils/Runtime/Scripts/Billboard.cs.meta new file mode 100644 index 0000000..0dbef09 --- /dev/null +++ b/Assets/RicUtils/Runtime/Scripts/Billboard.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 59e34fd5caa59ff448d8c8b8e4fecefe +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RicUtils/Runtime/Scripts/Managers/DataGenericManager.cs b/Assets/RicUtils/Runtime/Scripts/Managers/DataGenericManager.cs index 33dd90d..d41ad06 100644 --- a/Assets/RicUtils/Runtime/Scripts/Managers/DataGenericManager.cs +++ b/Assets/RicUtils/Runtime/Scripts/Managers/DataGenericManager.cs @@ -1,7 +1,4 @@ using RicUtils.ScriptableObjects; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; namespace RicUtils.Managers { diff --git a/Assets/RicUtils/Runtime/Scripts/Managers/GenericManager.cs b/Assets/RicUtils/Runtime/Scripts/Managers/GenericManager.cs index e5ff0aa..ee2ab55 100644 --- a/Assets/RicUtils/Runtime/Scripts/Managers/GenericManager.cs +++ b/Assets/RicUtils/Runtime/Scripts/Managers/GenericManager.cs @@ -1,5 +1,3 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; namespace RicUtils.Managers diff --git a/Assets/RicUtils/Runtime/Scripts/Managers/SingletonCreation.cs b/Assets/RicUtils/Runtime/Scripts/Managers/SingletonCreation.cs index 0140940..4cbc094 100644 --- a/Assets/RicUtils/Runtime/Scripts/Managers/SingletonCreation.cs +++ b/Assets/RicUtils/Runtime/Scripts/Managers/SingletonCreation.cs @@ -1,7 +1,5 @@ using RicUtils.Settings; using RicUtils.Utilities; -using System.Collections; -using System.Collections.Generic; using System.Reflection; using UnityEngine; diff --git a/Assets/RicUtils/Runtime/Scripts/Managers/SingletonGenericManager.cs b/Assets/RicUtils/Runtime/Scripts/Managers/SingletonGenericManager.cs index d912996..54c6ffa 100644 --- a/Assets/RicUtils/Runtime/Scripts/Managers/SingletonGenericManager.cs +++ b/Assets/RicUtils/Runtime/Scripts/Managers/SingletonGenericManager.cs @@ -1,5 +1,3 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; namespace RicUtils.Managers diff --git a/Assets/RicUtils/Runtime/Scripts/PathConstants.cs b/Assets/RicUtils/Runtime/Scripts/PathConstants.cs index 1aaef20..5ca8163 100644 --- a/Assets/RicUtils/Runtime/Scripts/PathConstants.cs +++ b/Assets/RicUtils/Runtime/Scripts/PathConstants.cs @@ -1,7 +1,4 @@ -using System.Collections; -using System.Collections.Generic; using System.Runtime.CompilerServices; -using UnityEngine; [assembly: InternalsVisibleTo("RicUtils.Editor")] namespace RicUtils diff --git a/Assets/RicUtils/Runtime/Scripts/ScriptableObjects/AvailableScriptableObject.cs b/Assets/RicUtils/Runtime/Scripts/ScriptableObjects/AvailableScriptableObject.cs index 533b3de..9fdd3e9 100644 --- a/Assets/RicUtils/Runtime/Scripts/ScriptableObjects/AvailableScriptableObject.cs +++ b/Assets/RicUtils/Runtime/Scripts/ScriptableObjects/AvailableScriptableObject.cs @@ -1,4 +1,3 @@ -using System.Collections; using System.Collections.Generic; using UnityEngine; diff --git a/Assets/RicUtils/Runtime/Scripts/ScriptableObjects/DataManagerScriptableObject.cs b/Assets/RicUtils/Runtime/Scripts/ScriptableObjects/DataManagerScriptableObject.cs index d3faffc..f1f002d 100644 --- a/Assets/RicUtils/Runtime/Scripts/ScriptableObjects/DataManagerScriptableObject.cs +++ b/Assets/RicUtils/Runtime/Scripts/ScriptableObjects/DataManagerScriptableObject.cs @@ -1,5 +1,3 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; namespace RicUtils.ScriptableObjects diff --git a/Assets/RicUtils/Runtime/Scripts/ScriptableObjects/GenericScriptableObject.cs b/Assets/RicUtils/Runtime/Scripts/ScriptableObjects/GenericScriptableObject.cs index 46ff601..8461491 100644 --- a/Assets/RicUtils/Runtime/Scripts/ScriptableObjects/GenericScriptableObject.cs +++ b/Assets/RicUtils/Runtime/Scripts/ScriptableObjects/GenericScriptableObject.cs @@ -1,5 +1,3 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; namespace RicUtils.ScriptableObjects diff --git a/Assets/RicUtils/Runtime/Scripts/Settings/RicUtils_RuntimeSettings.cs b/Assets/RicUtils/Runtime/Scripts/Settings/RicUtils_RuntimeSettings.cs index 4a9b07d..cec4fcd 100644 --- a/Assets/RicUtils/Runtime/Scripts/Settings/RicUtils_RuntimeSettings.cs +++ b/Assets/RicUtils/Runtime/Scripts/Settings/RicUtils_RuntimeSettings.cs @@ -1,6 +1,4 @@ using RicUtils.Utilities; -using System.Collections; -using System.Collections.Generic; using UnityEditor; using UnityEngine; diff --git a/Assets/RicUtils/Runtime/Scripts/Settings/SingletonManager.cs b/Assets/RicUtils/Runtime/Scripts/Settings/SingletonManager.cs index 497d947..efd2f98 100644 --- a/Assets/RicUtils/Runtime/Scripts/Settings/SingletonManager.cs +++ b/Assets/RicUtils/Runtime/Scripts/Settings/SingletonManager.cs @@ -1,10 +1,6 @@ using RicUtils.Managers; using RicUtils.ScriptableObjects; -using System.Collections; -using System.Collections.Generic; -using System.Security.Cryptography.X509Certificates; using TypeReferences; -using UnityEngine; namespace RicUtils.Settings { diff --git a/Assets/RicUtils/Runtime/Scripts/Utilities/ReflectionUtilities.cs b/Assets/RicUtils/Runtime/Scripts/Utilities/ReflectionUtilities.cs index 9906013..f503608 100644 --- a/Assets/RicUtils/Runtime/Scripts/Utilities/ReflectionUtilities.cs +++ b/Assets/RicUtils/Runtime/Scripts/Utilities/ReflectionUtilities.cs @@ -1,9 +1,7 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; -using UnityEngine; namespace RicUtils.Utilities { diff --git a/Assets/RicUtils/Runtime/Scripts/Utilities/RicUtilities.cs b/Assets/RicUtils/Runtime/Scripts/Utilities/RicUtilities.cs index 3ead5ee..ac7c94a 100644 --- a/Assets/RicUtils/Runtime/Scripts/Utilities/RicUtilities.cs +++ b/Assets/RicUtils/Runtime/Scripts/Utilities/RicUtilities.cs @@ -1,6 +1,4 @@ using RicUtils.ScriptableObjects; -using System.Collections; -using System.Collections.Generic; using System.IO; using System.Text.RegularExpressions; using UnityEditor; diff --git a/Assets/RicUtils/Runtime/Scripts/Utilities/SerializedPropertyUtilities.cs b/Assets/RicUtils/Runtime/Scripts/Utilities/SerializedPropertyUtilities.cs new file mode 100644 index 0000000..3f15e66 --- /dev/null +++ b/Assets/RicUtils/Runtime/Scripts/Utilities/SerializedPropertyUtilities.cs @@ -0,0 +1,282 @@ +#if UNITY_EDITOR +using UnityEditor; +using UnityEngine; + +namespace RicUtils.Utilities +{ + public static class SerializedPropertyUtilities + { + public static bool IsNumerical(this SerializedProperty property) + { + switch (property.propertyType) + { + case SerializedPropertyType.Float: + case SerializedPropertyType.Integer: + return true; + } + + return false; + } + + public static bool IsVectorFloat(this SerializedProperty property) + { + switch (property.propertyType) + { + case SerializedPropertyType.Vector2: + case SerializedPropertyType.Vector3: + case SerializedPropertyType.Vector4: + return true; + } + + return false; + } + + public static bool IsVectorInt(this SerializedProperty property) + { + switch (property.propertyType) + { + case SerializedPropertyType.Vector2Int: + case SerializedPropertyType.Vector3Int: + return true; + } + + return false; + } + + public static bool IsVector(this SerializedProperty property) + { + return property.IsVectorFloat() || property.IsVectorInt(); + } + + public static bool HandleMinValues(this SerializedProperty property, float minValue) + { + switch (property.propertyType) + { + case SerializedPropertyType.Float: + case SerializedPropertyType.Integer: + return property.HandleMinNumericalValues(minValue); + + case SerializedPropertyType.Vector2: + case SerializedPropertyType.Vector3: + case SerializedPropertyType.Vector4: + return property.HandleMinVectorValues(new Vector4(minValue, minValue, minValue, minValue)); + + case SerializedPropertyType.Vector2Int: + case SerializedPropertyType.Vector3Int: + return property.HandleMinVectorIntValues(new Vector3Int((int)minValue, (int)minValue, (int)minValue)); + } + + return false; + } + + public static bool HandleMinNumericalValues(this SerializedProperty property, float minValue) + { + if (property.propertyType == SerializedPropertyType.Float && property.floatValue < minValue) + { + property.floatValue = minValue; + return true; + } + + if (property.propertyType == SerializedPropertyType.Integer && property.intValue < minValue) + { + property.intValue = (int)minValue; + } + + return false; + } + + public static bool HandleMinVectorValues(this SerializedProperty property, Vector4 minValue) + { + Vector4 vector = Vector4.zero; + switch (property.propertyType) + { + case SerializedPropertyType.Vector2: + vector = property.vector2Value; + break; + case SerializedPropertyType.Vector3: + vector = property.vector3Value; + break; + case SerializedPropertyType.Vector4: + vector = property.vector4Value; + break; + } + + bool handled = false; + for (int i = 0; i < 4; ++i) + { + if (vector[i] < minValue[i]) + { + vector[i] = minValue[i]; + handled = true; + } + } + + switch (property.propertyType) + { + case SerializedPropertyType.Vector2: + property.vector2Value = vector; + break; + case SerializedPropertyType.Vector3: + property.vector3Value = vector; + break; + case SerializedPropertyType.Vector4: + property.vector4Value = vector; + break; + } + + return handled; + } + + public static bool HandleMinVectorIntValues(this SerializedProperty property, Vector3Int minValue) + { + Vector3Int vector = Vector3Int.zero; + switch (property.propertyType) + { + case SerializedPropertyType.Vector2Int: + vector = (Vector3Int)property.vector2IntValue; + break; + case SerializedPropertyType.Vector3Int: + vector = property.vector3IntValue; + break; + } + + bool handled = false; + for (int i = 0; i < 3; ++i) + { + if (vector[i] < minValue[i]) + { + vector[i] = minValue[i]; + handled = true; + } + } + + switch (property.propertyType) + { + case SerializedPropertyType.Vector2Int: + property.vector2IntValue = (Vector2Int)vector; + break; + case SerializedPropertyType.Vector3Int: + property.vector3IntValue = vector; + break; + } + + return handled; + } + + public static bool HandleMaxValues(this SerializedProperty property, float maxValue) + { + switch (property.propertyType) + { + case SerializedPropertyType.Float: + case SerializedPropertyType.Integer: + return property.HandleMaxNumericalValues(maxValue); + + case SerializedPropertyType.Vector2: + case SerializedPropertyType.Vector3: + case SerializedPropertyType.Vector4: + return property.HandleMaxVectorValues(new Vector4(maxValue, maxValue, maxValue, maxValue)); + + case SerializedPropertyType.Vector2Int: + case SerializedPropertyType.Vector3Int: + return property.HandleMaxVectorIntValues(new Vector3Int((int)maxValue, (int)maxValue, (int)maxValue)); + } + + return false; + } + + public static bool HandleMaxNumericalValues(this SerializedProperty property, float maxValue) + { + if (property.propertyType == SerializedPropertyType.Float && property.floatValue > maxValue) + { + property.floatValue = maxValue; + return true; + } + + if (property.propertyType == SerializedPropertyType.Integer && property.intValue > maxValue) + { + property.intValue = (int)maxValue; + } + + return false; + } + + public static bool HandleMaxVectorValues(this SerializedProperty property, Vector4 maxValue) + { + Vector4 vector = Vector4.zero; + switch (property.propertyType) + { + case SerializedPropertyType.Vector2: + vector = property.vector2Value; + break; + case SerializedPropertyType.Vector3: + vector = property.vector3Value; + break; + case SerializedPropertyType.Vector4: + vector = property.vector4Value; + break; + } + + bool handled = false; + for (int i = 0; i < 4; ++i) + { + if (vector[i] > maxValue[i]) + { + vector[i] = maxValue[i]; + handled = true; + } + } + + switch (property.propertyType) + { + case SerializedPropertyType.Vector2: + property.vector2Value = vector; + break; + case SerializedPropertyType.Vector3: + property.vector3Value = vector; + break; + case SerializedPropertyType.Vector4: + property.vector4Value = vector; + break; + } + + return handled; + } + + public static bool HandleMaxVectorIntValues(this SerializedProperty property, Vector3Int maxValue) + { + Vector3Int vector = Vector3Int.zero; + switch (property.propertyType) + { + case SerializedPropertyType.Vector2Int: + vector = (Vector3Int)property.vector2IntValue; + break; + case SerializedPropertyType.Vector3Int: + vector = property.vector3IntValue; + break; + } + + bool handled = false; + for (int i = 0; i < 3; ++i) + { + if (vector[i] > maxValue[i]) + { + vector[i] = maxValue[i]; + handled = true; + } + } + + switch (property.propertyType) + { + case SerializedPropertyType.Vector2Int: + property.vector2IntValue = (Vector2Int)vector; + break; + case SerializedPropertyType.Vector3Int: + property.vector3IntValue = vector; + break; + } + + return handled; + } + } +} +#endif \ No newline at end of file diff --git a/Assets/RicUtils/Runtime/Scripts/Utilities/SerializedPropertyUtilities.cs.meta b/Assets/RicUtils/Runtime/Scripts/Utilities/SerializedPropertyUtilities.cs.meta new file mode 100644 index 0000000..d9b2484 --- /dev/null +++ b/Assets/RicUtils/Runtime/Scripts/Utilities/SerializedPropertyUtilities.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1c3b9907fd7505042a11d1de3dcc2318 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: