Tanoda
MaxValue.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;
10using System.Collections.Generic;
11#if UNITY_EDITOR
12using UnityEditor;
13#endif
14
15namespace Leap.Unity.Attributes {
16
18 public float maxValue;
19
20 public MaxValue(float maxValue) {
21 this.maxValue = maxValue;
22 }
23
24#if UNITY_EDITOR
25 public void ConstrainValue(SerializedProperty property) {
26 if (property.propertyType == SerializedPropertyType.Float) {
27 property.floatValue = Mathf.Min(maxValue, property.floatValue);
28 } else if (property.propertyType == SerializedPropertyType.Integer) {
29 property.intValue = Mathf.Min((int)maxValue, property.intValue);
30 } else if (property.propertyType == SerializedPropertyType.Vector2) {
31 property.vector2Value = Vector2.Min(new Vector2(maxValue, maxValue), property.vector2Value);
32 } else if (property.propertyType == SerializedPropertyType.Vector3) {
33 property.vector3Value = Vector3.Min(new Vector3(maxValue, maxValue, maxValue), property.vector3Value);
34 } else if (property.propertyType == SerializedPropertyType.Vector4) {
35 property.vector4Value = Vector4.Min(new Vector4(maxValue, maxValue, maxValue, maxValue), 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}
MaxValue(float maxValue)
Definition: MaxValue.cs:20