Skip to content

Commit

Permalink
feat(Util): Reuse overload withinrange
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Nov 13, 2024
1 parent d3814f7 commit 121664e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Assets/JCSUnity/Scripts/Input/JCS_ButtonSelectionGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void SelectSelection(int selectionIndex, bool hoverCheck = false)
{
if (hoverCheck)
{
if (JCS_Util.WithInArrayRange(selectionIndex, mSelections))
if (JCS_Util.WithInRange(selectionIndex, mSelections))
{
if (mSelections[selectionIndex].Skip)
return;
Expand All @@ -214,15 +214,15 @@ public void SelectSelection(int selectionIndex, bool hoverCheck = false)
if (mCurrentSelectIndex == selectionIndex)
return;

if (JCS_Util.WithInArrayRange(mCurrentSelectIndex, mSelections))
if (JCS_Util.WithInRange(mCurrentSelectIndex, mSelections))
{
// disable current active selection.
mSelections[mCurrentSelectIndex].Active = false;
}

this.mCurrentSelectIndex = selectionIndex;

this.mCurrentSelectIndex = JCS_Util.LoopInArray(this.mCurrentSelectIndex, mSelections);
this.mCurrentSelectIndex = JCS_Util.LoopIn(this.mCurrentSelectIndex, mSelections);

// active the new active selection.
mSelections[mCurrentSelectIndex].Active = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public List<JCS_TransformLinkedObject> NewLinked(int n = 1, int startIndex = 0)
/// <returns> List of removed linked object. </returns>
public List<JCS_TransformLinkedObject> RemoveLinked(int n = 1, int startIndex = 0)
{
if (!JCS_Util.WithInArrayRange(startIndex, mManagedList))
if (!JCS_Util.WithInRange(startIndex, mManagedList))
{
JCS_Debug.LogReminder("Can't remove linked node with index lower than 0");
return null;
Expand Down
2 changes: 1 addition & 1 deletion Assets/JCSUnity/Scripts/UI/Page/JCS_PageIndicators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void SetPage(int page)
{
SetSprite(mInactiveSprite);

if (!JCS_Util.WithInArrayRange(page, mIndicators))
if (!JCS_Util.WithInRange(page, mIndicators))
{
JCS_Debug.LogWarning("Page indicators out of range exception");
return;
Expand Down
8 changes: 4 additions & 4 deletions Assets/JCSUnity/Scripts/Util/JCS_Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public static bool WithInRange(float minRange, float maxRange, float currentVal)
/// With in array range. (Array)
/// </summary>
/// <returns></returns>
public static bool WithInArrayRange<T>(int index, T[] arr)
public static bool WithInRange<T>(int index, T[] arr)
{
return index >= 0 && index < arr.Length;
}
Expand All @@ -204,7 +204,7 @@ public static bool WithInArrayRange<T>(int index, T[] arr)
/// With in array range. (List)
/// </summary>
/// <returns></returns>
public static bool WithInArrayRange<T>(int index, List<T> arr)
public static bool WithInRange<T>(int index, List<T> arr)
{
return index >= 0 && index < arr.Count;
}
Expand All @@ -216,7 +216,7 @@ public static bool WithInArrayRange<T>(int index, List<T> arr)
/// <param name="index"> Index </param>
/// <param name="arr"> Array. </param>
/// <returns> index that looped. </returns>
public static int LoopInArray<T>(int index, T[] arr)
public static int LoopIn<T>(int index, T[] arr)
{
// loop through the array, if at the tail of the array set it to head.
if (index < 0)
Expand All @@ -234,7 +234,7 @@ public static int LoopInArray<T>(int index, T[] arr)
/// <param name="index"> Index </param>
/// <param name="arr"> List. </param>
/// <returns> index that looped. </returns>
public static int LoopInArray<T>(int index, List<T> arr)
public static int LoopIn<T>(int index, List<T> arr)
{
// loop through the array, if at the tail of the array set it to head.
if (index < 0)
Expand Down
4 changes: 2 additions & 2 deletions docs/ScriptReference/Util/JCS_Util.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ All code utility is stored here.
| FindObjectByType | Retrieves the first active loaded object of Type type. |
| FindObjectsByType | Retrieves a list of all loaded objects of Type type. |
| WithInRange | Check if the value is within the range. |
| WithInArrayRange | Check if the index valid within the array length.&nbsp&nbsp(0 ~ (length - 1)) |
| LoopInArray | Make the index is within the array length by setting the maxinum of (legnth - 1) or mininum of 0. |
| WithInRange | Check if the index valid within the array length. |
| LoopIn | Make the index is within the array length by setting the maxinum of (legnth - 1) or mininum of 0. |
| SpawnAnimateObject | Spawn a gameobject with animation attached. |
| SpawnAnimateObjectDeathEvent | Spawn a gameobject with the animator and death event on it. |
| SetActiveToAllChildren | Active all the child in a transform. |
Expand Down

0 comments on commit 121664e

Please sign in to comment.