chunk 2: remaining non-audio non-NewImport assets
This commit is contained in:
23
Assets/FirstGearGames/Utilities/Arrays.cs
Normal file
23
Assets/FirstGearGames/Utilities/Arrays.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FirstGearGames.Utilities.Objects
|
||||
{
|
||||
|
||||
public static class Arrays
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds an entry to a list if it does not exist already.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name=""></param>
|
||||
/// <param name="value"></param>
|
||||
public static void AddUnique<T>(this List<T> list, object value)
|
||||
{
|
||||
if (!list.Contains((T)value))
|
||||
list.Add((T)value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
18
Assets/FirstGearGames/Utilities/Arrays.cs.meta
Normal file
18
Assets/FirstGearGames/Utilities/Arrays.cs.meta
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 76a2fc6713d4d504fb1c3f004962f574
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 162991
|
||||
packageName: Smooth Camera Shaker
|
||||
packageVersion: 2.12
|
||||
assetPath: Assets/FirstGearGames/Utilities/Arrays.cs
|
||||
uploadId: 376379
|
||||
60
Assets/FirstGearGames/Utilities/DDOL.cs
Normal file
60
Assets/FirstGearGames/Utilities/DDOL.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace FirstGearGames.Utilities.Objects
|
||||
{
|
||||
|
||||
|
||||
public class DDOL : MonoBehaviour
|
||||
{
|
||||
#region Public.
|
||||
/// <summary>
|
||||
/// Singleton instance of this class.
|
||||
/// </summary>
|
||||
public static DDOL Instance { get; private set; }
|
||||
#endregion
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
FirstInitialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes this script for use. Should only be completed once.
|
||||
/// </summary>
|
||||
private void FirstInitialize()
|
||||
{
|
||||
if (Instance != null && Instance != this)
|
||||
{
|
||||
Debug.LogError("Multiple DDOL scripts found. There should be only one.");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Instance = this;
|
||||
gameObject.name = "FirstGearGames DDOL";
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current DDOL or creates one if not yet created.
|
||||
/// </summary>
|
||||
public static DDOL ReturnDDOL()
|
||||
{
|
||||
//Not yet made.
|
||||
if (Instance == null)
|
||||
{
|
||||
GameObject obj = new GameObject();
|
||||
DDOL ddol = obj.AddComponent<DDOL>();
|
||||
return ddol;
|
||||
}
|
||||
//Already made.
|
||||
else
|
||||
{
|
||||
return Instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
18
Assets/FirstGearGames/Utilities/DDOL.cs.meta
Normal file
18
Assets/FirstGearGames/Utilities/DDOL.cs.meta
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b66878174ece2f4f983390755507db7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 162991
|
||||
packageName: Smooth Camera Shaker
|
||||
packageVersion: 2.12
|
||||
assetPath: Assets/FirstGearGames/Utilities/DDOL.cs
|
||||
uploadId: 376379
|
||||
8
Assets/FirstGearGames/Utilities/Editor.meta
Normal file
8
Assets/FirstGearGames/Utilities/Editor.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32702bf1940665648ba38a2baa5231ab
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
72
Assets/FirstGearGames/Utilities/Editor/DrawBitMaskField.cs
Normal file
72
Assets/FirstGearGames/Utilities/Editor/DrawBitMaskField.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace FirstGearGames.Utilities.Editors
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// SOURCE: https://answers.unity.com/questions/1477896/assign-enum-value-from-editorguienumflagsfield.html
|
||||
/// </summary>
|
||||
public static class EditorExtension
|
||||
{
|
||||
public static int DrawBitMaskField(Rect aPosition, int aMask, System.Type aType, GUIContent aLabel)
|
||||
{
|
||||
var itemNames = System.Enum.GetNames(aType);
|
||||
var itemValues = System.Enum.GetValues(aType) as int[];
|
||||
|
||||
int val = aMask;
|
||||
int maskVal = 0;
|
||||
for (int i = 0; i < itemValues.Length; i++)
|
||||
{
|
||||
if (itemValues[i] != 0)
|
||||
{
|
||||
if ((val & itemValues[i]) == itemValues[i])
|
||||
maskVal |= 1 << i;
|
||||
}
|
||||
else if (val == 0)
|
||||
maskVal |= 1 << i;
|
||||
}
|
||||
int newMaskVal = EditorGUI.MaskField(aPosition, aLabel, maskVal, itemNames);
|
||||
int changes = maskVal ^ newMaskVal;
|
||||
|
||||
for (int i = 0; i < itemValues.Length; i++)
|
||||
{
|
||||
if ((changes & (1 << i)) != 0)
|
||||
{
|
||||
if ((newMaskVal & (1 << i)) != 0)
|
||||
{
|
||||
if (itemValues[i] == 0)
|
||||
{
|
||||
val = 0;
|
||||
break;
|
||||
}
|
||||
else
|
||||
val |= itemValues[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
val &= ~itemValues[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
[CustomPropertyDrawer(typeof(BitMaskAttribute))]
|
||||
public class EnumBitMaskPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
var typeAttr = attribute as BitMaskAttribute;
|
||||
// Add the actual int value behind the field name
|
||||
label.text = label.text + " (" + prop.intValue + ")";
|
||||
prop.intValue = EditorExtension.DrawBitMaskField(position, prop.intValue, typeAttr.propType, label);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1aa5b3604b2806d43932a7c78d4d287d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 162991
|
||||
packageName: Smooth Camera Shaker
|
||||
packageVersion: 2.12
|
||||
assetPath: Assets/FirstGearGames/Utilities/Editor/DrawBitMaskField.cs
|
||||
uploadId: 376379
|
||||
8
Assets/FirstGearGames/Utilities/EditorRuntime.meta
Normal file
8
Assets/FirstGearGames/Utilities/EditorRuntime.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: efa114911b78df5489aa6f96288ac9ef
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace FirstGearGames.Utilities.Editors
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// SOURCE: https://answers.unity.com/questions/1477896/assign-enum-value-from-editorguienumflagsfield.html
|
||||
/// </summary>
|
||||
public class BitMaskAttribute : PropertyAttribute
|
||||
{
|
||||
public System.Type propType;
|
||||
public BitMaskAttribute(System.Type aType)
|
||||
{
|
||||
propType = aType;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d29005cecd48ddc4a9017c0db498d576
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 162991
|
||||
packageName: Smooth Camera Shaker
|
||||
packageVersion: 2.12
|
||||
assetPath: Assets/FirstGearGames/Utilities/EditorRuntime/BitMaskAttribute.cs
|
||||
uploadId: 376379
|
||||
109
Assets/FirstGearGames/Utilities/Enums.cs
Normal file
109
Assets/FirstGearGames/Utilities/Enums.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using System;
|
||||
|
||||
namespace FirstGearGames.Utilities.Maths
|
||||
{
|
||||
|
||||
|
||||
public static class Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// Determine an enum value from a given string. This can be an expensive function.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="text">Text of string.</param>
|
||||
/// <param name="defaultValue">Default value if enum couldn't be found.</param>
|
||||
/// <returns>Enum found or default value if no enum is found.</returns>
|
||||
public static T FromString<T>(string text, T defaultValue)
|
||||
{
|
||||
//If string is empty or null return default value.
|
||||
if (string.IsNullOrEmpty(text))
|
||||
return defaultValue;
|
||||
//If enum isn't defined return default value.
|
||||
if (!Enum.IsDefined(typeof(T), (string)text))
|
||||
return defaultValue;
|
||||
//Return parsed value.
|
||||
return (T)Enum.Parse(typeof(T), text, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns if whole(extended enum) has any of the part values.
|
||||
/// </summary>
|
||||
/// <param name="whole"></param>
|
||||
/// <param name="part">Values to check for within whole.</param>
|
||||
/// <returns>Returns true part is within whole.</returns>
|
||||
public static bool Contains(this Enum whole, Enum part)
|
||||
{
|
||||
//If not the same type of Enum return false.
|
||||
/* Commented out for performance. Designer
|
||||
* should know better than to compare two different
|
||||
* enums. */
|
||||
//if (!SameType(value, target))
|
||||
// return false;
|
||||
|
||||
/* Convert enum values to ulong. With so few
|
||||
* values a uint would be safe, but should
|
||||
* the options expand ulong is safer. */
|
||||
ulong wholeNum = Convert.ToUInt64(whole);
|
||||
ulong partNum = Convert.ToUInt64(part);
|
||||
|
||||
return ((wholeNum & partNum) != 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns if part values contains any of whole(extended enum).
|
||||
/// </summary>
|
||||
/// <param name="whole"></param>
|
||||
/// <param name="part"></param>
|
||||
/// <returns>Returns true whole is within part.</returns>
|
||||
public static bool ReverseContains(this Enum whole, Enum part)
|
||||
{
|
||||
//If not the same type of Enum return false.
|
||||
/* Commented out for performance. Designer
|
||||
* should know better than to compare two different
|
||||
* enums. */
|
||||
//if (!SameType(value, target))
|
||||
// return false;
|
||||
|
||||
/* Convert enum values to ulong. With so few
|
||||
* values a uint would be safe, but should
|
||||
* the options expand ulong is safer. */
|
||||
ulong wholeNum = Convert.ToUInt64(whole);
|
||||
ulong partNum = Convert.ToUInt64(part);
|
||||
|
||||
return ((partNum & wholeNum) != 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns if an enum equals a specified value.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="target"></param>
|
||||
/// <returns></returns>
|
||||
public static bool Equals(this Enum value, Enum target)
|
||||
{
|
||||
//If not the same type of Enum return false.
|
||||
/* Commented out for performance. Designer
|
||||
* should know better than to compare two different
|
||||
* enums. */
|
||||
//if (!SameType(value, target))
|
||||
// return false;
|
||||
|
||||
ulong valueNum = Convert.ToUInt64(value);
|
||||
ulong wholeNum = Convert.ToUInt64(target);
|
||||
|
||||
return (valueNum == wholeNum);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns if a is the same Enum as b.
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
/// <param name="target"></param>
|
||||
/// <returns></returns>
|
||||
public static bool SameType(Enum a, Enum b)
|
||||
{
|
||||
return (a.GetType() == b.GetType());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
18
Assets/FirstGearGames/Utilities/Enums.cs.meta
Normal file
18
Assets/FirstGearGames/Utilities/Enums.cs.meta
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1bc10a70cf690dd47bcb3173f30d3d3a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 162991
|
||||
packageName: Smooth Camera Shaker
|
||||
packageVersion: 2.12
|
||||
assetPath: Assets/FirstGearGames/Utilities/Enums.cs
|
||||
uploadId: 376379
|
||||
132
Assets/FirstGearGames/Utilities/Floats.cs
Normal file
132
Assets/FirstGearGames/Utilities/Floats.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace FirstGearGames.Utilities.Maths
|
||||
{
|
||||
|
||||
|
||||
public static class Floats
|
||||
{
|
||||
private static System.Random _random = new System.Random();
|
||||
|
||||
/// <summary>
|
||||
/// Provides a random inclusive int within a given range. Preferred over Unity's Random to eliminate confusion as Unity uses inclusive for floats max, and exclusive for int max.
|
||||
/// </summary>
|
||||
/// <param name="minimum">Inclusive minimum value.</param>
|
||||
/// <param name="maximum">Inclusive maximum value.</param>
|
||||
/// <returns></returns>
|
||||
public static float RandomInclusiveRange(float minimum, float maximum)
|
||||
{
|
||||
double min = Convert.ToDouble(minimum);
|
||||
double max = Convert.ToDouble(maximum);
|
||||
|
||||
double result = (_random.NextDouble() * (max - min)) + min;
|
||||
return Convert.ToSingle(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a random float between 0f and 1f.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static float Random01()
|
||||
{
|
||||
return RandomInclusiveRange(0f, 1f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns if a target float is within variance of the source float.
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
/// <param name="b"></param>
|
||||
/// <param name="tolerance"></param>
|
||||
public static bool Near(this float a, float b, float tolerance = 0.01f)
|
||||
{
|
||||
return (Mathf.Abs(a - b) <= tolerance);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clamps a float and returns if the float required clamping.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="min"></param>
|
||||
/// <param name="max"></param>
|
||||
/// <param name="clamped"></param>
|
||||
/// <returns></returns>
|
||||
public static float Clamp(float value, float min, float max, ref bool clamped)
|
||||
{
|
||||
clamped = (value < min);
|
||||
if (clamped)
|
||||
return min;
|
||||
|
||||
clamped = (value > min);
|
||||
if (clamped)
|
||||
return max;
|
||||
|
||||
clamped = false;
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a float after being adjusted by the specified variance.
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="variance"></param>
|
||||
/// <returns></returns>
|
||||
public static float Variance(this float source, float variance)
|
||||
{
|
||||
float pickedVariance = RandomInclusiveRange(1f - variance, 1f + variance);
|
||||
return (source * pickedVariance);
|
||||
}
|
||||
/// <summary>
|
||||
/// Sets a float value to result after being adjusted by the specified variance.
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="variance"></param>
|
||||
/// <returns></returns>
|
||||
public static void Variance(this float source, float variance, ref float result)
|
||||
{
|
||||
float pickedVariance = RandomInclusiveRange(1f - variance, 1f + variance);
|
||||
result = (source * pickedVariance);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns negative-one, zero, or postive-one of a value instead of just negative-one or positive-one.
|
||||
/// </summary>
|
||||
/// <param name="value">Value to sign.</param>
|
||||
/// <returns>Precise sign.</returns>
|
||||
public static float PreciseSign(float value)
|
||||
{
|
||||
if (value == 0f)
|
||||
return 0f;
|
||||
else
|
||||
return (Mathf.Sign(value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns if a float is within a range.
|
||||
/// </summary>
|
||||
/// <param name="source">Value of float.</param>
|
||||
/// <param name="rangeMin">Minimum of range.</param>
|
||||
/// <param name="rangeMax">Maximum of range.</param>
|
||||
/// <returns></returns>
|
||||
public static bool InRange(this float source, float rangeMin, float rangeMax)
|
||||
{
|
||||
return (source >= rangeMin && source <= rangeMax);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Randomly flips a float value.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static float RandomlyFlip(float value)
|
||||
{
|
||||
if (Ints.RandomInclusiveRange(0, 1) == 0)
|
||||
return value;
|
||||
else
|
||||
return (value *= -1f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
18
Assets/FirstGearGames/Utilities/Floats.cs.meta
Normal file
18
Assets/FirstGearGames/Utilities/Floats.cs.meta
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5dbacafb14b963b419b64fb35a8add7c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 162991
|
||||
packageName: Smooth Camera Shaker
|
||||
packageVersion: 2.12
|
||||
assetPath: Assets/FirstGearGames/Utilities/Floats.cs
|
||||
uploadId: 376379
|
||||
70
Assets/FirstGearGames/Utilities/FrameRateCalculator.cs
Normal file
70
Assets/FirstGearGames/Utilities/FrameRateCalculator.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace FirstGearGames.Utilities.Maths
|
||||
{
|
||||
|
||||
public class FrameRateCalculator
|
||||
{
|
||||
#region Private.
|
||||
/// <summary>
|
||||
/// Time used to generate Frames.
|
||||
/// </summary>
|
||||
private float _timePassed = 0f;
|
||||
/// <summary>
|
||||
/// Frames performed in TimePassed. Float is used to reduce casting.
|
||||
/// </summary>
|
||||
private float _frames = 0;
|
||||
#endregion
|
||||
|
||||
#region Const.
|
||||
/// <summary>
|
||||
/// How many frames to pass before slicing calculation values.
|
||||
/// </summary>
|
||||
private const int RESET_FRAME_COUNT = 60;
|
||||
/// <summary>
|
||||
/// Percentage to slice calculation values by. Higher percentages result in smoother frame rate adjustments.
|
||||
/// </summary>
|
||||
private const float CALCULATION_SLICE_PERCENT = 0.7f;
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current frame rate.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int GetIntFrameRate()
|
||||
{
|
||||
return Mathf.CeilToInt((_frames / _timePassed));
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the current frame rate.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public float GetFloatFrameRate()
|
||||
{
|
||||
return (_frames / _timePassed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates frame count and time passed.
|
||||
/// </summary>
|
||||
/// <returns>True if this update hit reset frame.</returns>
|
||||
public bool Update(float unscaledDeltaTime)
|
||||
{
|
||||
_timePassed += unscaledDeltaTime;
|
||||
_frames++;
|
||||
|
||||
if (_frames > RESET_FRAME_COUNT)
|
||||
{
|
||||
_frames *= CALCULATION_SLICE_PERCENT;
|
||||
_timePassed *= CALCULATION_SLICE_PERCENT;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
18
Assets/FirstGearGames/Utilities/FrameRateCalculator.cs.meta
Normal file
18
Assets/FirstGearGames/Utilities/FrameRateCalculator.cs.meta
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e46d803097ca61e408d44faa9aa1893a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 162991
|
||||
packageName: Smooth Camera Shaker
|
||||
packageVersion: 2.12
|
||||
assetPath: Assets/FirstGearGames/Utilities/FrameRateCalculator.cs
|
||||
uploadId: 376379
|
||||
91
Assets/FirstGearGames/Utilities/Ints.cs
Normal file
91
Assets/FirstGearGames/Utilities/Ints.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace FirstGearGames.Utilities.Maths
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Various utility classes relating to floats.
|
||||
/// </summary>
|
||||
public static class Ints
|
||||
{
|
||||
private static System.Random _random = new System.Random();
|
||||
|
||||
/// <summary>
|
||||
/// Pads an index a specified value. Preferred over typical padding so that pad values used with skins can be easily found in the code.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="padding"></param>
|
||||
/// <returns></returns>
|
||||
public static string PadInt(int value, int padding)
|
||||
{
|
||||
return value.ToString().PadLeft(padding, '0');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides a random inclusive int within a given range. Preferred over Unity's Random to eliminate confusion as Unity uses inclusive for floats max, and exclusive for int max.
|
||||
/// </summary>
|
||||
/// <param name="minimum">Inclusive minimum value.</param>
|
||||
/// <param name="maximum">Inclusive maximum value.</param>
|
||||
/// <returns></returns>
|
||||
public static int RandomInclusiveRange(int minimum, int maximum)
|
||||
{
|
||||
return _random.Next(minimum, maximum + 1);
|
||||
}
|
||||
/// <summary>
|
||||
/// Provides a random exclusive int within a given range. Preferred over Unity's Random to eliminate confusion as Unity uses inclusive for floats max, and exclusive for int max.
|
||||
/// </summary>
|
||||
/// <param name="minimum">Inclusive minimum value.</param>
|
||||
/// <param name="maximum">Exclusive maximum value.</param>
|
||||
/// <returns></returns>
|
||||
public static int RandomExclusiveRange(int minimum, int maximum)
|
||||
{
|
||||
return _random.Next(minimum, maximum);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a clamped int within a specified range.
|
||||
/// </summary>
|
||||
/// <param name="value">Value to clamp.</param>
|
||||
/// <param name="minimum">Minimum value.</param>
|
||||
/// <param name="maximum">Maximum value.</param>
|
||||
/// <returns></returns>
|
||||
public static int Clamp(int value, int minimum, int maximum)
|
||||
{
|
||||
if (value < minimum)
|
||||
value = minimum;
|
||||
else if (value > maximum)
|
||||
value = maximum;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determins if all values passed in are the same.
|
||||
/// </summary>
|
||||
/// <param name="values">Values to check.</param>
|
||||
/// <returns>True if all values are the same.</returns>
|
||||
public static bool ValuesMatch(params int[] values)
|
||||
{
|
||||
if (values.Length == 0)
|
||||
{
|
||||
Debug.Log("Ints -> ValuesMatch -> values array is empty.");
|
||||
return false;
|
||||
}
|
||||
|
||||
//Assign first value as element in first array.
|
||||
int firstValue = values[0];
|
||||
//Check all values.
|
||||
for (int i = 1; i < values.Length; i++)
|
||||
{
|
||||
//If any value doesn't match first value return false.
|
||||
if (firstValue != values[i])
|
||||
return false;
|
||||
}
|
||||
|
||||
//If this far all values match.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
18
Assets/FirstGearGames/Utilities/Ints.cs.meta
Normal file
18
Assets/FirstGearGames/Utilities/Ints.cs.meta
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 113d58f1d7d39544aaf7101fee558070
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 162991
|
||||
packageName: Smooth Camera Shaker
|
||||
packageVersion: 2.12
|
||||
assetPath: Assets/FirstGearGames/Utilities/Ints.cs
|
||||
uploadId: 376379
|
||||
8
Assets/FirstGearGames/Utilities/Structures.meta
Normal file
8
Assets/FirstGearGames/Utilities/Structures.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0177a3ecaa12e4540886356516893275
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Assets/FirstGearGames/Utilities/Structures/RangeFloat.cs
Normal file
35
Assets/FirstGearGames/Utilities/Structures/RangeFloat.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using FirstGearGames.Utilities.Maths;
|
||||
|
||||
namespace FirstGearGames.Utilities.Structures
|
||||
{
|
||||
|
||||
|
||||
[System.Serializable]
|
||||
public struct FloatRange
|
||||
{
|
||||
public FloatRange(float minimum, float maximum)
|
||||
{
|
||||
Minimum = minimum;
|
||||
Maximum = maximum;
|
||||
}
|
||||
/// <summary>
|
||||
/// Minimum range.
|
||||
/// </summary>
|
||||
public float Minimum;
|
||||
/// <summary>
|
||||
/// Maximum range.
|
||||
/// </summary>
|
||||
public float Maximum;
|
||||
|
||||
/// <summary>
|
||||
/// Returns a random value between Minimum and Maximum.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public float RandomInclusive()
|
||||
{
|
||||
return Floats.RandomInclusiveRange(Minimum, Maximum);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a29ab16c2faf95a4e912b7bf31c39a7f
|
||||
timeCreated: 1527199791
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 162991
|
||||
packageName: Smooth Camera Shaker
|
||||
packageVersion: 2.12
|
||||
assetPath: Assets/FirstGearGames/Utilities/Structures/RangeFloat.cs
|
||||
uploadId: 376379
|
||||
43
Assets/FirstGearGames/Utilities/Structures/RangeInt.cs
Normal file
43
Assets/FirstGearGames/Utilities/Structures/RangeInt.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using FirstGearGames.Utilities.Maths;
|
||||
|
||||
namespace FirstGearGames.Utilities.Structures
|
||||
{
|
||||
|
||||
|
||||
[System.Serializable]
|
||||
public struct IntRange
|
||||
{
|
||||
public IntRange(int minimum, int maximum)
|
||||
{
|
||||
Minimum = minimum;
|
||||
Maximum = maximum;
|
||||
}
|
||||
/// <summary>
|
||||
/// Minimum range.
|
||||
/// </summary>
|
||||
public int Minimum;
|
||||
/// <summary>
|
||||
/// Maximum range.
|
||||
/// </summary>
|
||||
public int Maximum;
|
||||
|
||||
/// <summary>
|
||||
/// Returns an exclusive random value between Minimum and Maximum.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public float RandomExclusive()
|
||||
{
|
||||
return Ints.RandomExclusiveRange(Minimum, Maximum);
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns an inclusive random value between Minimum and Maximum.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public float RandomInclusive()
|
||||
{
|
||||
return Ints.RandomInclusiveRange(Minimum, Maximum);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
20
Assets/FirstGearGames/Utilities/Structures/RangeInt.cs.meta
Normal file
20
Assets/FirstGearGames/Utilities/Structures/RangeInt.cs.meta
Normal file
@@ -0,0 +1,20 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 42b78623511ca6b479a865feddd442b4
|
||||
timeCreated: 1527199791
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 162991
|
||||
packageName: Smooth Camera Shaker
|
||||
packageVersion: 2.12
|
||||
assetPath: Assets/FirstGearGames/Utilities/Structures/RangeInt.cs
|
||||
uploadId: 376379
|
||||
75
Assets/FirstGearGames/Utilities/Transforms.cs
Normal file
75
Assets/FirstGearGames/Utilities/Transforms.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace FirstGearGames.Utilities.Objects
|
||||
{
|
||||
|
||||
public static class Transforms
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the topmost parent for a transform.
|
||||
/// </summary>
|
||||
/// <param name="t"></param>
|
||||
/// <returns></returns>
|
||||
public static Transform TopmostParent(this Transform t)
|
||||
{
|
||||
if (t.parent == null)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
else
|
||||
{
|
||||
Transform result = t.parent;
|
||||
while (result.parent != null)
|
||||
result = result.parent;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Destroys all children under the specified transform.
|
||||
/// </summary>
|
||||
/// <param name="t"></param>
|
||||
public static void DestroyChildren(this Transform t, bool destroyImmediately = false)
|
||||
{
|
||||
foreach (Transform child in t)
|
||||
{
|
||||
if (destroyImmediately)
|
||||
MonoBehaviour.DestroyImmediate(child.gameObject);
|
||||
else
|
||||
MonoBehaviour.Destroy(child.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets components in children and optionally parent.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="results"></param>
|
||||
/// <param name="parent"></param>
|
||||
/// <param name="includeParent"></param>
|
||||
/// <param name="includeInactive"></param>
|
||||
public static void GetComponentsInChildren<T>(Transform parent, List<T> results, bool includeParent = true, bool includeInactive = false) where T : Component
|
||||
{
|
||||
if (!includeParent)
|
||||
{
|
||||
List<T> current = new List<T>();
|
||||
for (int i = 0; i < parent.childCount; i++)
|
||||
{
|
||||
parent.GetChild(i).GetComponentsInChildren(includeInactive, current);
|
||||
results.AddRange(current);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
parent.GetComponentsInChildren(includeInactive, results);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
18
Assets/FirstGearGames/Utilities/Transforms.cs.meta
Normal file
18
Assets/FirstGearGames/Utilities/Transforms.cs.meta
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd1cd9a8be59cc542983ed59c3e220ac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 162991
|
||||
packageName: Smooth Camera Shaker
|
||||
packageVersion: 2.12
|
||||
assetPath: Assets/FirstGearGames/Utilities/Transforms.cs
|
||||
uploadId: 376379
|
||||
138
Assets/FirstGearGames/Utilities/Vectors.cs
Normal file
138
Assets/FirstGearGames/Utilities/Vectors.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace FirstGearGames.Utilities.Maths
|
||||
{
|
||||
|
||||
public static class Vectors
|
||||
{
|
||||
#region Vector3.
|
||||
/// <summary>
|
||||
/// Calculates the linear parameter t that produces the interpolant value within the range [a, b].
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
/// <param name="b"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static float InverseLerp(Vector3 a, Vector3 b, Vector3 value)
|
||||
{
|
||||
Vector3 ab = b - a;
|
||||
Vector3 av = value - a;
|
||||
return Mathf.Clamp01(Vector3.Dot(av, ab) / Vector3.Dot(ab, ab));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns if the target Vector3 is within variance of the source Vector3.
|
||||
/// </summary>
|
||||
/// <param name="a">Source vector.</param>
|
||||
/// <param name="b">Target vector.</param>
|
||||
/// <param name="tolerance">How close the target vector must be to be considered close.</param>
|
||||
/// <returns></returns>
|
||||
public static bool Near(this Vector3 a, Vector3 b, float tolerance = 0.01f)
|
||||
{
|
||||
return (Vector3.Distance(a, b) <= tolerance);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns if any values within a Vector3 are NaN.
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsNan(this Vector3 source)
|
||||
{
|
||||
return (float.IsNaN(source.x) || float.IsNaN(source.y) || float.IsNaN(source.z));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lerp between three Vector3 values.
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
/// <param name="b"></param>
|
||||
/// <param name="c"></param>
|
||||
/// <param name="percent"></param>
|
||||
/// <returns></returns>
|
||||
public static Vector3 Lerp3(Vector3 a, Vector3 b, Vector3 c, float percent)
|
||||
{
|
||||
Vector3 r0 = Vector3.Lerp(a, b, percent);
|
||||
Vector3 r1 = Vector3.Lerp(b, c, percent);
|
||||
return Vector3.Lerp(r0, r1, percent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lerp between three Vector3 values.
|
||||
/// </summary>
|
||||
/// <param name="vectors"></param>
|
||||
/// <param name="percent"></param>
|
||||
/// <returns></returns>
|
||||
public static Vector3 Lerp3(Vector3[] vectors, float percent)
|
||||
{
|
||||
if (vectors.Length < 3)
|
||||
{
|
||||
Debug.LogWarning("Vectors -> Lerp3 -> Vectors length must be 3.");
|
||||
return Vector3.zero;
|
||||
}
|
||||
|
||||
return Lerp3(vectors[0], vectors[1], vectors[2], percent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies a Vector3 by another.
|
||||
/// </summary>
|
||||
/// <param name="src"></param>
|
||||
/// <param name="multiplier"></param>
|
||||
/// <returns></returns>
|
||||
public static Vector3 Multiply(this Vector3 src, Vector3 multiplier)
|
||||
{
|
||||
return new Vector3(src.x * multiplier.x, src.y * multiplier.y, src.z * multiplier.z);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Vector2.
|
||||
|
||||
/// <summary>
|
||||
/// Lerp between three Vector2 values.
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
/// <param name="b"></param>
|
||||
/// <param name="c"></param>
|
||||
/// <param name="percent"></param>
|
||||
/// <returns></returns>
|
||||
public static Vector2 Lerp3(Vector2 a, Vector2 b, Vector2 c, float percent)
|
||||
{
|
||||
Vector2 r0 = Vector2.Lerp(a, b, percent);
|
||||
Vector2 r1 = Vector2.Lerp(b, c, percent);
|
||||
return Vector2.Lerp(r0, r1, percent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lerp between three Vector2 values.
|
||||
/// </summary>
|
||||
/// <param name="vectors"></param>
|
||||
/// <param name="percent"></param>
|
||||
/// <returns></returns>
|
||||
public static Vector2 Lerp2(Vector2[] vectors, float percent)
|
||||
{
|
||||
if (vectors.Length < 3)
|
||||
{
|
||||
Debug.LogWarning("Vectors -> Lerp3 -> Vectors length must be 3.");
|
||||
return Vector2.zero;
|
||||
}
|
||||
|
||||
return Lerp3(vectors[0], vectors[1], vectors[2], percent);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies a Vector2 by another.
|
||||
/// </summary>
|
||||
/// <param name="src"></param>
|
||||
/// <param name="multiplier"></param>
|
||||
/// <returns></returns>
|
||||
public static Vector2 Multiply(this Vector2 src, Vector2 multiplier)
|
||||
{
|
||||
return new Vector2(src.x * multiplier.x, src.y * multiplier.y);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
18
Assets/FirstGearGames/Utilities/Vectors.cs.meta
Normal file
18
Assets/FirstGearGames/Utilities/Vectors.cs.meta
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 16a2a79e3d8834044963e588c63af3e7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 162991
|
||||
packageName: Smooth Camera Shaker
|
||||
packageVersion: 2.12
|
||||
assetPath: Assets/FirstGearGames/Utilities/Vectors.cs
|
||||
uploadId: 376379
|
||||
Reference in New Issue
Block a user