Skip to content

Commit 1e6431f

Browse files
author
lawwong
committed
Fix incorrect EnumArray.StaticMin/Max
1 parent 54542a9 commit 1e6431f

File tree

7 files changed

+31
-43
lines changed

7 files changed

+31
-43
lines changed

Assets/HTC.UnityPlugin/Utility/Container/EnumArray.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ static EnumArrayBase()
399399
continue; // length out of range
400400
}
401401
StaticMinInt = vi;
402+
StaticMin = ve;
402403
}
403404
else if (vi > StaticMaxInt)
404405
{
@@ -408,6 +409,7 @@ static EnumArrayBase()
408409
continue; // length out of range
409410
}
410411
StaticMaxInt = vi;
412+
StaticMax = ve;
411413
}
412414
}
413415

Assets/HTC.UnityPlugin/ViveInputUtility/Examples/10.ControllerTooltips/ControllerTooltips.unity

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,9 @@ MonoBehaviour:
13021302
- {fileID: 0}
13031303
- {fileID: 0}
13041304
- {fileID: 0}
1305+
- {fileID: 0}
1306+
- {fileID: 0}
1307+
- {fileID: 0}
13051308
m_defaultRenderData: {fileID: 0}
13061309
m_tooltipParent: {fileID: 0}
13071310
m_tooltipPrefab: {fileID: 191042, guid: f64ed917a7e3d044d8d831b345edca5d, type: 2}
@@ -3006,18 +3009,7 @@ MonoBehaviour:
30063009
m_roleValueInt: 0
30073010
m_onIsValidChanged:
30083011
m_PersistentCalls:
3009-
m_Calls:
3010-
- m_Target: {fileID: 724095205}
3011-
m_MethodName: SetActive
3012-
m_Mode: 0
3013-
m_Arguments:
3014-
m_ObjectArgument: {fileID: 0}
3015-
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
3016-
m_IntArgument: 0
3017-
m_FloatArgument: 0
3018-
m_StringArgument:
3019-
m_BoolArgument: 0
3020-
m_CallState: 2
3012+
m_Calls: []
30213013
m_TypeName: HTC.UnityPlugin.Vive.VivePoseTracker+UnityEventBool, Assembly-CSharp,
30223014
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
30233015
--- !u!114 &2006434404

Assets/HTC.UnityPlugin/ViveInputUtility/Examples/10.ControllerTooltips/ModeManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public enum Mode
2424

2525
private void Awake()
2626
{
27-
SwitchMode(initMode);
27+
EnterMode(initMode);
2828
}
2929

3030
public void SwitchToTeleportMode() { SwitchMode(Mode.Teleport); }

Assets/HTC.UnityPlugin/ViveInputUtility/Examples/10.ControllerTooltips/TooltipMenu.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ MonoBehaviour:
1313
m_EditorClassIdentifier:
1414
m_buttonList: 0400000000000000
1515
m_dataList:
16-
- labelText: Cancel
16+
- labelText: Close Menu
1717
- labelText: Select

Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/ControllerTooltip/Editor/TooltipRenderDataAssetBaseEditor.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,26 +103,18 @@ public override void OnInspectorGUI()
103103
private void ShowAddTriggerMenu()
104104
{
105105
var menu = new GenericMenu();
106-
var displayedNames = new List<GUIContent>(btnEnumInfo.displayedLength);
107-
var displayedValues = new List<int>(btnEnumInfo.displayedLength);
108-
for (int i = 0, imax = btnEnumInfo.displayedLength; i < imax; ++i)
106+
foreach(var ev in visibleInList.EnumValues)
109107
{
110-
var v = btnEnumInfo.displayedValues[i];
111-
displayedNames.Add(new GUIContent(btnEnumInfo.displayedNames[i]));
112-
displayedValues.Add(v);
113-
}
114-
for (int i = 0, imax = btnEnumInfo.displayedLength; i < imax; ++i)
115-
{
116-
var value = btnEnumInfo.displayedValues[i];
117-
//if (value == (int)ControllerButton.None) { continue; }
118-
var name = btnEnumInfo.displayedNames[i];
119-
if (visibleInList[value])
108+
var button = ev.Key;
109+
var visible = ev.Value;
110+
var name = visibleInList.EnumName((int)button);
111+
if (visible)
120112
{
121113
menu.AddDisabledItem(new GUIContent(name));
122114
}
123115
else
124116
{
125-
menu.AddItem(new GUIContent(name), false, OnAddNewSelected, value);
117+
menu.AddItem(new GUIContent(name), false, OnAddNewSelected, (int)button);
126118
}
127119
}
128120
menu.ShowAsContext();

Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/ControllerTooltip/TooltipRendererBase.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ public bool TryGetValidTooltipRig(ControllerButton button, out TooltipRig rig)
2727
if (!EnumArrayBase<ControllerButton>.StaticIsValidIndex((int)button)) { return false; }
2828

2929
var model = VRModule.GetDeviceState(m_viveRole.GetDeviceIndex()).deviceModel;
30-
31-
TooltipRigAsset rigSetAsset = null;
30+
var rigSetAsset = (TooltipRigAsset)null;
3231
if (m_customTooltipRigSet != null)
3332
{
3433
rigSetAsset = m_customTooltipRigSet[(int)model];
@@ -89,41 +88,42 @@ private void OnDeviceIndexChanged(uint deviceIndex)
8988
{
9089
if (dataStateArray == null) { return; }
9190

92-
for (ControllerButton i = EnumArrayBase<ControllerButton>.StaticMin, imax = EnumArrayBase<ControllerButton>.StaticMax; i <= imax; ++i)
91+
foreach (var ev in dataStateArray.EnumValues)
9392
{
94-
var state = dataStateArray[(int)i];
93+
var button = ev.Key;
94+
var state = ev.Value;
9595
if (!state.isValid) { continue; }
9696

9797
TooltipRig rig;
98-
var shouldShow = TryGetValidTooltipRig(i, out rig);
98+
var shouldShow = TryGetValidTooltipRig(button, out rig);
9999
var wasVisible = state.isVisible;
100100

101101
if (wasVisible)
102102
{
103103
if (shouldShow)
104104
{
105-
OnShowTooltip(i, rig, state.data, true);
105+
OnShowTooltip(button, rig, state.data, true);
106106
}
107107
else
108108
{
109-
dataStateArray[(int)i] = new DataState()
109+
dataStateArray[(int)button] = new DataState()
110110
{
111111
state = State.Hidden,
112112
data = state.data,
113113
};
114-
OnHideTooltip(i);
114+
OnHideTooltip(button);
115115
}
116116
}
117117
else
118118
{
119119
if (shouldShow)
120120
{
121-
dataStateArray[(int)i] = new DataState()
121+
dataStateArray[(int)button] = new DataState()
122122
{
123123
state = State.Visible,
124124
data = state.data,
125125
};
126-
OnShowTooltip(i, rig, state.data, false);
126+
OnShowTooltip(button, rig, state.data, false);
127127
}
128128
}
129129
}
@@ -166,15 +166,17 @@ public void SetTooltipData(IEnumerator<KeyValuePair<ControllerButton, TRenderDat
166166
}
167167
}
168168

169-
for (ControllerButton i = EnumArrayBase<ControllerButton>.StaticMin, imax = EnumArrayBase<ControllerButton>.StaticMax; i <= imax; ++i)
169+
foreach (var ev in btnVisibleTmp.EnumValues)
170170
{
171-
if (btnVisibleTmp[(int)i])
171+
var button = ev.Key;
172+
var wasSet = ev.Value;
173+
if (wasSet)
172174
{
173-
btnVisibleTmp[(int)i] = false;
175+
btnVisibleTmp[(int)button] = false;
174176
}
175177
else
176178
{
177-
ResetTooltipData(i);
179+
ResetTooltipData(button);
178180
}
179181
}
180182
}
@@ -186,7 +188,6 @@ public void SetTooltipData(ControllerButton button, TRenderData data)
186188

187189
TooltipRig rig;
188190
var shouldShow = TryGetValidTooltipRig(button, out rig);
189-
190191
dataStateArray[(int)button] = new DataState()
191192
{
192193
state = shouldShow ? State.Visible : State.Hidden,

Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/ViveInput/ViveInput.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public enum ButtonEventType
3333
/// </summary>
3434
public enum ControllerButton
3535
{
36+
[InvalidEnumArrayIndex]
3637
None = -1,
3738

3839
// classic buttons

0 commit comments

Comments
 (0)