mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-13 09:07:39 +02:00
Change Project License to MIT (#700)
* license change replace unneeded package * reword this
This commit is contained in:
22
Assets/Scripts/Util/MathUtils.cs
Normal file
22
Assets/Scripts/Util/MathUtils.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace HeavenStudio.Util
|
||||
{
|
||||
public static class MathUtils
|
||||
{
|
||||
public static float Round2Nearest(float value, float nearest)
|
||||
{
|
||||
return Mathf.Round(value / nearest) * nearest;
|
||||
}
|
||||
|
||||
public static float Normalize(float value, float min, float max)
|
||||
{
|
||||
return (value - min) / (max - min);
|
||||
}
|
||||
|
||||
public static bool IsBetween(this float value, float min, float max)
|
||||
{
|
||||
return value >= min && value <= max;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Util/MathUtils.cs.meta
Normal file
11
Assets/Scripts/Util/MathUtils.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ecfdacc9bf1519248b0b93009ed2a045
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using Starpelly;
|
||||
|
||||
|
||||
namespace HeavenStudio.Util
|
||||
{
|
||||
@ -287,7 +287,7 @@ namespace HeavenStudio.Util
|
||||
while (bendTimer < bendTime)
|
||||
{
|
||||
bendTimer += Time.deltaTime;
|
||||
float normalizedProgress = Mathp.Normalize(bendTimer, 0, bendTime);
|
||||
float normalizedProgress = MathUtils.Normalize(bendTimer, 0, bendTime);
|
||||
float currentPitch = Mathf.Lerp(startingPitch, bendedPitch, normalizedProgress);
|
||||
audioSource.pitch = Mathf.Min(currentPitch, bendedPitch);
|
||||
yield return null;
|
||||
@ -302,7 +302,7 @@ namespace HeavenStudio.Util
|
||||
while (bendTimer < bendTime)
|
||||
{
|
||||
bendTimer += Time.deltaTime;
|
||||
float normalizedProgress = Mathp.Normalize(bendTimer, 0, bendTime);
|
||||
float normalizedProgress = MathUtils.Normalize(bendTimer, 0, bendTime);
|
||||
float currentPitch = Mathf.Lerp(startingPitch, bendedPitch, 1 - normalizedProgress);
|
||||
audioSource.pitch = Mathf.Max(currentPitch, pitch);
|
||||
yield return null;
|
||||
|
@ -1,6 +1,8 @@
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace HeavenStudio.Util
|
||||
{
|
||||
public static class StringUtils
|
||||
@ -28,5 +30,36 @@ namespace HeavenStudio.Util
|
||||
"$1 $2"
|
||||
);
|
||||
}
|
||||
|
||||
public static string Color2Hex(this Color color)
|
||||
{
|
||||
Color32 col = (Color32)color;
|
||||
string hex = col.r.ToString("X2") + col.g.ToString("X2") + col.b.ToString("X2");
|
||||
return hex;
|
||||
}
|
||||
|
||||
public static Color Hex2RGB(this string hex)
|
||||
{
|
||||
if (hex is null or "") return Color.black;
|
||||
try
|
||||
{
|
||||
hex = hex.Replace("0x", "");//in case the string is formatted 0xFFFFFF
|
||||
hex = hex.Replace("#", "");//in case the string is formatted #FFFFFF
|
||||
byte a = 255;//assume fully visible unless specified in hex
|
||||
byte r = byte.Parse(hex.Substring(0, 2), NumberStyles.HexNumber);
|
||||
byte g = byte.Parse(hex.Substring(2, 2), NumberStyles.HexNumber);
|
||||
byte b = byte.Parse(hex.Substring(4, 2), NumberStyles.HexNumber);
|
||||
//Only use alpha if the string has enough characters
|
||||
if (hex.Length >= 8)
|
||||
{
|
||||
a = byte.Parse(hex.Substring(6, 2), NumberStyles.HexNumber);
|
||||
}
|
||||
return new Color32(r, g, b, a);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Color.black;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user