OSDN Git Service

Added Assets for main menu
[mindgames/Mindgames_main.git] / Mindgames / Library / PackageCache / com.unity.render-pipelines.high-definition@6.9.0-preview / Runtime / Core / Debugging / Prefabs / Scripts / DebugUIHandlerEnumField.cs
1 using System;
2 using UnityEngine.UI;
3
4 namespace UnityEngine.Experimental.Rendering.UI
5 {
6     public class DebugUIHandlerEnumField : DebugUIHandlerWidget
7     {
8         public Text nameLabel;
9         public Text valueLabel;
10         protected DebugUI.EnumField m_Field;
11
12         internal override void SetWidget(DebugUI.Widget widget)
13         {
14             base.SetWidget(widget);
15             m_Field = CastWidget<DebugUI.EnumField>();
16             nameLabel.text = m_Field.displayName;
17             UpdateValueLabel();
18         }
19
20         public override bool OnSelection(bool fromNext, DebugUIHandlerWidget previous)
21         {
22             nameLabel.color = colorSelected;
23             valueLabel.color = colorSelected;
24             return true;
25         }
26
27         public override void OnDeselection()
28         {
29             nameLabel.color = colorDefault;
30             valueLabel.color = colorDefault;
31         }
32
33         public override void OnAction()
34         {
35             OnIncrement(false);
36         }
37
38         public override void OnIncrement(bool fast)
39         {
40             if (m_Field.enumValues.Length == 0)
41                 return;
42
43             var array = m_Field.enumValues;
44             int index = m_Field.currentIndex;
45
46             if (index == array.Length - 1)
47             {
48                 index = 0;
49             }
50             else
51             {
52                 if (fast)
53                 {
54                     //check if quickSeparators have not been constructed
55                     //it is the case when not constructed with autoenum
56                     var separators = m_Field.quickSeparators;
57                     if(separators == null)
58                     {
59                         m_Field.InitQuickSeparators();
60                         separators = m_Field.quickSeparators;
61                     }
62
63                     int idxSup = 0;
64                     for (; idxSup < separators.Length && index + 1 > separators[idxSup]; ++idxSup) ;
65                     if(idxSup == separators.Length)
66                     {
67                         index = 0;
68                     }
69                     else
70                     {
71                         index = separators[idxSup];
72                     }
73                 }
74                 else
75                 {
76                     index += 1;
77                 }
78             }
79
80             m_Field.SetValue(array[index]);
81             m_Field.currentIndex = index;
82             UpdateValueLabel();
83         }
84
85         public override void OnDecrement(bool fast)
86         {
87             if (m_Field.enumValues.Length == 0)
88                 return;
89
90             var array = m_Field.enumValues;
91             int index = m_Field.currentIndex;
92
93             if (index == 0)
94             {
95                 if(fast)
96                 {
97                     //check if quickSeparators have not been constructed
98                     //it is thecase when not constructed with autoenum
99                     var separators = m_Field.quickSeparators;
100                     if (separators == null)
101                     {
102                         m_Field.InitQuickSeparators();
103                         separators = m_Field.quickSeparators;
104                     }
105
106                     index = separators[separators.Length - 1];
107                 }
108                 else
109                 {
110                     index = array.Length - 1;
111                 }
112             }
113             else
114             {
115                 if (fast)
116                 {
117                     //check if quickSeparators have not been constructed
118                     //it is the case when not constructed with autoenum
119                     var separators = m_Field.quickSeparators;
120                     if (separators == null)
121                     {
122                         m_Field.InitQuickSeparators();
123                         separators = m_Field.quickSeparators;
124                     }
125
126                     int idxInf = separators.Length - 1;
127                     for (; idxInf > 0 && index <= separators[idxInf]; --idxInf) ;
128                     index = separators[idxInf];
129                 }
130                 else
131                 {
132                     index -= 1;
133                 }
134             }
135
136             m_Field.SetValue(array[index]);
137             m_Field.currentIndex = index;
138             UpdateValueLabel();
139         }
140
141         protected virtual void UpdateValueLabel()
142         {
143             int index = m_Field.currentIndex;
144
145             // Fallback just in case, we may be handling sub/sectionned enums here
146             if (index < 0)
147                 index = 0;
148
149             valueLabel.text = "< " + m_Field.enumNames[index].text + " >";
150         }
151     }
152 }