mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交Unity 联机Pro
This commit is contained in:
63
JNFrame2/Assets/Plugins/SRF/Scripts/Helpers/AssetUtil.cs
Normal file
63
JNFrame2/Assets/Plugins/SRF/Scripts/Helpers/AssetUtil.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
|
||||
#endif
|
||||
|
||||
namespace SRF.Helpers
|
||||
{
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
public static class AssetUtil
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
|
||||
// This makes it easy to create, name and place unique new ScriptableObject asset files.
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public static T CreateAsset<T>() where T : ScriptableObject
|
||||
{
|
||||
var path = AssetDatabase.GetAssetPath(Selection.activeObject);
|
||||
|
||||
if (path == "")
|
||||
{
|
||||
path = "Assets";
|
||||
}
|
||||
else if (Path.GetExtension(path) != "")
|
||||
{
|
||||
path = path.Replace(Path.GetFileName(path), "");
|
||||
}
|
||||
|
||||
return CreateAsset<T>(path, "New " + typeof (T).Name);
|
||||
}
|
||||
|
||||
public static T CreateAsset<T>(string path, string name) where T : ScriptableObject
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
path = "Assets";
|
||||
}
|
||||
|
||||
if (!name.EndsWith(".asset"))
|
||||
{
|
||||
name += ".asset";
|
||||
}
|
||||
|
||||
var assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/" + name);
|
||||
|
||||
var asset = ScriptableObject.CreateInstance<T>();
|
||||
AssetDatabase.CreateAsset(asset, assetPathAndName);
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
return asset;
|
||||
}
|
||||
|
||||
public static void SelectAssetInProjectView(Object asset)
|
||||
{
|
||||
EditorUtility.FocusProjectWindow();
|
||||
Selection.activeObject = asset;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de28cc9633260c54a9ba062b7ad82e63
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
73
JNFrame2/Assets/Plugins/SRF/Scripts/Helpers/Hierarchy.cs
Normal file
73
JNFrame2/Assets/Plugins/SRF/Scripts/Helpers/Hierarchy.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
namespace SRF
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class Hierarchy
|
||||
{
|
||||
private static readonly char[] Seperator = {'/'};
|
||||
private static readonly Dictionary<string, Transform> Cache = new Dictionary<string, Transform>();
|
||||
|
||||
[Obsolete("Use static Get() instead")]
|
||||
public Transform this[string key]
|
||||
{
|
||||
get { return Get(key); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pass in a path (e.g. /Test/Me/One) and get a transform with the hierarchy Test->Me->One.
|
||||
/// Any Transforms required below this path will be auto-created.
|
||||
/// This is a very slow method, so use only on initialisation.
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public static Transform Get(string key)
|
||||
{
|
||||
Transform t;
|
||||
|
||||
// Check cache
|
||||
if (Cache.TryGetValue(key, out t))
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
var find = GameObject.Find(key);
|
||||
|
||||
if (find)
|
||||
{
|
||||
t = find.transform;
|
||||
Cache.Add(key, t);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
// Find container parent
|
||||
var elements = key.Split(Seperator, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
// Create new container
|
||||
t = new GameObject(elements.Last()).transform;
|
||||
Cache.Add(key, t);
|
||||
|
||||
// If root
|
||||
if (elements.Length == 1)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
t.parent = Get(string.Join("/", elements, 0, elements.Length - 1));
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
#if (!UNITY_2017 && !UNITY_2018 && !UNITY_2019) || UNITY_2019_3_OR_NEWER
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
public static void RuntimeInitialize()
|
||||
{
|
||||
// To handle entering play mode without a domain reload, need to reset the state of the service manager.
|
||||
Cache.Clear();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ecf392c4c08d14543b90300c27422d60
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
namespace SRF.Helpers
|
||||
{
|
||||
using System.Reflection;
|
||||
|
||||
public sealed class MethodReference
|
||||
{
|
||||
private readonly Func<object[], object> _method;
|
||||
|
||||
public MethodReference(object target, MethodInfo method)
|
||||
{
|
||||
SRDebugUtil.AssertNotNull(target);
|
||||
|
||||
_method = o => method.Invoke(target, o);
|
||||
}
|
||||
|
||||
public MethodReference(Func<object[], object> method)
|
||||
{
|
||||
_method = method;
|
||||
}
|
||||
|
||||
public object Invoke(object[] parameters)
|
||||
{
|
||||
return _method.Invoke(parameters);
|
||||
}
|
||||
|
||||
public static implicit operator MethodReference(Action action)
|
||||
{
|
||||
return new MethodReference(args =>
|
||||
{
|
||||
action();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ed7f46979ff4b3418a838a6b940a9ab
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
208
JNFrame2/Assets/Plugins/SRF/Scripts/Helpers/PropertyReference.cs
Normal file
208
JNFrame2/Assets/Plugins/SRF/Scripts/Helpers/PropertyReference.cs
Normal file
@@ -0,0 +1,208 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using JetBrains.Annotations;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SRF.Helpers
|
||||
{
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
public delegate void PropertyValueChangedHandler(PropertyReference property);
|
||||
|
||||
public sealed class PropertyReference
|
||||
{
|
||||
public event PropertyValueChangedHandler ValueChanged
|
||||
{
|
||||
add
|
||||
{
|
||||
if (_valueChangedListeners == null)
|
||||
{
|
||||
_valueChangedListeners = new List<PropertyValueChangedHandler>();
|
||||
}
|
||||
|
||||
_valueChangedListeners.Add(value);
|
||||
if (_valueChangedListeners.Count == 1 && _target is INotifyPropertyChanged)
|
||||
{
|
||||
// Subscribe to value changed event on target.
|
||||
((INotifyPropertyChanged)_target).PropertyChanged += OnTargetPropertyChanged;
|
||||
}
|
||||
}
|
||||
|
||||
remove
|
||||
{
|
||||
if (_valueChangedListeners == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_valueChangedListeners.Remove(value) && _valueChangedListeners.Count == 0 &&
|
||||
_target is INotifyPropertyChanged)
|
||||
{
|
||||
// Unsubscribe from value changed event on target.
|
||||
((INotifyPropertyChanged) _target).PropertyChanged -= OnTargetPropertyChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[CanBeNull] private readonly PropertyInfo _property;
|
||||
[CanBeNull] private readonly object _target;
|
||||
|
||||
[CanBeNull] private readonly Attribute[] _attributes;
|
||||
|
||||
[CanBeNull] private readonly Func<object> _getter;
|
||||
|
||||
[CanBeNull] private readonly Action<object> _setter;
|
||||
|
||||
[CanBeNull] private List<PropertyValueChangedHandler> _valueChangedListeners;
|
||||
|
||||
|
||||
public static PropertyReference FromLambda<T>(Func<T> getter, Action<T> setter = null, params Attribute[] attributes)
|
||||
{
|
||||
Action<object> internalSetter = null;
|
||||
if (setter != null)
|
||||
{
|
||||
internalSetter = o => setter((T)o);
|
||||
}
|
||||
return new PropertyReference(typeof(T), () => getter(), internalSetter, attributes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a property reference from an object target and reflection PropertyInfo.
|
||||
/// This represents a property on an object.
|
||||
/// </summary>
|
||||
public PropertyReference(object target, PropertyInfo property)
|
||||
{
|
||||
SRDebugUtil.AssertNotNull(target);
|
||||
SRDebugUtil.AssertNotNull(property);
|
||||
|
||||
PropertyType = property.PropertyType;
|
||||
_property = property;
|
||||
_target = target;
|
||||
|
||||
#if NETFX_CORE
|
||||
if(_property.GetMethod != null && _property.GetMethod.IsPublic)
|
||||
#else
|
||||
if (property.GetGetMethod() != null)
|
||||
#endif
|
||||
{
|
||||
_getter = () => SRReflection.GetPropertyValue(target, property);
|
||||
}
|
||||
|
||||
|
||||
#if NETFX_CORE
|
||||
if(_property.SetMethod != null && _property.SetMethod.IsPublic)
|
||||
#else
|
||||
if (property.GetSetMethod() != null)
|
||||
#endif
|
||||
{
|
||||
_setter = (v) => SRReflection.SetPropertyValue(target, property, v);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a property reference from lambdas. This has no underlying reflection or object associated with it.
|
||||
/// </summary>
|
||||
public PropertyReference(Type type, Func<object> getter = null, Action<object> setter = null, Attribute[] attributes = null)
|
||||
{
|
||||
SRDebugUtil.AssertNotNull(type);
|
||||
|
||||
PropertyType = type;
|
||||
_attributes = attributes;
|
||||
_getter = getter;
|
||||
_setter = setter;
|
||||
}
|
||||
|
||||
public Type PropertyType { get; private set; }
|
||||
|
||||
public bool CanRead
|
||||
{
|
||||
get
|
||||
{
|
||||
return _getter != null;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanWrite
|
||||
{
|
||||
get
|
||||
{
|
||||
return _setter != null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Notify any listeners to <see cref="ValueChanged"/> that the value has been updated.
|
||||
/// </summary>
|
||||
public void NotifyValueChanged()
|
||||
{
|
||||
if (_valueChangedListeners == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var handler in _valueChangedListeners)
|
||||
{
|
||||
handler(this);
|
||||
}
|
||||
}
|
||||
|
||||
public object GetValue()
|
||||
{
|
||||
if (_getter != null)
|
||||
{
|
||||
return _getter();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetValue(object value)
|
||||
{
|
||||
if (_setter != null)
|
||||
{
|
||||
_setter(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("Can not write to property");
|
||||
}
|
||||
}
|
||||
|
||||
public T GetAttribute<T>() where T : Attribute
|
||||
{
|
||||
if (_attributes != null)
|
||||
{
|
||||
return _attributes.FirstOrDefault(p => p is T) as T;
|
||||
}
|
||||
|
||||
if (_property != null)
|
||||
{
|
||||
return _property.GetCustomAttributes(typeof(T), true).FirstOrDefault() as T;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
private void OnTargetPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (_valueChangedListeners == null || _valueChangedListeners.Count == 0)
|
||||
{
|
||||
Debug.LogWarning("[PropertyReference] Received property value changed event when there are no listeners. Did the event not get unsubscribed correctly?");
|
||||
return;
|
||||
}
|
||||
|
||||
NotifyValueChanged();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (_property != null)
|
||||
{
|
||||
return "{0}.{1}".Fmt(_property.DeclaringType.Name, _property.Name);
|
||||
}
|
||||
|
||||
return "<delegate>";
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dedbd84f93f7d4c4e86f2d3a238916c4
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
64
JNFrame2/Assets/Plugins/SRF/Scripts/Helpers/SRDebugUtil.cs
Normal file
64
JNFrame2/Assets/Plugins/SRF/Scripts/Helpers/SRDebugUtil.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using SRF;
|
||||
using UnityEngine;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
public static class SRDebugUtil
|
||||
{
|
||||
public const int LineBufferCount = 512;
|
||||
public static bool IsFixedUpdate { get; set; }
|
||||
|
||||
[DebuggerNonUserCode]
|
||||
[DebuggerStepThrough]
|
||||
public static void AssertNotNull(object value, string message = null, MonoBehaviour instance = null)
|
||||
{
|
||||
if (!EqualityComparer<object>.Default.Equals(value, null))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
message = message != null ? "NotNullAssert Failed: {0}".Fmt(message) : "Assert Failed";
|
||||
|
||||
Debug.LogError(message, instance);
|
||||
|
||||
if (instance != null)
|
||||
{
|
||||
instance.enabled = false;
|
||||
}
|
||||
|
||||
throw new NullReferenceException(message);
|
||||
}
|
||||
|
||||
[DebuggerNonUserCode]
|
||||
[DebuggerStepThrough]
|
||||
public static void Assert(bool condition, string message = null, MonoBehaviour instance = null)
|
||||
{
|
||||
if (condition)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
message = message != null ? "Assert Failed: {0}".Fmt(message) : "Assert Failed";
|
||||
|
||||
Debug.LogError(message, instance);
|
||||
throw new Exception(message);
|
||||
}
|
||||
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
[DebuggerNonUserCode]
|
||||
[DebuggerStepThrough]
|
||||
public static void EditorAssertNotNull(object value, string message = null, MonoBehaviour instance = null)
|
||||
{
|
||||
AssertNotNull(value, message, instance);
|
||||
}
|
||||
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
[DebuggerNonUserCode]
|
||||
[DebuggerStepThrough]
|
||||
public static void EditorAssert(bool condition, string message = null, MonoBehaviour instance = null)
|
||||
{
|
||||
Assert(condition, message, instance);
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f74f500c46d2b60419e95b8bd0cb87b6
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
73
JNFrame2/Assets/Plugins/SRF/Scripts/Helpers/SRFileUtil.cs
Normal file
73
JNFrame2/Assets/Plugins/SRF/Scripts/Helpers/SRFileUtil.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
public static class SRFileUtil
|
||||
{
|
||||
#if !UNITY_WEBPLAYER && !NETFX_CORE
|
||||
|
||||
public static void DeleteDirectory(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.Delete(path, true);
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
Thread.Sleep(0);
|
||||
Directory.Delete(path, true);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Returns the human-readable file size for an arbitrary, 64-bit file size
|
||||
/// The default format is "0.### XB", e.g. "4.2 KB" or "1.434 GB"
|
||||
/// </summary>
|
||||
/// <param name="i"></param>
|
||||
/// <remarks>http://stackoverflow.com/a/281684/147003</remarks>
|
||||
/// <returns></returns>
|
||||
public static string GetBytesReadable(long i)
|
||||
{
|
||||
var sign = (i < 0 ? "-" : "");
|
||||
double readable = (i < 0 ? -i : i);
|
||||
string suffix;
|
||||
if (i >= 0x1000000000000000) // Exabyte
|
||||
{
|
||||
suffix = "EB";
|
||||
readable = i >> 50;
|
||||
}
|
||||
else if (i >= 0x4000000000000) // Petabyte
|
||||
{
|
||||
suffix = "PB";
|
||||
readable = i >> 40;
|
||||
}
|
||||
else if (i >= 0x10000000000) // Terabyte
|
||||
{
|
||||
suffix = "TB";
|
||||
readable = i >> 30;
|
||||
}
|
||||
else if (i >= 0x40000000) // Gigabyte
|
||||
{
|
||||
suffix = "GB";
|
||||
readable = i >> 20;
|
||||
}
|
||||
else if (i >= 0x100000) // Megabyte
|
||||
{
|
||||
suffix = "MB";
|
||||
readable = i >> 10;
|
||||
}
|
||||
else if (i >= 0x400) // Kilobyte
|
||||
{
|
||||
suffix = "KB";
|
||||
readable = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
return i.ToString(sign + "0 B"); // Byte
|
||||
}
|
||||
readable /= 1024;
|
||||
|
||||
return sign + readable.ToString("0.### ") + suffix;
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c5dd64a3a7854e4f948daaec7d318fa
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
19
JNFrame2/Assets/Plugins/SRF/Scripts/Helpers/SRInstantiate.cs
Normal file
19
JNFrame2/Assets/Plugins/SRF/Scripts/Helpers/SRInstantiate.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
|
||||
public static class SRInstantiate
|
||||
{
|
||||
public static T Instantiate<T>(T prefab) where T : Component
|
||||
{
|
||||
return (T) Object.Instantiate(prefab);
|
||||
}
|
||||
|
||||
public static GameObject Instantiate(GameObject prefab)
|
||||
{
|
||||
return (GameObject) Object.Instantiate(prefab);
|
||||
}
|
||||
|
||||
public static T Instantiate<T>(T prefab, Vector3 position, Quaternion rotation) where T : Component
|
||||
{
|
||||
return (T) Object.Instantiate(prefab, position, rotation);
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b2502558f76a9a4b9d3fd4d26d4d2a6
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
@@ -0,0 +1,788 @@
|
||||
using UnityEngine;
|
||||
|
||||
public static partial class SRMath
|
||||
{
|
||||
/**
|
||||
*
|
||||
* These tweening functions taken from https://wpf-animation.googlecode.com/svn/trunk/src/WPF/Animation/PennerDoubleAnimation.cs
|
||||
* Licensed under the new BSD License
|
||||
*
|
||||
* @author Darren David darren-code@lookorfeel.com
|
||||
* @version 1.0
|
||||
*
|
||||
* Credit/Thanks:
|
||||
* Robert Penner - The easing equations we all know and love
|
||||
* (http://robertpenner.com/easing/) [See License.txt for license info]
|
||||
*
|
||||
* Lee Brimelow - initial port of Penner's equations to WPF
|
||||
* (http://thewpfblog.com/?p=12)
|
||||
*
|
||||
* Zeh Fernando - additional equations (out/in) from
|
||||
* caurina.transitions.Tweener (http://code.google.com/p/tweener/)
|
||||
* [See License.txt for license info]
|
||||
*
|
||||
*/
|
||||
|
||||
private static class TweenFunctions
|
||||
{
|
||||
#region Equations
|
||||
|
||||
#region Linear
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a simple linear tweening, with no easing.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float Linear(float t, float b, float c, float d)
|
||||
{
|
||||
return c*t/d + b;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Expo
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for an exponential (2^t) easing out:
|
||||
/// decelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float ExpoEaseOut(float t, float b, float c, float d)
|
||||
{
|
||||
return (t == d) ? b + c : c*(-Mathf.Pow(2, -10*t/d) + 1) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for an exponential (2^t) easing in:
|
||||
/// accelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float ExpoEaseIn(float t, float b, float c, float d)
|
||||
{
|
||||
return (t == 0) ? b : c*Mathf.Pow(2, 10*(t/d - 1)) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for an exponential (2^t) easing in/out:
|
||||
/// acceleration until halfway, then deceleration.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float ExpoEaseInOut(float t, float b, float c, float d)
|
||||
{
|
||||
if (t == 0)
|
||||
{
|
||||
return b;
|
||||
}
|
||||
|
||||
if (t == d)
|
||||
{
|
||||
return b + c;
|
||||
}
|
||||
|
||||
if ((t /= d/2) < 1)
|
||||
{
|
||||
return c/2*Mathf.Pow(2, 10*(t - 1)) + b;
|
||||
}
|
||||
|
||||
return c/2*(-Mathf.Pow(2, -10*--t) + 2) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for an exponential (2^t) easing out/in:
|
||||
/// deceleration until halfway, then acceleration.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float ExpoEaseOutIn(float t, float b, float c, float d)
|
||||
{
|
||||
if (t < d/2)
|
||||
{
|
||||
return ExpoEaseOut(t*2, b, c/2, d);
|
||||
}
|
||||
|
||||
return ExpoEaseIn((t*2) - d, b + c/2, c/2, d);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Circular
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a circular (sqrt(1-t^2)) easing out:
|
||||
/// decelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float CircEaseOut(float t, float b, float c, float d)
|
||||
{
|
||||
return c*Mathf.Sqrt(1 - (t = t/d - 1)*t) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a circular (sqrt(1-t^2)) easing in:
|
||||
/// accelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float CircEaseIn(float t, float b, float c, float d)
|
||||
{
|
||||
return -c*(Mathf.Sqrt(1 - (t /= d)*t) - 1) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a circular (sqrt(1-t^2)) easing in/out:
|
||||
/// acceleration until halfway, then deceleration.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float CircEaseInOut(float t, float b, float c, float d)
|
||||
{
|
||||
if ((t /= d/2) < 1)
|
||||
{
|
||||
return -c/2*(Mathf.Sqrt(1 - t*t) - 1) + b;
|
||||
}
|
||||
|
||||
return c/2*(Mathf.Sqrt(1 - (t -= 2)*t) + 1) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a circular (sqrt(1-t^2)) easing in/out:
|
||||
/// acceleration until halfway, then deceleration.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float CircEaseOutIn(float t, float b, float c, float d)
|
||||
{
|
||||
if (t < d/2)
|
||||
{
|
||||
return CircEaseOut(t*2, b, c/2, d);
|
||||
}
|
||||
|
||||
return CircEaseIn((t*2) - d, b + c/2, c/2, d);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Quad
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a quadratic (t^2) easing out:
|
||||
/// decelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float QuadEaseOut(float t, float b, float c, float d)
|
||||
{
|
||||
return -c*(t /= d)*(t - 2) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a quadratic (t^2) easing in:
|
||||
/// accelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float QuadEaseIn(float t, float b, float c, float d)
|
||||
{
|
||||
return c*(t /= d)*t + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a quadratic (t^2) easing in/out:
|
||||
/// acceleration until halfway, then deceleration.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float QuadEaseInOut(float t, float b, float c, float d)
|
||||
{
|
||||
if ((t /= d/2) < 1)
|
||||
{
|
||||
return c/2*t*t + b;
|
||||
}
|
||||
|
||||
return -c/2*((--t)*(t - 2) - 1) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a quadratic (t^2) easing out/in:
|
||||
/// deceleration until halfway, then acceleration.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float QuadEaseOutIn(float t, float b, float c, float d)
|
||||
{
|
||||
if (t < d/2)
|
||||
{
|
||||
return QuadEaseOut(t*2, b, c/2, d);
|
||||
}
|
||||
|
||||
return QuadEaseIn((t*2) - d, b + c/2, c/2, d);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Sine
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a sinusoidal (sin(t)) easing out:
|
||||
/// decelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float SineEaseOut(float t, float b, float c, float d)
|
||||
{
|
||||
return c*Mathf.Sin(t/d*(Mathf.PI/2)) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a sinusoidal (sin(t)) easing in:
|
||||
/// accelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float SineEaseIn(float t, float b, float c, float d)
|
||||
{
|
||||
return -c*Mathf.Cos(t/d*(Mathf.PI/2)) + c + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a sinusoidal (sin(t)) easing in/out:
|
||||
/// acceleration until halfway, then deceleration.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float SineEaseInOut(float t, float b, float c, float d)
|
||||
{
|
||||
if ((t /= d/2) < 1)
|
||||
{
|
||||
return c/2*(Mathf.Sin(Mathf.PI*t/2)) + b;
|
||||
}
|
||||
|
||||
return -c/2*(Mathf.Cos(Mathf.PI*--t/2) - 2) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a sinusoidal (sin(t)) easing in/out:
|
||||
/// deceleration until halfway, then acceleration.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float SineEaseOutIn(float t, float b, float c, float d)
|
||||
{
|
||||
if (t < d/2)
|
||||
{
|
||||
return SineEaseOut(t*2, b, c/2, d);
|
||||
}
|
||||
|
||||
return SineEaseIn((t*2) - d, b + c/2, c/2, d);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cubic
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a cubic (t^3) easing out:
|
||||
/// decelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float CubicEaseOut(float t, float b, float c, float d)
|
||||
{
|
||||
return c*((t = t/d - 1)*t*t + 1) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a cubic (t^3) easing in:
|
||||
/// accelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float CubicEaseIn(float t, float b, float c, float d)
|
||||
{
|
||||
return c*(t /= d)*t*t + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a cubic (t^3) easing in/out:
|
||||
/// acceleration until halfway, then deceleration.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float CubicEaseInOut(float t, float b, float c, float d)
|
||||
{
|
||||
if ((t /= d/2) < 1)
|
||||
{
|
||||
return c/2*t*t*t + b;
|
||||
}
|
||||
|
||||
return c/2*((t -= 2)*t*t + 2) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a cubic (t^3) easing out/in:
|
||||
/// deceleration until halfway, then acceleration.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float CubicEaseOutIn(float t, float b, float c, float d)
|
||||
{
|
||||
if (t < d/2)
|
||||
{
|
||||
return CubicEaseOut(t*2, b, c/2, d);
|
||||
}
|
||||
|
||||
return CubicEaseIn((t*2) - d, b + c/2, c/2, d);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Quartic
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a quartic (t^4) easing out:
|
||||
/// decelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float QuartEaseOut(float t, float b, float c, float d)
|
||||
{
|
||||
return -c*((t = t/d - 1)*t*t*t - 1) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a quartic (t^4) easing in:
|
||||
/// accelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float QuartEaseIn(float t, float b, float c, float d)
|
||||
{
|
||||
return c*(t /= d)*t*t*t + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a quartic (t^4) easing in/out:
|
||||
/// acceleration until halfway, then deceleration.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float QuartEaseInOut(float t, float b, float c, float d)
|
||||
{
|
||||
if ((t /= d/2) < 1)
|
||||
{
|
||||
return c/2*t*t*t*t + b;
|
||||
}
|
||||
|
||||
return -c/2*((t -= 2)*t*t*t - 2) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a quartic (t^4) easing out/in:
|
||||
/// deceleration until halfway, then acceleration.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float QuartEaseOutIn(float t, float b, float c, float d)
|
||||
{
|
||||
if (t < d/2)
|
||||
{
|
||||
return QuartEaseOut(t*2, b, c/2, d);
|
||||
}
|
||||
|
||||
return QuartEaseIn((t*2) - d, b + c/2, c/2, d);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Quintic
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a quintic (t^5) easing out:
|
||||
/// decelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float QuintEaseOut(float t, float b, float c, float d)
|
||||
{
|
||||
return c*((t = t/d - 1)*t*t*t*t + 1) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a quintic (t^5) easing in:
|
||||
/// accelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float QuintEaseIn(float t, float b, float c, float d)
|
||||
{
|
||||
return c*(t /= d)*t*t*t*t + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a quintic (t^5) easing in/out:
|
||||
/// acceleration until halfway, then deceleration.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float QuintEaseInOut(float t, float b, float c, float d)
|
||||
{
|
||||
if ((t /= d/2) < 1)
|
||||
{
|
||||
return c/2*t*t*t*t*t + b;
|
||||
}
|
||||
return c/2*((t -= 2)*t*t*t*t + 2) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a quintic (t^5) easing in/out:
|
||||
/// acceleration until halfway, then deceleration.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float QuintEaseOutIn(float t, float b, float c, float d)
|
||||
{
|
||||
if (t < d/2)
|
||||
{
|
||||
return QuintEaseOut(t*2, b, c/2, d);
|
||||
}
|
||||
return QuintEaseIn((t*2) - d, b + c/2, c/2, d);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Elastic
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for an elastic (exponentially decaying sine wave) easing out:
|
||||
/// decelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float ElasticEaseOut(float t, float b, float c, float d)
|
||||
{
|
||||
if ((t /= d) == 1)
|
||||
{
|
||||
return b + c;
|
||||
}
|
||||
|
||||
var p = d*.3f;
|
||||
var s = p/4;
|
||||
|
||||
return (c*Mathf.Pow(2, -10*t)*Mathf.Sin((t*d - s)*(2*Mathf.PI)/p) + c + b);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for an elastic (exponentially decaying sine wave) easing in:
|
||||
/// accelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float ElasticEaseIn(float t, float b, float c, float d)
|
||||
{
|
||||
if ((t /= d) == 1)
|
||||
{
|
||||
return b + c;
|
||||
}
|
||||
|
||||
var p = d*.3f;
|
||||
var s = p/4;
|
||||
|
||||
return -(c*Mathf.Pow(2, 10*(t -= 1))*Mathf.Sin((t*d - s)*(2*Mathf.PI)/p)) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for an elastic (exponentially decaying sine wave) easing in/out:
|
||||
/// acceleration until halfway, then deceleration.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float ElasticEaseInOut(float t, float b, float c, float d)
|
||||
{
|
||||
if ((t /= d/2) == 2)
|
||||
{
|
||||
return b + c;
|
||||
}
|
||||
|
||||
var p = d*(.3f*1.5f);
|
||||
var s = p/4;
|
||||
|
||||
if (t < 1)
|
||||
{
|
||||
return -.5f*(c*Mathf.Pow(2, 10*(t -= 1))*Mathf.Sin((t*d - s)*(2*Mathf.PI)/p)) + b;
|
||||
}
|
||||
return c*Mathf.Pow(2, -10*(t -= 1))*Mathf.Sin((t*d - s)*(2*Mathf.PI)/p)*.5f + c + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for an elastic (exponentially decaying sine wave) easing out/in:
|
||||
/// deceleration until halfway, then acceleration.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float ElasticEaseOutIn(float t, float b, float c, float d)
|
||||
{
|
||||
if (t < d/2)
|
||||
{
|
||||
return ElasticEaseOut(t*2, b, c/2, d);
|
||||
}
|
||||
return ElasticEaseIn((t*2) - d, b + c/2, c/2, d);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Bounce
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out:
|
||||
/// decelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float BounceEaseOut(float t, float b, float c, float d)
|
||||
{
|
||||
if ((t /= d) < (1/2.75f))
|
||||
{
|
||||
return c*(7.5625f*t*t) + b;
|
||||
}
|
||||
if (t < (2/2.75))
|
||||
{
|
||||
return c*(7.5625f*(t -= (1.5f/2.75f))*t + .75f) + b;
|
||||
}
|
||||
if (t < (2.5/2.75))
|
||||
{
|
||||
return c*(7.5625f*(t -= (2.25f/2.75f))*t + .9375f) + b;
|
||||
}
|
||||
return c*(7.5625f*(t -= (2.625f/2.75f))*t + .984375f) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in:
|
||||
/// accelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float BounceEaseIn(float t, float b, float c, float d)
|
||||
{
|
||||
return c - BounceEaseOut(d - t, 0, c, d) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in/out:
|
||||
/// acceleration until halfway, then deceleration.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float BounceEaseInOut(float t, float b, float c, float d)
|
||||
{
|
||||
if (t < d/2)
|
||||
{
|
||||
return BounceEaseIn(t*2, 0, c, d)*.5f + b;
|
||||
}
|
||||
return BounceEaseOut(t*2 - d, 0, c, d)*.5f + c*.5f + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out/in:
|
||||
/// deceleration until halfway, then acceleration.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float BounceEaseOutIn(float t, float b, float c, float d)
|
||||
{
|
||||
if (t < d/2)
|
||||
{
|
||||
return BounceEaseOut(t*2, b, c/2, d);
|
||||
}
|
||||
return BounceEaseIn((t*2) - d, b + c/2, c/2, d);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Back
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out:
|
||||
/// decelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float BackEaseOut(float t, float b, float c, float d)
|
||||
{
|
||||
return c*((t = t/d - 1)*t*((1.70158f + 1)*t + 1.70158f) + 1) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in:
|
||||
/// accelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float BackEaseIn(float t, float b, float c, float d)
|
||||
{
|
||||
return c*(t /= d)*t*((1.70158f + 1)*t - 1.70158f) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in/out:
|
||||
/// acceleration until halfway, then deceleration.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float BackEaseInOut(float t, float b, float c, float d)
|
||||
{
|
||||
var s = 1.70158f;
|
||||
if ((t /= d/2) < 1)
|
||||
{
|
||||
return c/2*(t*t*(((s *= (1.525f)) + 1)*t - s)) + b;
|
||||
}
|
||||
return c/2*((t -= 2)*t*(((s *= (1.525f)) + 1)*t + s) + 2) + b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in:
|
||||
/// deceleration until halfway, then acceleration.
|
||||
/// </summary>
|
||||
/// <param name="t">Current time in seconds.</param>
|
||||
/// <param name="b">Starting value.</param>
|
||||
/// <param name="c">Final value.</param>
|
||||
/// <param name="d">Duration of animation.</param>
|
||||
/// <returns>The correct value.</returns>
|
||||
public static float BackEaseOutIn(float t, float b, float c, float d)
|
||||
{
|
||||
if (t < d/2)
|
||||
{
|
||||
return BackEaseOut(t*2, b, c/2, d);
|
||||
}
|
||||
return BackEaseIn((t*2) - d, b + c/2, c/2, d);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0be6d36a29af844fa2d7584d66b374c
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
209
JNFrame2/Assets/Plugins/SRF/Scripts/Helpers/SRMath.Tweening.cs
Normal file
209
JNFrame2/Assets/Plugins/SRF/Scripts/Helpers/SRMath.Tweening.cs
Normal file
@@ -0,0 +1,209 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public static partial class SRMath
|
||||
{
|
||||
public enum EaseType
|
||||
{
|
||||
Linear,
|
||||
QuadEaseOut,
|
||||
QuadEaseIn,
|
||||
QuadEaseInOut,
|
||||
QuadEaseOutIn,
|
||||
ExpoEaseOut,
|
||||
ExpoEaseIn,
|
||||
ExpoEaseInOut,
|
||||
ExpoEaseOutIn,
|
||||
CubicEaseOut,
|
||||
CubicEaseIn,
|
||||
CubicEaseInOut,
|
||||
CubicEaseOutIn,
|
||||
QuartEaseOut,
|
||||
QuartEaseIn,
|
||||
QuartEaseInOut,
|
||||
QuartEaseOutIn,
|
||||
QuintEaseOut,
|
||||
QuintEaseIn,
|
||||
QuintEaseInOut,
|
||||
QuintEaseOutIn,
|
||||
CircEaseOut,
|
||||
CircEaseIn,
|
||||
CircEaseInOut,
|
||||
CircEaseOutIn,
|
||||
SineEaseOut,
|
||||
SineEaseIn,
|
||||
SineEaseInOut,
|
||||
SineEaseOutIn,
|
||||
ElasticEaseOut,
|
||||
ElasticEaseIn,
|
||||
ElasticEaseInOut,
|
||||
ElasticEaseOutIn,
|
||||
BounceEaseOut,
|
||||
BounceEaseIn,
|
||||
BounceEaseInOut,
|
||||
BounceEaseOutIn,
|
||||
BackEaseOut,
|
||||
BackEaseIn,
|
||||
BackEaseInOut,
|
||||
BackEaseOutIn
|
||||
}
|
||||
|
||||
public static float Ease(float from, float to, float t, EaseType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case EaseType.Linear:
|
||||
return TweenFunctions.Linear(t, from, to, 1f);
|
||||
case EaseType.QuadEaseOut:
|
||||
return TweenFunctions.QuadEaseOut(t, from, to, 1f);
|
||||
case EaseType.QuadEaseIn:
|
||||
return TweenFunctions.QuadEaseIn(t, from, to, 1f);
|
||||
case EaseType.QuadEaseInOut:
|
||||
return TweenFunctions.QuadEaseInOut(t, from, to, 1f);
|
||||
case EaseType.QuadEaseOutIn:
|
||||
return TweenFunctions.QuadEaseOutIn(t, from, to, 1f);
|
||||
case EaseType.ExpoEaseOut:
|
||||
return TweenFunctions.ExpoEaseOut(t, from, to, 1f);
|
||||
case EaseType.ExpoEaseIn:
|
||||
return TweenFunctions.ExpoEaseIn(t, from, to, 1f);
|
||||
case EaseType.ExpoEaseInOut:
|
||||
return TweenFunctions.ExpoEaseInOut(t, from, to, 1f);
|
||||
case EaseType.ExpoEaseOutIn:
|
||||
return TweenFunctions.ExpoEaseOutIn(t, from, to, 1f);
|
||||
case EaseType.CubicEaseOut:
|
||||
return TweenFunctions.CubicEaseOut(t, from, to, 1f);
|
||||
case EaseType.CubicEaseIn:
|
||||
return TweenFunctions.CubicEaseIn(t, from, to, 1f);
|
||||
case EaseType.CubicEaseInOut:
|
||||
return TweenFunctions.CubicEaseInOut(t, from, to, 1f);
|
||||
case EaseType.CubicEaseOutIn:
|
||||
return TweenFunctions.CubicEaseOutIn(t, from, to, 1f);
|
||||
case EaseType.QuartEaseOut:
|
||||
return TweenFunctions.QuartEaseOut(t, from, to, 1f);
|
||||
case EaseType.QuartEaseIn:
|
||||
return TweenFunctions.QuartEaseIn(t, from, to, 1f);
|
||||
case EaseType.QuartEaseInOut:
|
||||
return TweenFunctions.QuartEaseInOut(t, from, to, 1f);
|
||||
case EaseType.QuartEaseOutIn:
|
||||
return TweenFunctions.QuartEaseOutIn(t, from, to, 1f);
|
||||
case EaseType.QuintEaseOut:
|
||||
return TweenFunctions.QuintEaseOut(t, from, to, 1f);
|
||||
case EaseType.QuintEaseIn:
|
||||
return TweenFunctions.QuintEaseIn(t, from, to, 1f);
|
||||
case EaseType.QuintEaseInOut:
|
||||
return TweenFunctions.QuintEaseInOut(t, from, to, 1f);
|
||||
case EaseType.QuintEaseOutIn:
|
||||
return TweenFunctions.QuintEaseOutIn(t, from, to, 1f);
|
||||
case EaseType.CircEaseOut:
|
||||
return TweenFunctions.CircEaseOut(t, from, to, 1f);
|
||||
case EaseType.CircEaseIn:
|
||||
return TweenFunctions.CircEaseIn(t, from, to, 1f);
|
||||
case EaseType.CircEaseInOut:
|
||||
return TweenFunctions.CircEaseInOut(t, from, to, 1f);
|
||||
case EaseType.CircEaseOutIn:
|
||||
return TweenFunctions.CircEaseOutIn(t, from, to, 1f);
|
||||
case EaseType.SineEaseOut:
|
||||
return TweenFunctions.SineEaseOut(t, from, to, 1f);
|
||||
case EaseType.SineEaseIn:
|
||||
return TweenFunctions.SineEaseIn(t, from, to, 1f);
|
||||
case EaseType.SineEaseInOut:
|
||||
return TweenFunctions.SineEaseInOut(t, from, to, 1f);
|
||||
case EaseType.SineEaseOutIn:
|
||||
return TweenFunctions.SineEaseOutIn(t, from, to, 1f);
|
||||
case EaseType.ElasticEaseOut:
|
||||
return TweenFunctions.ElasticEaseOut(t, from, to, 1f);
|
||||
case EaseType.ElasticEaseIn:
|
||||
return TweenFunctions.ElasticEaseIn(t, from, to, 1f);
|
||||
case EaseType.ElasticEaseInOut:
|
||||
return TweenFunctions.ElasticEaseInOut(t, from, to, 1f);
|
||||
case EaseType.ElasticEaseOutIn:
|
||||
return TweenFunctions.ElasticEaseOutIn(t, from, to, 1f);
|
||||
case EaseType.BounceEaseOut:
|
||||
return TweenFunctions.BounceEaseOut(t, from, to, 1f);
|
||||
case EaseType.BounceEaseIn:
|
||||
return TweenFunctions.BounceEaseIn(t, from, to, 1f);
|
||||
case EaseType.BounceEaseInOut:
|
||||
return TweenFunctions.BounceEaseInOut(t, from, to, 1f);
|
||||
case EaseType.BounceEaseOutIn:
|
||||
return TweenFunctions.BounceEaseOutIn(t, from, to, 1f);
|
||||
case EaseType.BackEaseOut:
|
||||
return TweenFunctions.BackEaseOut(t, from, to, 1f);
|
||||
case EaseType.BackEaseIn:
|
||||
return TweenFunctions.BackEaseIn(t, from, to, 1f);
|
||||
case EaseType.BackEaseInOut:
|
||||
return TweenFunctions.BackEaseInOut(t, from, to, 1f);
|
||||
case EaseType.BackEaseOutIn:
|
||||
return TweenFunctions.BackEaseOutIn(t, from, to, 1f);
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException("type");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate a framerate-independent value to lerp by
|
||||
/// </summary>
|
||||
/// <param name="strength"></param>
|
||||
/// <param name="deltaTime"></param>
|
||||
/// <returns></returns>
|
||||
public static float SpringLerp(float strength, float deltaTime)
|
||||
{
|
||||
var ms = Mathf.RoundToInt(deltaTime*1000f);
|
||||
var step = 0.001f*strength;
|
||||
|
||||
var from = 0f;
|
||||
var to = 1f;
|
||||
|
||||
for (var i = 0; i < ms; i++)
|
||||
{
|
||||
from = Mathf.Lerp(from, to, step);
|
||||
}
|
||||
|
||||
return from;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A frame-rate independent way of doing Mathf.Lerp(from, to, Time.deltaTime * strength). Based on NGUIMath.SpringLerp
|
||||
/// </summary>
|
||||
/// <param name="from">Starting Value</param>
|
||||
/// <param name="to">End Value</param>
|
||||
/// <param name="strength">How fast the spring will complete</param>
|
||||
/// <param name="deltaTime">Pass in Time.deltaTime or RealTime.deltaTime</param>
|
||||
/// <returns>Interpolated value</returns>
|
||||
public static float SpringLerp(float from, float to, float strength, float deltaTime)
|
||||
{
|
||||
return Mathf.Lerp(from, to, SpringLerp(strength, deltaTime));
|
||||
}
|
||||
|
||||
public static Vector3 SpringLerp(Vector3 from, Vector3 to, float strength, float deltaTime)
|
||||
{
|
||||
return Vector3.Lerp(from, to, SpringLerp(strength, deltaTime));
|
||||
}
|
||||
|
||||
public static Quaternion SpringLerp(Quaternion from, Quaternion to, float strength, float deltaTime)
|
||||
{
|
||||
return Quaternion.Slerp(from, to, SpringLerp(strength, deltaTime));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Smoothly clamp value between 0 and max, smoothing between min and max
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="min"></param>
|
||||
/// <param name="max"></param>
|
||||
/// <param name="easeType"></param>
|
||||
/// <returns></returns>
|
||||
public static float SmoothClamp(float value, float min, float max, float scrollMax,
|
||||
EaseType easeType = EaseType.ExpoEaseOut)
|
||||
{
|
||||
if (value < min)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
var p = Mathf.Clamp01((value - min)/(scrollMax - min));
|
||||
|
||||
Debug.Log(p);
|
||||
|
||||
return Mathf.Clamp(min + Mathf.Lerp(value - min, max, Ease(0, 1f, p, easeType)), 0, max);
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 810c2c875ec6af345a04174ff5828880
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
151
JNFrame2/Assets/Plugins/SRF/Scripts/Helpers/SRMath.cs
Normal file
151
JNFrame2/Assets/Plugins/SRF/Scripts/Helpers/SRMath.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public static partial class SRMath
|
||||
{
|
||||
/// <summary>
|
||||
/// Lerp from one value to another, without clamping t to 0-1.
|
||||
/// </summary>
|
||||
/// <param name="from"></param>
|
||||
/// <param name="to"></param>
|
||||
/// <param name="t"></param>
|
||||
/// <returns></returns>
|
||||
public static float LerpUnclamped(float from, float to, float t)
|
||||
{
|
||||
return (1.0f - t)*from + t*to;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lerp from one vector to another, without clamping t
|
||||
/// </summary>
|
||||
/// <param name="from"></param>
|
||||
/// <param name="to"></param>
|
||||
/// <param name="t"></param>
|
||||
/// <returns></returns>
|
||||
public static Vector3 LerpUnclamped(Vector3 from, Vector3 to, float t)
|
||||
{
|
||||
return new Vector3(
|
||||
LerpUnclamped(from.x, to.x, t),
|
||||
LerpUnclamped(from.y, to.y, t),
|
||||
LerpUnclamped(from.z, to.z, t)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Value from 0.0f-1.0f, 0 when facing fully away and 1.0f when facing fully towards
|
||||
/// </summary>
|
||||
public static float FacingNormalized(Vector3 dir1, Vector3 dir2)
|
||||
{
|
||||
dir1.Normalize();
|
||||
dir2.Normalize();
|
||||
|
||||
return Mathf.InverseLerp(-1, 1, Vector3.Dot(dir1, dir2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reduces a given angle to a value between 180 and -180.
|
||||
/// </summary>
|
||||
/// <param name="angle">The angle to reduce, in radians.</param>
|
||||
/// <returns>The new angle, in radians.</returns>
|
||||
/// https://github.com/mono/MonoGame/blob/develop/MonoGame.Framework/MathHelper.cs
|
||||
public static float WrapAngle(float angle)
|
||||
{
|
||||
if (angle <= -180f)
|
||||
{
|
||||
angle += 360f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (angle > 180f)
|
||||
{
|
||||
angle -= 360f;
|
||||
}
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the angle closest to 'to'
|
||||
/// </summary>
|
||||
/// <param name="to"></param>
|
||||
/// <param name="angle1"></param>
|
||||
/// <param name="angle2"></param>
|
||||
/// <returns></returns>
|
||||
public static float NearestAngle(float to, float angle1, float angle2)
|
||||
{
|
||||
if (Mathf.Abs(Mathf.DeltaAngle(to, angle1)) > Mathf.Abs(Mathf.DeltaAngle(to, angle2)))
|
||||
{
|
||||
return angle2;
|
||||
}
|
||||
return angle1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrap value to 0-max (non-inclusive)
|
||||
/// </summary>
|
||||
/// <param name="max">Max value (non-inclusive)</param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns>Value wrapped from 0-max</returns>
|
||||
public static int Wrap(int max, int value)
|
||||
{
|
||||
if (max < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("max", "max must be greater than 0");
|
||||
}
|
||||
|
||||
while (value < 0)
|
||||
{
|
||||
value += max;
|
||||
}
|
||||
|
||||
while (value >= max)
|
||||
{
|
||||
value -= max;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrap value to 0-max (non-inclusive)
|
||||
/// </summary>
|
||||
/// <param name="max">Max value (non-inclusive)</param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns>Value wrapped from 0-max</returns>
|
||||
public static float Wrap(float max, float value)
|
||||
{
|
||||
while (value < 0)
|
||||
{
|
||||
value += max;
|
||||
}
|
||||
|
||||
while (value >= max)
|
||||
{
|
||||
value -= max;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static float Average(float v1, float v2)
|
||||
{
|
||||
return (v1 + v2)*0.5f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return an angle in range -180, 180 based on direction vector
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
public static float Angle(Vector2 direction)
|
||||
{
|
||||
var angle = Vector3.Angle(Vector3.up, direction);
|
||||
|
||||
if (Vector3.Cross(direction, Vector3.up).z > 0f)
|
||||
{
|
||||
angle *= -1;
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dc751da3d31975645847e0e4088ff560
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
46
JNFrame2/Assets/Plugins/SRF/Scripts/Helpers/SRReflection.cs
Normal file
46
JNFrame2/Assets/Plugins/SRF/Scripts/Helpers/SRReflection.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
namespace SRF.Helpers
|
||||
{
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
public static class SRReflection
|
||||
{
|
||||
public static void SetPropertyValue(object obj, PropertyInfo p, object value)
|
||||
{
|
||||
#if NETFX_CORE
|
||||
p.SetValue(obj, value, null);
|
||||
#else
|
||||
p.GetSetMethod().Invoke(obj, new[] {value});
|
||||
#endif
|
||||
}
|
||||
|
||||
public static object GetPropertyValue(object obj, PropertyInfo p)
|
||||
{
|
||||
#if NETFX_CORE
|
||||
return p.GetValue(obj, null);
|
||||
#else
|
||||
return p.GetGetMethod().Invoke(obj, null);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static T GetAttribute<T>(MemberInfo t) where T : Attribute
|
||||
{
|
||||
#if !NETFX_CORE
|
||||
return Attribute.GetCustomAttribute(t, typeof (T)) as T;
|
||||
#else
|
||||
return t.GetCustomAttribute(typeof (T), true) as T;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if NETFX_CORE
|
||||
|
||||
public static T GetAttribute<T>(Type t) where T : Attribute
|
||||
{
|
||||
|
||||
return GetAttribute<T>(t.GetTypeInfo());
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6aaf1b857713dd44a955633b6458f1c2
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
Reference in New Issue
Block a user