VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
AVR_Attributes.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using System;
5 using System.Linq;
6 
7 /// <summary>
8 /// Contains C#-Attributes for various uses.
9 /// </summary>
10 namespace AVR.Core.Attributes {
11 
12  /// <summary>
13  /// This attribute can be used to easily make a function into a command runnable through the AVR_DevConsole.
14  /// This can only be used on *static* void-functions where the parameters are eithe none, a single string or an array of strings.
15  /// Usage examples:
16  ///
17  /// This will add "run_command" as a command that outputs a hello world message. The second parameter in the constructor provides a description, which the user can see by using the "help" command. Providing a description is not mandatory but recommended.
18  /// \code
19  /// [AVR.Core.Attributes.ConsoleCommand("run_command", "Prints a hello world")]
20  /// static void run_command() {
21  /// print("Hello World");
22  /// }
23  /// \endcode
24  ///
25  /// This examples creates a simple "echo" command, which outputs the first argument given to the command. The second parameter (1), defines the minimum amount of arguments a command requires. Providing less will output a warning message to the user.
26  /// \code
27  /// [AVR.Core.Attributes.ConsoleCommand("echo_command", 1, "Replies with the same string")]
28  /// static void echo_command(string arg) {
29  /// print(arg);
30  /// }
31  /// \endcode
32  ///
33  /// This example echoes the second parameter passed. (So the command "echo_second_word hello world" will output "world").
34  /// \code
35  /// [AVR.Core.Attributes.ConsoleCommand("echo_second_word", 2)]
36  /// static void echo_second_word(string[] args) {
37  /// print(args[1]);
38  /// }
39  /// \endcode
40  /// </summary>
41  [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = true)]
42  public class ConsoleCommand : Attribute {
43  private string command_string;
44  private string desc;
45  private int min_args;
46 
47  /// <summary>
48  /// Defines a method as a command vor the AVR_DevConsole.
49  /// <param name="command_string"> String which represents the command. This is the same string a user inputs to run it. </param>
50  /// <param name="min_args"> Minimum amount of arguments a user must provide for the command to run. </param>
51  /// <param name="desc"> Brief description that explains what the command does and how it is used. </param>
52  /// </summary>
53  public ConsoleCommand(string command_string, int min_args = 0, string description = "No description given.") {
54  this.command_string = command_string;
55  this.min_args = min_args;
56  this.desc = description;
57  }
58 
59  /// <summary>
60  /// Defines a method as a command vor the AVR_DevConsole.
61  /// <param name="command_string"> String which represents the command. This is the same string a user inputs to run it. </param>
62  /// <param name="desc"> Brief description that explains what the command does and how it is used. </param>
63  /// </summary>
64  public ConsoleCommand(string command_string, string description)
65  {
66  this.command_string = command_string;
67  this.min_args = 0;
68  this.desc = description;
69  }
70 
71  public string getCommandString() => command_string;
72 
73  public int getMinArgs() => min_args;
74 
75  public string getDescription() => desc;
76  }
77 
78 
79  /// <summary>
80  /// Sets the documentation html file inside of Packages/com.avr.core/Documentation/html of a given class. When the user clicks on the documentation button in the inspector the respective page will be opened.
81  /// Example:
82  /// \code
83  /// [AVR.Core.Attributes.DocumentationUrl("class_a_v_r_1_1_core_1_1_a_v_r___controller.html")]
84  /// public class AVR_Controller : AVR_GenericXRDevice
85  /// { ... }
86  /// \endcode
87  /// </summary>
88  [AttributeUsage(AttributeTargets.Class, Inherited = true)]
89  public class DocumentationUrl : Attribute {
90  string url;
91 
92  /// <summary>
93  /// Defines the html file used for documentation for an AVR_Component.
94  /// <param name="url"> File relative to Packages/com.avr.core/Documentation/html that is the documentation for this class. </param>
95  /// </summary>
96  public DocumentationUrl(string url) {
97  this.url = url;
98  }
99 
100  public string getDocumentationUrl() {
101  return url;
102  }
103  }
104 
105 
106  /// <summary>
107  /// Allows for simple hiding of properties in the UnityEditor depending on certain conditions.
108  /// For instance, in the following example the "type" field will only be displayed in the inspector if the "tracking" field is set to true:
109  /// \code
110  /// public bool tracking = false;
111  ///
112  /// [AVR.Core.Attributes.ConditionalHideInInspector("tracking", true)]
113  /// public TrackingType type;
114  /// \endcode
115  /// \code
116  /// // Hides the variable if "counter" is larger than 3
117  /// [AVR.Core.Attributes.ConditionalHideInInspector("counter", 3, AVR.Core.Attributes.ConditionalHideInInspector.compareType.BIGGER)]
118  ///
119  /// // Hides the variable if "type" is equal to TypeEnum.TYPE2. Since "EQUAL" is the default comparison mode, the parameter is optional.
120  /// [AVR.Core.Attributes.ConditionalHideInInspector("type", (int)TypeEnum.TYPE2)]
121  /// \endcode
122  /// <param name="hideConditionPropertyName"> The first parameter is always the name of the field that represents the condition. The name is case-sensitive. </param>
123  /// <param name="invertCondition"> Will invert the given condition. Hence why in the example above, tracking = false hides the type field. </param>
124  /// <param name="compareValue"> Optionally, one can compare the given field with some given value. The type of comparison is determined by: </param>
125  /// <param name="ctype"> Type of comparison performed if a compareValue is provided. Examples: </param>
126  /// </summary>
127  [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)]
128  public class ConditionalHideInInspector: PropertyAttribute
129  {
130  public enum compareType { EQUAL, BIGGER, SMALLER, BIGGEREQUAL, SMALLEREQUAL, UNEQUAL };
131 
132  public compareType ctype { get; private set; }
133  public string hideConditionPropertyName { get; private set; }
134  public bool invertCondition { get; private set; }
135  public float compareValue { get; private set; }
136 
137  /// <summary>
138  /// Hides a field in the Inspector if a given condition is true.
139  /// <param name="hideConditionPropertyName"> The first parameter is always the name of the field that represents the condition. The name is case-sensitive. </param>
140  /// <param name="invertCondition"> Will invert the given condition. Hence why in the example above, tracking = false hides the type field. </param>
141  /// </summary>
142  public ConditionalHideInInspector(string hideConditionPropertyName, bool invertCondition = false)
143  {
144  this.hideConditionPropertyName = hideConditionPropertyName;
145  this.invertCondition = invertCondition;
146  this.ctype = compareType.BIGGEREQUAL;
147  compareValue = 1.0f;
148  }
149 
150  /// <summary>
151  /// Hides a field in the Inspector if a given condition is true.
152  /// <param name="hideConditionPropertyName"> The first parameter is always the name of the field that represents the condition. The name is case-sensitive. </param>
153  /// <param name="invertCondition"> Will invert the given condition. Hence why in the example above, tracking = false hides the type field. </param>
154  /// <param name="compareValue"> Optionally, one can compare the given field with some given value. The type of comparison is determined by: </param>
155  /// <param name="ctype"> Type of comparison performed if a compareValue is provided. Examples: </param>
156  /// </summary>
157  public ConditionalHideInInspector(string hideConditionPropertyName, float compareValue, compareType ctype = compareType.EQUAL, bool invertCondition = false)
158  {
159  this.hideConditionPropertyName = hideConditionPropertyName;
160  this.invertCondition = invertCondition;
161  this.compareValue = compareValue;
162  this.ctype = ctype;
163  }
164 
165  /// <summary>
166  /// Hides a field in the Inspector if a given condition is true.
167  /// <param name="hideConditionPropertyName"> The first parameter is always the name of the field that represents the condition. The name is case-sensitive. </param>
168  /// <param name="invertCondition"> Will invert the given condition. Hence why in the example above, tracking = false hides the type field. </param>
169  /// <param name="compareValue"> Optionally, one can compare the given field with some given value. The type of comparison is determined by: </param>
170  /// <param name="ctype"> Type of comparison performed if a compareValue is provided. Examples: </param>
171  /// </summary>
172  public ConditionalHideInInspector(string hideConditionPropertyName, int compareValue, compareType ctype = compareType.EQUAL, bool invertCondition = false)
173  {
174  this.hideConditionPropertyName = hideConditionPropertyName;
175  this.invertCondition = invertCondition;
176  this.compareValue = compareValue;
177  this.ctype = ctype;
178  }
179  }
180 
181  /// <summary>
182  /// Makes a field read-only in the inspector
183  /// </summary>
184  public class ReadOnly : PropertyAttribute
185  {
186 
187  }
188 
189  /// <summary>
190  /// Assigns given attributes to a foldout group in the inspector. The way these are drawn is determined by FoldoutPropertyDrawer
191  /// </summary>
192  //NOTE: FoldoutPropertyDrawer is a very dirty way of implementing Foldouts. TODO: Find a better solution.
193  [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)]
194  public class FoldoutGroup : PropertyAttribute
195  {
196  // The group id of this specific object
197  public string group_id;
198 
199  /// <summary>
200  /// Assigns given attributes to a foldout group in the inspector.
201  /// </summary>
202  /// <param name="group_id">string id of the given foldout group.</param>
203  public FoldoutGroup(string group_id)
204  {
205  this.group_id = group_id;
206  }
207  }
208 
209  /// <summary>
210  /// Makes a property of an object only show in the Network-behaviour window. Also works for private/protected attributes.
211  /// </summary>
212  [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)]
213  public class ShowInNetPrompt : PropertyAttribute
214  {
215  /// <summary>
216  /// Makes a property of an object only show in the Network-behaviour window
217  /// </summary>
219  {
220  }
221  }
222 }
DocumentationUrl(string url)
Defines the html file used for documentation for an AVR_Component. File relative to Packages/com...
FoldoutGroup(string group_id)
Assigns given attributes to a foldout group in the inspector.
ConsoleCommand(string command_string, string description)
Defines a method as a command vor the AVR_DevConsole. String which represents the command...
Makes a property of an object only show in the Network-behaviour window. Also works for private/prote...
Sets the documentation html file inside of Packages/com.avr.core/Documentation/html of a given class...
Makes a field read-only in the inspector
Assigns given attributes to a foldout group in the inspector. The way these are drawn is determined b...
ShowInNetPrompt()
Makes a property of an object only show in the Network-behaviour window
This attribute can be used to easily make a function into a command runnable through the AVR_DevConso...
ConditionalHideInInspector(string hideConditionPropertyName, float compareValue, compareType ctype=compareType.EQUAL, bool invertCondition=false)
Hides a field in the Inspector if a given condition is true. The first parameter is always the name o...
ConditionalHideInInspector(string hideConditionPropertyName, bool invertCondition=false)
Hides a field in the Inspector if a given condition is true. The first parameter is always the name o...
Allows for simple hiding of properties in the UnityEditor depending on certain conditions. For instance, in the following example the "type" field will only be displayed in the inspector if the "tracking" field is set to true:
ConsoleCommand(string command_string, int min_args=0, string description="No description given.")
Defines a method as a command vor the AVR_DevConsole. String which represents the command...
ConditionalHideInInspector(string hideConditionPropertyName, int compareValue, compareType ctype=compareType.EQUAL, bool invertCondition=false)
Hides a field in the Inspector if a given condition is true. The first parameter is always the name o...