-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShowWhenAttribute.cs
42 lines (37 loc) · 1.7 KB
/
ShowWhenAttribute.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using UnityEngine;
// source: https://gist.github.com/deebrol/02f61b7611fd4eca923776077b92dfc2
/// <summary>
/// Attribute used to show or hide the Field depending on certain conditions
/// </summary>
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
public class ShowWhenAttribute : PropertyAttribute {
public readonly string conditionFieldName;
public readonly object comparationValue;
public readonly object[] comparationValueArray;
/// <summary>
/// Attribute used to show or hide the Field depending on certain conditions
/// </summary>
/// <param name="conditionFieldName">Name of the bool condition Field</param>
public ShowWhenAttribute(string conditionFieldName) {
this.conditionFieldName = conditionFieldName;
}
/// <summary>
/// Attribute used to show or hide the Field depending on certain conditions
/// </summary>
/// <param name="conditionFieldName">Name of the Field to compare (bool, enum, int or float)</param>
/// <param name="comparationValue">Value to compare</param>
public ShowWhenAttribute(string conditionFieldName, object comparationValue = null) {
this.conditionFieldName = conditionFieldName;
this.comparationValue = comparationValue;
}
/// <summary>
/// Attribute used to show or hide the Field depending on certain conditions
/// </summary>
/// <param name="conditionFieldName">Name of the Field to compare (bool, enum, int or float)</param>
/// <param name="comparationValueArray">Array of values to compare (only for enums)</param>
public ShowWhenAttribute(string conditionFieldName, object[] comparationValueArray = null) {
this.conditionFieldName = conditionFieldName;
this.comparationValueArray = comparationValueArray;
}
}