Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- using OhiraKyou.Extensions;
- using System;
- namespace OhiraKyou {
- public class CustomMath {
- public static float Wrap01 (float value) {
- return Wrap(value, 0f, 1f);
- }
- public static float Wrap (float value, float min, float max) {
- if (min == 0f && max == 0f) return 0f;
- return (((value - min) % (max - min)) + (max - min)) % (max - min) + min;
- }
- public static int Wrap (int value, int min, int max) {
- if (min == 0 && max == 0) return 0;
- max++; // makes max inclusive
- return (((value - min) % (max - min)) + (max - min)) % (max - min) + min;
- }
- public static float GetWrappedSeconds (float currentSeconds, float maxTime) {
- return Wrap(currentSeconds + Time.deltaTime, 0f, maxTime);
- }
- public static float GetWrappedSeconds (float currentSeconds, float deltaTime, float maxTime) {
- return Wrap(currentSeconds + deltaTime, 0f, maxTime);
- }
- public static T Clamp<T> (T value, T min, T max) where T : IComparable<T> {
- if (value.CompareTo(min) < 0) return min;
- else if (value.CompareTo(max) > 0) return max;
- else return value;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment