Able
Askowl Base Library Enabler
Textual.cs
1 // Copyright 2018 (C) paul@marrington.net http://www.askowl.net/unity-packages
2 
3 namespace Decoupled {
4  using UnityEngine.UI;
5 
6  /// <a href="http://bit.ly/2PLnhaQ">Change text component properties - Unity or TextMeshPro</a>
7  public interface TextualInterface {
8  // ReSharper disable once InconsistentNaming
9  /// <a href="http://bit.ly/2PLnhaQ">Get or set the text to display</a>
10  string text { get; set; }
11  }
12 
13  /// <a href="http://bit.ly/2PLnhaQ">Decoupled text component concrete implementation</a> <inheritdoc cref="ComponentDecoupler{T}" />
14  public partial class Textual : ComponentDecoupler<Textual>, TextualInterface {
15  private TextualInterface Backer => Instance as TextualInterface;
16 
17  /// <inheritdoc />
18  public string text { get => Backer.text; set => Backer.text = value; }
19  }
20 
21  public partial class Textual {
22  private class UnityTextInterface : ComponentInterface, TextualInterface {
23  private Text UnityText => Component as Text;
24 
25  public string text { get => UnityText.text; set => UnityText.text = value; }
26 
27  public UnityTextInterface() => Instantiate<Text>(primary: false);
28  }
29 
30  // ReSharper disable once UnusedMember.Local
31  private UnityTextInterface unityTextInterface = new UnityTextInterface();
32  }
33 }
Decoupled text component concrete implementation
Definition: Textual.cs:14
Creating Decoupled Components
string text
Get or set the text to display
Definition: Textual.cs:10
Change text component properties - Unity or TextMeshPro
Definition: Textual.cs:7
ComponentInterface Instance
Called in concrete component instances to get the correct backing component