-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimeLocalizeAdapter.cs
113 lines (87 loc) · 2.9 KB
/
TimeLocalizeAdapter.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using UnityEngine;
namespace CodeWriter.ViewBinding.Applicators.Adapters
{
[AddComponentMenu("View Binding/Adapters/[Binding] Time Localize Adapter")]
public class TimeLocalizeAdapter : TimeLocalizeAdapterBase
{
[Space]
[SerializeField]
private bool showDays = false;
[SerializeField]
private bool showHours = false;
[SerializeField]
private bool showMinutes = false;
[Space]
[SerializeField]
private string formatDaysHoursMinutes = "TIME_D_H_M";
[SerializeField]
private string formatHoursMinutesSeconds = "TIME_H_M_S";
[SerializeField]
private string formatDaysHours = "TIME_D_H";
[SerializeField]
private string formatHoursMinutes = "TIME_H_M";
[SerializeField]
private string formatMinutesSeconds = "TIME_M_S";
[SerializeField]
private string formatHours = "TIME_H";
[SerializeField]
private string formatDays = "TIME_D";
[SerializeField]
private string formatMinutes = "TIME_M";
[SerializeField]
private string formatSeconds = "TIME_S";
[SerializeField]
private string formatZero = "TIME_S";
protected override string GetTimeStringFormat(TimeSpan span)
{
days.Value = (int) span.TotalDays;
if (days.Value > 0 && showDays)
{
hours.Value = span.Hours;
minutes.Value = span.Minutes;
seconds.Value = span.Seconds;
if (hours.Value > 0 && minutes.Value > 0)
{
return formatDaysHoursMinutes;
}
if (hours.Value > 0)
{
return formatDaysHours;
}
return formatDays;
}
hours.Value = (int) span.TotalHours;
if (hours.Value > 0 && showHours)
{
minutes.Value = span.Minutes;
seconds.Value = span.Seconds;
if (minutes.Value > 0 && seconds.Value > 0)
{
return formatHoursMinutesSeconds;
}
if (minutes.Value > 0)
{
return formatHoursMinutes;
}
return formatHours;
}
minutes.Value = (int) span.TotalMinutes;
if (minutes.Value > 0 && showMinutes)
{
seconds.Value = span.Seconds;
if (seconds.Value > 0)
{
return formatMinutesSeconds;
}
return formatMinutes;
}
seconds.Value = (int) span.TotalSeconds;
if (seconds.Value > 0)
{
return formatSeconds;
}
return formatZero;
}
}
}