VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
AVRUI_InputField_PlusMinus.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEngine.UI;
5 
6 namespace AVR.UI.Utils {
7  /// <summary>
8  /// Inputfield that the value of which can be increased/decreased by function call. The value of the inputfield ought to be numerical.
9  /// </summary>
10  [AVR.Core.Attributes.DocumentationUrl("class_a_v_r_1_1_u_i_1_1_utils_1_1_a_v_r_u_i___input_field___plus_minus.html")]
11  public class AVRUI_InputField_PlusMinus : AVR.Core.AVR_Behaviour
12  {
13  public float increase_amount = 0.1f;
14  public float decrease_amount = 0.1f;
15  public bool allowNegative = true;
16 
17  private InputField input;
18  private TMPro.TMP_InputField input_tmp;
19 
20  void Awake() {
21  input = GetComponent<InputField>();
22  input_tmp = GetComponent<TMPro.TMP_InputField>();
23  if(!input && !input_tmp) {
24  AVR.Core.AVR_DevConsole.cerror("Numeric Inputfield need either a InputField or a TMP_InputField component!", this);
25  Destroy(this);
26  }
27  }
28 
29  public void increase_value() {
30  try {
31  if(input) {
32  input.text = allowNegative ?
33  (float.Parse(input.text) + increase_amount).ToString()
34  :
35  (Mathf.Max(0, float.Parse(input.text) + increase_amount)).ToString();
36  }
37  else {
38  input_tmp.text = allowNegative ?
39  (float.Parse(input_tmp.text) + increase_amount).ToString()
40  :
41  (Mathf.Max(0, float.Parse(input_tmp.text) + increase_amount)).ToString();
42  }
43  } catch(System.Exception ) { }
44  }
45 
46  public void decrease_value() {
47  try {
48  if (input)
49  {
50  input.text = allowNegative ?
51  (float.Parse(input.text) - decrease_amount).ToString()
52  :
53  (Mathf.Max(0, float.Parse(input.text) - decrease_amount)).ToString();
54  }
55  else
56  {
57  input_tmp.text = allowNegative ?
58  (float.Parse(input_tmp.text) - decrease_amount).ToString()
59  :
60  (Mathf.Max(0, float.Parse(input_tmp.text) - decrease_amount)).ToString();
61  }
62  } catch(System.Exception) { }
63  }
64  }
65 }
Inputfield that the value of which can be increased/decreased by function call. The value of the inpu...
Sets the documentation html file inside of Packages/com.avr.core/Documentation/html of a given class...