Skip to content

Commit 1ac296c

Browse files
committed
button selection group make hover compatible with mouse/PC.
1 parent 759a934 commit 1ac296c

File tree

3 files changed

+32
-57
lines changed

3 files changed

+32
-57
lines changed

Assets/JCSUnity/Scripts/Input/JCS_ButtonSelection.cs

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,6 @@ public class JCS_ButtonSelection
3535
public SelectionDisable selectionDisable = SelectionDisable;
3636
public SelectionActive selectionActive = SelectionActive;
3737

38-
/// <summary>
39-
/// Direction the object link to button.
40-
/// </summary>
41-
public enum LinkDirection
42-
{
43-
ButtonToSelection,
44-
SelectionToButton,
45-
};
46-
4738

4839
/*******************************************/
4940
/* Private Variables */
@@ -90,14 +81,6 @@ public enum LinkDirection
9081
[SerializeField]
9182
private bool mSelfAsButton = true;
9283

93-
[Tooltip("Make skip variable with interactable with the button.")]
94-
[SerializeField]
95-
private bool mLinkSkipWithInteractableButton = true;
96-
97-
[Tooltip("Direction the 'skip' variable connect to button's interactable variable.")]
98-
[SerializeField]
99-
private LinkDirection mLinkDirection = LinkDirection.ButtonToSelection;
100-
10184

10285
[Header("- Full Control (JCS_ButtonSelection)")]
10386

@@ -124,8 +107,6 @@ public enum LinkDirection
124107
/*******************************************/
125108
/* setter / getter */
126109
/*******************************************/
127-
public LinkDirection linkDirection { get { return this.mLinkDirection; } set { this.mLinkDirection = value; } }
128-
public bool LinkSkipWithInteractableButton { get { return this.mLinkSkipWithInteractableButton; } set { this.mLinkSkipWithInteractableButton = value; } }
129110
public bool DeactiveAtAwake { get { return this.mDeactiveAtAwake; } set { this.mDeactiveAtAwake = value; } }
130111
public bool SelfAsButton { get { return this.mSelfAsButton; } set { this.mSelfAsButton = value; } }
131112
public JCS_Button Button { get { return this.mButton; } set { this.mButton = value; } }
@@ -140,16 +121,7 @@ public bool Active
140121
}
141122
}
142123
public JCS_ButtonSelectionGroup ButtonSelectionGroup { get { return this.mButtonSelectionGroup; } set { this.mButtonSelectionGroup = value; } }
143-
public bool Skip
144-
{
145-
get { return this.mSkip; }
146-
set
147-
{
148-
this.mSkip = value;
149-
150-
SetInteractableButton();
151-
}
152-
}
124+
public bool Skip { get { return this.mSkip; } }
153125

154126
public JCS_ButtonSelection UpSelection { get { return this.mUpSelection; } set { this.mUpSelection = value; } }
155127
public JCS_ButtonSelection DownSelection { get { return this.mDownSelection; } set { this.mDownSelection = value; } }
@@ -180,10 +152,9 @@ private void Awake()
180152

181153
private void Start()
182154
{
183-
SetInteractableButton();
155+
SetSkip(mSkip);
184156
}
185157

186-
187158
/*******************************************/
188159
/* Self-Define */
189160
/*******************************************/
@@ -280,31 +251,15 @@ private void ActiveEffects(bool act)
280251
/// <summary>
281252
/// Make skip variable connect to interactable with button.
282253
/// </summary>
283-
private void SetInteractableButton()
254+
public void SetSkip(bool act, bool fromButton = false)
284255
{
285-
if (!mLinkSkipWithInteractableButton || mButton == null)
256+
if (mButton == null)
286257
return;
287258

288-
switch (mLinkDirection)
289-
{
290-
case LinkDirection.ButtonToSelection:
291-
{
292-
// change itself, button have more control/power
293-
// over selection.
294-
mSkip = !mButton.Interactable;
295-
}
296-
return;
297-
case LinkDirection.SelectionToButton:
298-
{
299-
// vice versa, this have more control/power
300-
// over button.
301-
mButton.SetInteractable(!mSkip);
302-
}
303-
return;
304-
}
259+
this.mSkip = act;
305260

306-
// this should not happens...
307-
JCS_Debug.LogWarning("Button selection link failed...");
261+
if (!fromButton)
262+
mButton.SetInteractable(!mSkip, true);
308263
}
309264

310265
}

Assets/JCSUnity/Scripts/Input/JCS_ButtonSelectionGroup.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public enum Direction
4040
UP,
4141
DOWN,
4242
RIGHT,
43-
LEFT,
43+
LEFT,
4444
};
4545

4646

@@ -218,8 +218,17 @@ public void PrevSelection()
218218
/// Selection this selection.
219219
/// </summary>
220220
/// <param name="selectionIndex"> index to select. </param>
221-
public void SelectSelection(int selectionIndex)
221+
public void SelectSelection(int selectionIndex, bool hoverCheck = false)
222222
{
223+
if (hoverCheck)
224+
{
225+
if (JCS_Utility.WithInArrayRange(selectionIndex, mSelections))
226+
{
227+
if (mSelections[selectionIndex].Skip)
228+
return;
229+
}
230+
}
231+
223232
// no need to do anything.
224233
if (mCurrentSelectIndex == selectionIndex)
225234
return;
@@ -240,12 +249,19 @@ public void SelectSelection(int selectionIndex)
240249
if (selectionChanged != null)
241250
selectionChanged.Invoke();
242251
}
252+
public void SelectSelectionHover(int selectionIndex)
253+
{
254+
SelectSelection(selectionIndex, true);
255+
}
243256

244257
/// <summary>
245258
/// Selection this selection.
259+
///
260+
/// ATTENTION(jenchieh): this can only use by the 'Event
261+
/// Trigger' component.
246262
/// </summary>
247263
/// <param name="selection"> selection to select. </param>
248-
public void SelectSelection(JCS_ButtonSelection selection)
264+
public void SelectSelection(JCS_ButtonSelection selection, bool hoverCheck = false)
249265
{
250266
if (selection == null)
251267
return;
@@ -264,14 +280,18 @@ public void SelectSelection(JCS_ButtonSelection selection)
264280

265281
if (bs == selection)
266282
{
267-
SelectSelection(index);
283+
SelectSelection(index, hoverCheck);
268284
return;
269285
}
270286
}
271287

272288
JCS_Debug.LogError(@"Try to select a selection, but seems like the
273289
selection is not in the group...");
274290
}
291+
public void SelectSelectionHover(JCS_ButtonSelection selection)
292+
{
293+
SelectSelection(selection, true);
294+
}
275295

276296
/// <summary>
277297
/// Selection this selection.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Build from DESKTOP-5QUO247 at 12/9/2017 5:56:40 AM
1+
Build from DESKTOP-5QUO247 at 12/9/2017 7:48:41 AM

0 commit comments

Comments
 (0)