Tanoda
MinValue.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using UnityEngine;
10#if UNITY_EDITOR
11using UnityEditor;
12#endif
13using System.Collections.Generic;
14
15namespace Leap.Unity.Attributes {
16
18 public float minValue;
19
20 public MinValue(float minValue) {
21 this.minValue = minValue;
22 }
23
24#if UNITY_EDITOR
25 public void ConstrainValue(SerializedProperty property) {
26 if (property.propertyType == SerializedPropertyType.Float) {
27 property.floatValue = Mathf.Max(minValue, property.floatValue);
28 } else if (property.propertyType == SerializedPropertyType.Integer) {
29 property.intValue = Mathf.Max((int)minValue, property.intValue);
30 } else if (property.propertyType == SerializedPropertyType.Vector2) {
31 property.vector2Value = Vector2.Max(new Vector2(minValue, minValue), property.vector2Value);
32 } else if (property.propertyType == SerializedPropertyType.Vector3) {
33 property.vector3Value = Vector3.Max(new Vector3(minValue, minValue, minValue), property.vector3Value);
34 } else if (property.propertyType == SerializedPropertyType.Vector4) {
35 property.vector4Value = Vector4.Max(new Vector4(minValue, minValue, minValue, minValue), property.vector4Value);
36 }
37 }
38
39 public override IEnumerable<SerializedPropertyType> SupportedTypes {
40 get {
41 yield return SerializedPropertyType.Integer;
42 yield return SerializedPropertyType.Float;
43 yield return SerializedPropertyType.Vector2;
44 yield return SerializedPropertyType.Vector3;
45 yield return SerializedPropertyType.Vector4;
46 }
47 }
48#endif
49 }
50}
MinValue(float minValue)
Definition: MinValue.cs:20