SegmentDisplay
Derived from
MonoBehaviour
Main class of SegmentDisplay. This class contains majority of all the methods and settings needed to use SegmentDisplay. There are two other classes derived from this class, SegmentDisplaySprite and SegmentDisplayImage for sprite and image based displays. Sprite based display is used in 2D and 3D worlds, while Image based display is used in UI. Those two classes contains some setting specific for these environments. Normally SegmentDisplay is set up in Unity Editor inspector. All properties and fields of this class need to be changed by code only in case SegmendDisplay is created from prefab during runtime and it wasn't in scene before. But if SegmendDisplay prefab is already added to scene in Unity Editor, you only need to use methods of this class in your code. Note when setting or adding text to display that is using colons. Make sure that text you are setting is matching display digits, so that colon in your text will match the location of colon in display. If display is for example "##:##" (5 digits where third one is colon") and you try to add text "2:15", that may cause display to show for example "2 15". In this case solution is to add text " 2:15" instead (notice space before number 2) or add text "2:15" as right aligned.
Fields
public bool Mod_S14S16_One | Draw number 1 without extra diagonal segment. | public bool Mod_S14S16_Seven | Draw number 7 with diagonal line instead vertical. | public bool Mod_S14S16_Zero | Draw number 0 with slash going through the number. | public bool Mod_S7S14_SixNine | Draw numbers 6 and 9 without having last horizontal segment. | public bool Mod_S7_Seven | Draw number 7 with extra vertical line on top left. | public bool[] ColonAtIndex | Array of boolean values that defines in which indexes there will be colon instead of normal digit. | public bool[] SmallerDigitAtIndex | Array of boolean values that defines in which indexes there will be smaller digits instead of normal size digit. |
Enums
Indexer
Properties
public bool ApostrophesEnabled | Include extra apostrophe segment after each digit. | public float ColonRelativeSpacing | Spacing around colons, relative to digit spacing. | public bool ColonsEnabled | Enable or disable colons. | public bool DecimalPointsEnabled | Include extra decimal point segment after each digit. | public Alignments DefaultAlignment | Default alignment of text if not specified when calling SetText() or AddText() methods. | public int DigitCount | Sets or gets number of digits (numbers and/or characters) in this display. | public float DigitSpacing | Spacing between digits. | public DisplayTypes DisplayType | Type of the display, number of segments in each digit. | public FourteenSegmentStyles FourteenSegmentStyle | Set or get fourteen segment display style. | public string InitialText | Initial text that is added to display when display starts. | public Color OffColor | Color of segment when it is not lit. | public Color OnColor | Color of segment when it is lit. | public float SegmentSpread | Spread out segments or bring them closer inside one digit. | public SevenSegmentStyles SevenSegmentStyle | Set or get seven segment display style. | public SixteenSegmentStyles SixteenSegmentStyle | Set or get sixteen segment display style. | public bool SmallerDigitsEnabled | Enable or disable some digits being smaller than another. | public float SmallerDigitsSizePercent | Set the size of smaller digits compared to normal size digits. | public float SmallerDigitsVerticalPosition | Set the vertical position of smaller digits compared to normal size digits. |
Methods
Fields
public bool Mod_S14S16_One Draw number 1 without extra diagonal segment. Have effect on 14 and 16 segment displays. This can be changed during runtime, but it doesn't affect texts that is already on display.
public bool Mod_S14S16_Seven Draw number 7 with diagonal line instead vertical. Have effect on 14 and 16 segment displays. This can be changed during runtime, but it doesn't affect texts that is already on display.
public bool Mod_S14S16_Zero Draw number 0 with slash going through the number. Have effect on 14 and 16 segment displays. This can be changed during runtime, but it doesn't affect texts that is already on display.
public bool Mod_S7S14_SixNine Draw numbers 6 and 9 without having last horizontal segment. Have effect on 7 and 14 segment displays. This can be changed during runtime, but it doesn't affect texts that is already on display.
public bool Mod_S7_Seven Draw number 7 with extra vertical line on top left. Have effect on 7 segment display. This can be changed during runtime, but it doesn't affect texts that is already on display.
public bool[] ColonAtIndex Array of boolean values that defines in which indexes there will be colon instead of normal digit. This array is automatically created and set to correct length when ColonsEnabled is set to true, or when DigitCount is changed while colons are enabled. Before that, this array may be null or have invalid length. Changing values in this array have no effect after display is created to the scene.
public bool[] SmallerDigitAtIndex Array of boolean values that defines in which indexes there will be smaller digits instead of normal size digit. This array is automatically created and set to correct length when SmallerDigitsEnabled is set to true, or when DigitCount is changed while smaller digits are enabled. Before that, this array may be null or have invalid length. Changing values in this array have no effect after display is created to the scene.
Enums
public enum Alignments Text alignments. Items | Left | Align text to left side of display. First character of text will be in leftmost digit. If text is longer than display, end of the text will be cut out. | | Center | Align text to center of display. If text is longer than display, text may be cut out both in start and end. Note that center aligned text may not work correctly in displays that have colons enabled. | | Right | Align text to right side of display. Last character of text will be in rightmost digit. If text is longer than display, start of the text will be cut out. |
public enum DisplayTypes Different display types, telling how many segments there are in each digit. Items | SevenSegment | Classic seven segment display. This type of display typically shows just numbers. Best choice for simple clocks, timers or scoreboards. This type display support also letters, but some of them may require imagination to read and some are more like symbolic, like M and W. This is sufficient for showing short, one word messages such "Start", "End", "Play", "Stop", "Pause", "Open", "Close". But due limitation of segments, these texts may have upper and lower case letters mixed and "start" looks more like "StArt". | | FourteenSegment | Fourteen segment display is good choice if your display also needs to show text. Only upper case letters are supported but text is very readable. Multiple symbols are also supported. | | SixteenSegment | Very much like fourteen segment display but can also show lower case letters and few extra symbols such curly brackets. |
public enum FourteenSegmentStyles Different styles for fourteen segment display. Items | Basic | Basic style. | | Cheap | Cheap electronics style. Practically just 7 segment display turned to 14 segment as easily as possible. |
public enum SevenSegmentStyles Different styles for seven segment display. Items | Basic | Basic all-around style. | | Classic | Classic style where each of seven segments are completely identical. | | Sharp | Very sharp corners and square decimal points and colons. | | Round | Round style where each segment is different and they make smooth shapes. |
public enum SixteenSegmentStyles Different styles for sixteen segment display. Items | Basic | Basic style. | | MiniLeds | Style where each segment is generated by rows of small, round lights. Very common in modern CD/DVD/BluRay players or stereos. |
Indexer
public SingleDigit this [int digitIndex] Gets reference to certain digit of this display. Useful if you want to control some digit separately. Parameters | digitIndex | Digit index, 0 is leftmost digit. |
Properties
public bool ApostrophesEnabled Include extra apostrophe segment after each digit. Note that this cause that in some case display may hold longer texts than number of digits. If display size is for example 4 digits and apostrophes are enabled, display pattern will be "#'#'#'#'" meaning that even text "1'2'3'4'" (8 characters) will fit to this 4 digit display. But on the other hand, "'''12" (5 characters) will not fit. Value | True to enable apostrophes, false to have digits without apostrophe segment. |
public float ColonRelativeSpacing Spacing around colons, relative to digit spacing. 1.0 means no change to normal digit spacing, colon will take same amount of space as any other digit. 0.0 means no space for colons, digits around colon are as close each other as they would be without any colon between them. Value | Percentage value defining how much space is between colons compared to normal spacing between digits. |
public bool ColonsEnabled Enable or disable colons. Value | True to enable colons, false to keep all digits normal. |
public bool DecimalPointsEnabled Include extra decimal point segment after each digit. Note that this cause that in some case display may hold longer texts than number of digits. If display size is for example 4 digits and decimal points are enabled, display pattern will be "#.#.#.#." meaning that even text "1.2.3.4." (8 characters) will fit to this 4 digit display. But on the other hand, "...12" (5 characters) will not fit. Value | True to enable decimal points, false to have digits without decimal point segment. |
public Alignments DefaultAlignment Default alignment of text if not specified when calling SetText() or AddText() methods. This is also used in editor as test text alignment. Value | One of the choices from enum Alignments. |
public int DigitCount Sets or gets number of digits (numbers and/or characters) in this display. Value | Number of digits in display. |
public float DigitSpacing Spacing between digits. 1.0 is default spacing, smaller value brings digits closer to each other and larger pushes digits away from each other. Value | Percentage value defining how close or far away digits are from each other. |
public DisplayTypes DisplayType Type of the display, number of segments in each digit. Value | One of the choices from enum DisplayTypes. |
public FourteenSegmentStyles FourteenSegmentStyle Set or get fourteen segment display style. Value | One of the choices from enum FourteenSegmentStyles. |
public string InitialText Initial text that is added to display when display starts. Can be also empty string in which case display will be empty at start. Value | Text to show when scene and display starts. |
public Color OffColor Color of segment when it is not lit. Note that color can be also partially or fully transparent. This color can be changed at any time also after display is created to scene. Colors will be updated in this or next update loop. Value | Color to be used for segments that are turned off. |
public Color OnColor Color of segment when it is lit. Note that color can be also transparency. This color can be changed at any time also after display is created to scene. Colors will be updated in this or next update loop. Value | Color to be used for segments that are turned on. |
public float SegmentSpread Spread out segments or bring them closer inside one digit. 1.0 is default, positive value spreads segments away from each other, negative brings them closer to each other. Value | Percentage value defining how close or far away single digit segments are from each other. |
public SevenSegmentStyles SevenSegmentStyle Set or get seven segment display style. Value | One of the choices from enum SevenSegmentStyles. |
public SixteenSegmentStyles SixteenSegmentStyle Set or get sixteen segment display style. Value | One of the choices from enum SixteenSegmentStyles. |
public bool SmallerDigitsEnabled Enable or disable some digits being smaller than another. Value | True to enable digits that are smaller than rest, false to keep all digits in same size. |
public float SmallerDigitsSizePercent Set the size of smaller digits compared to normal size digits. Any value between 0.0 and 1.0 (exclusive) is accepted. For example, 1.0 would make smaller digits same size as normal, and 0.0 would make them invisibly small. Value | Percentage value defining size of smaller digits compared to normal size digits. |
public float SmallerDigitsVerticalPosition Set the vertical position of smaller digits compared to normal size digits. Any value between 0.0 and 1.0 (inclusive) is accepted. Value | Value defining vertical position of smaller digits compared to normal size digits, 0 being in bottom and 1 being in top. |
Methods
public void AddText (string text) Add text to this display using default text alignment. All the digits in display that this text is not using are not changed. Meaning previous content will stay on display if this new text is not written over it. Parameters | text | Text to add. |
public void AddText (string text, Alignments alignment) Add text to this display using specified text alignment. All the digits in display that this text is not using are not changed. Meaning previous content will stay on display if this new text is not written over it. Parameters | text | Text to add. | | alignment | Alignment of new text. |
public void AddText (string text, Alignments alignment, int offset) Add text to this display using specified text alignment and possible offset. All the digits in display that this text is not using are not changed. Meaning previous content will stay on display if this new text is not written over it. Parameters | text | Text to add. | | alignment | Alignment of new text. | | offset | Offset of new text. This will move text certain amount of digits to wanted direction. For example, when using left alignment and offset 2, text will start from third digit, leaving two first digits empty. If using left alignment and offset -1, first character of text will be ignored (it would be outside the display) and second character of text will be in first digit of display. |
public void Clear () Clear the display. This will turn all segments of all digits to off state.
public void Clear (int startIndex, int count) Clear part of the display. This will turn all segments of selected digits to off state. Parameters | startIndex | Index of first digit to clear. | | count | How many digits to clear. |
public void Fill () Fill the display. This will turn all segments of all digits to on state.
public void Fill (int startIndex, int count) Fill part of the display. This will turn all segments of selected digits to on state. Parameters | startIndex | Index of first digit to fill. | | count | How many digits to fill. |
public SDController GetSDController () Gets the SegmentDisplay Controller instance for this display. Note that you do not necessarily need this. If you just want to add text to display, you can use SetText() methods in this class. SDController is useful if you wish to run series of text changes or for example scroll text on display. Returns | SDController instance. Each display have only one controller instance, same one is returned every time this method is called. |
public bool IsEmpty () Check whatever display is completely empty. Returns | True if all segments are not lit, false otherwise. |
public bool IsFull () Check whatever display is completely filled. Returns | True if all segments are lit, false otherwise. |
public void MoveLeft () Move all the content in display to one digit left. Content of leftmost digit will be lost and rightmost digit is set empty. Note that this will not work correctly in display that have colons enabled since content can't be copied between normal digit and colon.
public void MoveRight () Move all the content in display to one digit right. Content of rightmost digit will be lost and lefttmost digit is set empty. Note that this will not work correctly in display that have colons enabled since content can't be copied between normal digit and colon.
public void SetText (string text) Set text to this display using default text alignment. All the digits in display that this text is not using, are set to off state. Meaning that display will be cleared from all previous content it may had. Parameters | text | Text to set. |
public void SetText (string text, Alignments alignment) Set text to this display using specified text alignment. All the digits in display that this text is not using, are set to off state. Meaning that display will be cleared from all previous content it may had. Parameters | text | Text to set. | | alignment | Alignment of the text. |
public void SetText (string text, Alignments alignment, int offset) Set text to this display using specified text alignment and possible offset. All the digits in display that this text is not using, are set to off state. Meaning that display will be cleared from all previous content it may had. Parameters | text | Text to set. | | alignment | Alignment of the text. | | offset | Offset of the text. This will move text certain amount of digits to wanted direction. For example, when using left alignment and offset 2, text will start from third digit, leaving two first digits empty. If using left alignment and offset -1, first character of text will be ignored (it would be outside the display) and second character of text will be in first digit of display. |
|