From d4552adc9ec0998725e663c47114e6836061ad2c Mon Sep 17 00:00:00 2001
From: miepzerino <o.skotnik@gmail.com>
Date: Wed, 02 Apr 2025 14:52:46 +0000
Subject: [PATCH] #35 reworked ore generation

---
 Assets/Scripts/Attributes/MinMaxAttribute.cs |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/Assets/Scripts/Attributes/MinMaxAttribute.cs b/Assets/Scripts/Attributes/MinMaxAttribute.cs
new file mode 100644
index 0000000..8a42417
--- /dev/null
+++ b/Assets/Scripts/Attributes/MinMaxAttribute.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Reflection;
+using Unity.VisualScripting;
+using UnityEditor;
+using UnityEngine;
+
+namespace Assets.Scripts.Attributes
+{
+    // Custom attribute for the min-max slider
+    public class MinMaxAttribute : PropertyAttribute
+    {
+        public float Min { get; private set; }
+        public float Max { get; private set; }
+
+        public MinMaxAttribute(float min, float max)
+        {
+            Min = min;
+            Max = max;
+        }
+    }
+#if UNITY_EDITOR
+    [CustomPropertyDrawer(typeof(MinMaxAttribute))]
+    public class MinMaxDrawer : PropertyDrawer
+    {
+        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
+        {
+            if (property.propertyType != SerializedPropertyType.Vector2)
+            {
+                EditorGUI.LabelField(position, label.text, "Use MinMax with Vector2");
+                return;
+            }
+
+            var minMaxAttribute = (MinMaxAttribute)attribute;
+            var vector = property.vector2Value;
+
+            EditorGUI.BeginProperty(position, label, property);
+
+            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
+
+            float[] values = new float[] { vector.x, vector.y };
+            EditorGUI.MultiFloatField(position,
+                new GUIContent[] { new GUIContent("Min"), new GUIContent("Max") },
+                values);
+
+            values[0] = Mathf.Clamp(values[0], minMaxAttribute.Min, values[1]);
+            values[1] = Mathf.Clamp(values[1], values[0], minMaxAttribute.Max);
+
+            property.vector2Value = new Vector2(values[0], values[1]);
+
+            EditorGUI.EndProperty();
+        }
+    }
+#endif
+}
\ No newline at end of file

--
Gitblit v1.9.3