Last active
January 19, 2021 21:48
-
-
Save kankikuchi/0074c71dbd5b62d7d0e274a9a4deb03c to your computer and use it in GitHub Desktop.
間の値か確認するクラス【Unity】
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ValueBetweenChecker.cs | |
// http://kan-kikuchi.hatenablog.com/entry/ValueBetweenChecker | |
// | |
// Created by kan.kikuchi on 2020.03.26. | |
using UnityEngine; | |
/// <summary> | |
/// 間の値か確認するクラス | |
/// </summary> | |
public static class ValueBetweenChecker { | |
//================================================================================= | |
//判定 | |
//================================================================================= | |
/// <summary> | |
/// targetがaとbの間の数値か(int用) | |
/// </summary> | |
public static bool IsBetween(int target, int a, int b) { | |
if (a > b) { | |
return target <= a && target >= b; | |
} | |
return target <= b && target >= a; | |
} | |
/// <summary> | |
/// targetがaとbの間の数値か(float用) | |
/// </summary> | |
public static bool IsBetween(float target, float a, float b) { | |
if (a > b) { | |
return target <= a && target >= b; | |
} | |
return target <= b && target >= a; | |
} | |
/// <summary> | |
/// targetがaとbの間の数値か(Vector2用) | |
/// </summary> | |
public static bool IsBetween(ref Vector2 target, ref Vector2 a, ref Vector2 b) { | |
return IsBetween(target.x, a.x, b.x) && IsBetween(target.y, a.y, b.y); | |
} | |
/// <summary> | |
/// targetがaとbの間の数値か(Vector3用) | |
/// </summary> | |
public static bool IsBetween(ref Vector3 target, ref Vector3 a, ref Vector3 b) { | |
return IsBetween(target.x, a.x, b.x) && IsBetween(target.y, a.y, b.y) && IsBetween(target.z, a.z, b.z); | |
} | |
/// <summary> | |
/// targetがaとbの間の数値か(Vector2Int用) | |
/// </summary> | |
public static bool IsBetween(ref Vector2Int target, ref Vector2Int a, ref Vector2Int b) { | |
return IsBetween(target.x, a.x, b.x) && IsBetween(target.y, a.y, b.y); | |
} | |
/// <summary> | |
/// targetがaとbの間の数値か(Vector3Int用) | |
/// </summary> | |
public static bool IsBetween(ref Vector3Int target, ref Vector3Int a, ref Vector3Int b) { | |
return IsBetween(target.x, a.x, b.x) && IsBetween(target.y, a.y, b.y) && IsBetween(target.z, a.z, b.z); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment