Last active
January 19, 2021 21:48
-
-
Save kankikuchi/ca0d59b082e698545e0a843c081bc2b9 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
// BetweenExtention.cs | |
// http://kan-kikuchi.hatenablog.com/entry/ValueBetweenChecker | |
// | |
// Created by kan.kikuchi on 2020.03.26. | |
using UnityEngine; | |
/// <summary> | |
/// 間の値か確認する拡張メソッドを追加するクラス | |
/// </summary> | |
public static class BetweenExtention { | |
//================================================================================= | |
//判定 | |
//================================================================================= | |
/// <summary> | |
/// targetがaとbの間の数値か(int用) | |
/// </summary> | |
public static bool IsBetween(this 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(this 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 this 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 this 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 this 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 this 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