Able
Askowl Base Library Enabler
LabelAttribute.cs
1 namespace Askowl {
2  using System;
3  using UnityEngine;
4 
5  /// <a href="http://bit.ly/2Rk1o06">Change label for generic components</a><inheritdoc />
6  public class LabelAttribute : PropertyAttribute { }
7 
8  /// <a href="http://bit.ly/2Rk1o06">Save label name to change attribute field descriptors</a>
9  public class LabelsAttribute : Attribute {
10  private readonly Map labels = new Map();
11  private readonly string label;
12 
13  /// <a href="http://bit.ly/2Rk1o06">[Labels("name")]</a>
14  public LabelsAttribute(string label) => this.label = label;
15 
16  /// <a href="http://bit.ly/2Rk1o06">Many labels</a>
17  public LabelsAttribute(params string[] labels) {
18  for (var i = 0; i < labels.Length; i+=2) this.labels.Add(labels[i], labels[i+1]);
19  }
20 
21  /// <a href="http://bit.ly/2Rk1o06">Make the switch in the Inspector</a>
22  public void Change(GUIContent guiLabel) => guiLabel.text = labels[guiLabel.text].Found
23  ? labels.Value?.ToString() ?? label ?? guiLabel.text
24  : label ?? guiLabel.text;
25  }
26 }
Definition: Clock.cs:3
LabelsAttribute(string label)
[Labels("name")]
A dictionary wrapper
Definition: Map.cs:10
Change label for generic components
LabelsAttribute(params string[] labels)
Many labels
Save label name to change attribute field descriptors
void Change(GUIContent guiLabel)
Make the switch in the Inspector