91 lines
1.7 KiB
C#
91 lines
1.7 KiB
C#
using UnityEngine;
|
|||
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
|
||
|
|
public class SegmentDisplay : MonoBehaviour{
|
||
|
|
public byte segments;
|
||
|
|
private Material segmentMaterial;
|
||
|
|
private int _mask;
|
||
|
|
|
||
|
|
private Dictionary<char, byte> char_map = new Dictionary<char, byte>() {
|
||
|
|
//digits
|
||
|
|
{'0', 0x3f },
|
||
|
|
{'1', 0x06 },
|
||
|
|
{'2', 0x5b },
|
||
|
|
{'3', 0x4f },
|
||
|
|
{'4', 0x66 },
|
||
|
|
{'5', 0x6d },
|
||
|
|
{'6', 0x7d },
|
||
|
|
{'7', 0x07 },
|
||
|
|
{'8', 0x7f },
|
||
|
|
{'9', 0x6f },
|
||
|
|
};
|
||
|
|
|
||
|
|
public void SetChar(char c)
|
||
|
|
{
|
||
|
|
byte val = char_map.ContainsKey(c) ? char_map[c] : (byte)0;
|
||
|
|
_mask = (_mask & (1 << 7)) | val;
|
||
|
|
UpdateShader();
|
||
|
|
}
|
||
|
|
|
||
|
|
Material mat
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
if (segmentMaterial == null)
|
||
|
|
{
|
||
|
|
segmentMaterial = gameObject.GetComponent<Renderer>().materials[1]; ;
|
||
|
|
}
|
||
|
|
return segmentMaterial;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void UpdateShader()
|
||
|
|
{
|
||
|
|
mat.SetInt("segments", _mask);
|
||
|
|
}
|
||
|
|
|
||
|
|
public bool ShowDot
|
||
|
|
{
|
||
|
|
get { return (_mask & (1 << 7)) != 0; }
|
||
|
|
set {
|
||
|
|
_mask = (_mask & ~(1 << 7));
|
||
|
|
if (value){
|
||
|
|
_mask |= 1 << 7;
|
||
|
|
}
|
||
|
|
UpdateShader();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void Start ()
|
||
|
|
{
|
||
|
|
|
||
|
|
// StartCoroutine(UpdateDigit());
|
||
|
|
}
|
||
|
|
|
||
|
|
void Update (){
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
private int d = 0;
|
||
|
|
|
||
|
|
/*IEnumerator UpdateDigit() {
|
||
|
|
while (true) {
|
||
|
|
yield return new WaitForSeconds(1);
|
||
|
|
|
||
|
|
if (d >= 9)
|
||
|
|
{
|
||
|
|
d = 0;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
d++;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
}*/
|
||
|
|
}
|