基础内容
必要插件安装 缓动曲线和动画基础 ElementFolder,Track与其次级模块,PathNode重构
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
using MoreMountains.Feedbacks;
|
||||
#if MM_TEXTMESHPRO
|
||||
using TMPro;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Feel
|
||||
{
|
||||
[AddComponentMenu("")]
|
||||
public class FeelSpringsAdvancedFloatDemo : MonoBehaviour
|
||||
{
|
||||
[Header("Bindings")]
|
||||
public MMSpringPosition PositionSpring;
|
||||
public MMSpringRotation RotationSpring;
|
||||
public MMSpringScale ScaleSpring;
|
||||
|
||||
public FeelSpringsDemoSlider PositionDampingSlider;
|
||||
public FeelSpringsDemoSlider PositionFrequencySlider;
|
||||
public FeelSpringsDemoSlider RotationDampingSlider;
|
||||
public FeelSpringsDemoSlider RotationFrequencySlider;
|
||||
public FeelSpringsDemoSlider ScaleDampingSlider;
|
||||
public FeelSpringsDemoSlider ScaleFrequencySlider;
|
||||
|
||||
|
||||
public FeelSpringsDemoSlider BumpAmountSlider;
|
||||
|
||||
public Transform MovingObject;
|
||||
|
||||
protected Vector3 _newPosition = Vector3.zero;
|
||||
protected Vector3 _newBump = Vector3.zero;
|
||||
protected float _range = 0.375f;
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
_newPosition = MovingObject.transform.localPosition;
|
||||
}
|
||||
|
||||
public virtual void RandomMove()
|
||||
{
|
||||
_newPosition.x = UnityEngine.Random.Range(-_range, _range);
|
||||
PositionSpring.MoveTo(_newPosition);
|
||||
ScaleSpring.BumpRandom();
|
||||
RotationSpring.BumpRandom();
|
||||
}
|
||||
|
||||
public virtual void RandomBump()
|
||||
{
|
||||
_newBump.x = 0f;
|
||||
_newBump.y = 0f;
|
||||
_newBump.z = 1000f * BumpAmountSlider.value;
|
||||
RotationSpring.Bump(_newBump);
|
||||
_newBump.x = 10f * BumpAmountSlider.value;
|
||||
_newBump.y = 10f * BumpAmountSlider.value;
|
||||
_newBump.z = 0f;
|
||||
ScaleSpring.Bump(_newBump);
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
PositionSpring.SpringVector3.SetDamping(PositionDampingSlider.value * Vector3.one);
|
||||
PositionSpring.SpringVector3.SetFrequency(PositionFrequencySlider.value * Vector3.one);
|
||||
|
||||
RotationSpring.SpringVector3.SetDamping(RotationDampingSlider.value * Vector3.one);
|
||||
RotationSpring.SpringVector3.SetFrequency(RotationFrequencySlider.value * Vector3.one);
|
||||
|
||||
ScaleSpring.SpringVector3.SetDamping(ScaleDampingSlider.value * Vector3.one);
|
||||
ScaleSpring.SpringVector3.SetFrequency(ScaleFrequencySlider.value * Vector3.one);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce29cd24982c2c84c8a611171d0af63a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,174 @@
|
||||
using MoreMountains.Feedbacks;
|
||||
using MoreMountains.Tools;
|
||||
#if MM_TEXTMESHPRO
|
||||
using TMPro;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
|
||||
using UnityEngine.InputSystem;
|
||||
#endif
|
||||
|
||||
namespace MoreMountains.Feel
|
||||
{
|
||||
[AddComponentMenu("")]
|
||||
public class FeelSpringsCellMovementDemo : MonoBehaviour
|
||||
{
|
||||
[Header("Spring")]
|
||||
public MMSpringPosition MovementSpring;
|
||||
public MMSpringRotation RotationSpring;
|
||||
public MMSpringScale ScaleSpring;
|
||||
|
||||
[Header("Bindings")]
|
||||
public FeelSpringsDemoSlider DampingSlider;
|
||||
public FeelSpringsDemoSlider FrequencySlider;
|
||||
public MMFeedbacks MoveFeedback;
|
||||
|
||||
protected Vector3 _newPosition;
|
||||
protected float _cellWidth = 0.125f;
|
||||
|
||||
protected enum Directions { Left, Right, Up, Down }
|
||||
|
||||
protected Vector2 _currentPosition;
|
||||
protected Vector3 _movementPosition;
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
UpdateSliderValues();
|
||||
HandleInput();
|
||||
}
|
||||
|
||||
public virtual void MoveRandomly()
|
||||
{
|
||||
int randomDirection = Random.Range(0, 4);
|
||||
Move((Directions)randomDirection);
|
||||
}
|
||||
|
||||
protected virtual void Move(Directions direction)
|
||||
{
|
||||
// we compute in _currentPosition the position we want to be in on the grid
|
||||
// _currentPosition is a Vector2, with x and y values ranging from -3 to 3,
|
||||
// representing the 7x7 grid we're moving on
|
||||
// so at the start, _currentPosition is (0,0), meaning we're in the middle of the grid
|
||||
// and if we were to move left, the new _currentPosition would be (-1,0), meaning we'd be one cell to the left
|
||||
ComputeNewGridPosition(direction);
|
||||
|
||||
// then we simply move the spring to the new position, by passing it the world position we want to move to
|
||||
// to get that world position, we multiply the current position by the cell width
|
||||
_movementPosition.x = _currentPosition.x * _cellWidth;
|
||||
_movementPosition.y = _currentPosition.y * _cellWidth;
|
||||
_movementPosition.z = MovementSpring.Target.transform.localPosition.z;
|
||||
// this is the only line required to have an object move using a spring in Feel :
|
||||
MovementSpring.MoveTo(_movementPosition);
|
||||
|
||||
ScaleSpring.Bump(5f * Vector3.one);
|
||||
MoveFeedback?.PlayFeedbacks();
|
||||
}
|
||||
|
||||
protected virtual void Bump(Directions direction)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case Directions.Left:
|
||||
RotationSpring.Bump(new Vector3(0f,0f,-900f));
|
||||
MovementSpring.Bump(new Vector3(4f,0f,0f));
|
||||
break;
|
||||
case Directions.Right:
|
||||
RotationSpring.Bump(new Vector3(0f,0f,900f));
|
||||
MovementSpring.Bump(new Vector3(-4f,0f,0f));
|
||||
break;
|
||||
case Directions.Up:
|
||||
RotationSpring.Bump(new Vector3(0f,0f,450f));
|
||||
MovementSpring.Bump(new Vector3(0f,-4f,0f));
|
||||
break;
|
||||
case Directions.Down:
|
||||
RotationSpring.Bump(new Vector3(0f,0f,-450f));
|
||||
MovementSpring.Bump(new Vector3(0f,4f,0f));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void ComputeNewGridPosition(Directions direction)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case Directions.Left:
|
||||
_currentPosition.x -= 1;
|
||||
break;
|
||||
case Directions.Right:
|
||||
_currentPosition.x += 1;
|
||||
break;
|
||||
case Directions.Up:
|
||||
_currentPosition.y += 1;
|
||||
break;
|
||||
case Directions.Down:
|
||||
_currentPosition.y -= 1;
|
||||
break;
|
||||
}
|
||||
if (_currentPosition.x < -3)
|
||||
{
|
||||
_currentPosition.x = -3;
|
||||
Bump(Directions.Left);
|
||||
return;
|
||||
}
|
||||
if (_currentPosition.x > 3)
|
||||
{
|
||||
_currentPosition.x = 3;
|
||||
Bump(Directions.Right);
|
||||
return;
|
||||
}
|
||||
if (_currentPosition.y < -3)
|
||||
{
|
||||
_currentPosition.y = -3;
|
||||
Bump(Directions.Down);
|
||||
return;
|
||||
}
|
||||
if (_currentPosition.y > 3)
|
||||
{
|
||||
_currentPosition.y = 3;
|
||||
Bump(Directions.Up);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void HandleInput()
|
||||
{
|
||||
bool input;
|
||||
|
||||
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
|
||||
input = Keyboard.current.leftArrowKey.wasPressedThisFrame;
|
||||
#else
|
||||
input = Input.GetKeyDown(KeyCode.LeftArrow);
|
||||
#endif
|
||||
if (input) { Move(Directions.Left); }
|
||||
|
||||
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
|
||||
input = Keyboard.current.rightArrowKey.wasPressedThisFrame;
|
||||
#else
|
||||
input = Input.GetKeyDown(KeyCode.RightArrow);
|
||||
#endif
|
||||
if (input) { Move(Directions.Right); }
|
||||
|
||||
|
||||
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
|
||||
input = Keyboard.current.downArrowKey.wasPressedThisFrame;
|
||||
#else
|
||||
input = Input.GetKeyDown(KeyCode.DownArrow);
|
||||
#endif
|
||||
if (input) { Move(Directions.Down); }
|
||||
|
||||
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
|
||||
input = Keyboard.current.upArrowKey.wasPressedThisFrame;
|
||||
#else
|
||||
input = Input.GetKeyDown(KeyCode.UpArrow);
|
||||
#endif
|
||||
if (input) { Move(Directions.Up); }
|
||||
}
|
||||
|
||||
protected virtual void UpdateSliderValues()
|
||||
{
|
||||
// bind the slider values to the springs
|
||||
MovementSpring.SpringVector3.SetDamping(DampingSlider.value * Vector3.one);
|
||||
MovementSpring.SpringVector3.SetFrequency(FrequencySlider.value * Vector3.one);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c90f68a1bea42f446a064e9d9ec5571c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,54 @@
|
||||
using System.Collections.Generic;
|
||||
using MoreMountains.Feedbacks;
|
||||
using MoreMountains.Tools;
|
||||
#if MM_TEXTMESHPRO
|
||||
using TMPro;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Feel
|
||||
{
|
||||
[AddComponentMenu("")]
|
||||
public class FeelSpringsComparisonDemo : MonoBehaviour
|
||||
{
|
||||
[Header("Spring")]
|
||||
public List<MMSpringFloat> Springs;
|
||||
public List<Transform> MovingObjects;
|
||||
public FeelSpringsDemoSlider BumpAmountSlider;
|
||||
|
||||
protected Vector3 _newPosition;
|
||||
|
||||
protected float _range = 0.375f;
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
foreach (MMSpringFloat spring in Springs)
|
||||
{
|
||||
spring.CurrentValue = 0f;
|
||||
spring.TargetValue = 0f;
|
||||
spring.Velocity = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void RandomBump()
|
||||
{
|
||||
float bumpAmount = BumpAmountSlider.value;
|
||||
foreach (MMSpringFloat spring in Springs)
|
||||
{
|
||||
spring.Bump(bumpAmount);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
for (int i = 0; i < Springs.Count; i++)
|
||||
{
|
||||
Springs[i].UpdateSpringValue(Time.deltaTime);
|
||||
|
||||
_newPosition = MovingObjects[i].transform.localPosition;
|
||||
_newPosition.x = MMMaths.Remap(Springs[i].CurrentValue, -1f, 1f, -_range, _range);
|
||||
MovingObjects[i].transform.localPosition = _newPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6e6269964a09f04b9bb2bd14aa0a979
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
using System.Collections.Generic;
|
||||
using MoreMountains.Tools;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Feel
|
||||
{
|
||||
[AddComponentMenu("")]
|
||||
public class FeelSpringsDemoManager : MonoBehaviour
|
||||
{
|
||||
[Header("Bindings")]
|
||||
public List<GameObject> DemoObjects;
|
||||
[MMReadOnly] public int CurrentIndex = 0;
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
EnableCurrentDemo();
|
||||
}
|
||||
|
||||
public virtual void NextDemo()
|
||||
{
|
||||
CurrentIndex++;
|
||||
if (CurrentIndex >= DemoObjects.Count)
|
||||
{
|
||||
CurrentIndex = 0;
|
||||
}
|
||||
EnableCurrentDemo();
|
||||
}
|
||||
|
||||
public virtual void PreviousDemo()
|
||||
{
|
||||
CurrentIndex--;
|
||||
if (CurrentIndex < 0)
|
||||
{
|
||||
CurrentIndex = DemoObjects.Count - 1;
|
||||
}
|
||||
EnableCurrentDemo();
|
||||
}
|
||||
|
||||
protected virtual void EnableCurrentDemo()
|
||||
{
|
||||
foreach (GameObject demoObject in DemoObjects)
|
||||
{
|
||||
demoObject.gameObject.SetActive(false);
|
||||
}
|
||||
DemoObjects[CurrentIndex].SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e289d5fe638bbb148aeffa7bad00c8a8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,35 @@
|
||||
#if MM_TEXTMESHPRO
|
||||
using TMPro;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
#if MM_UI
|
||||
using UnityEngine.UI;
|
||||
#endif
|
||||
|
||||
namespace MoreMountains.Feel
|
||||
{
|
||||
[AddComponentMenu("")]
|
||||
public class FeelSpringsDemoSlider : MonoBehaviour
|
||||
{
|
||||
#if MM_UI
|
||||
[Header("Bindings")]
|
||||
public Slider TargetSlider;
|
||||
#endif
|
||||
#if MM_TEXTMESHPRO
|
||||
public TMP_Text ValueText;
|
||||
#endif
|
||||
#if MM_UI
|
||||
public float value => TargetSlider.value;
|
||||
#else
|
||||
public float value => 0f;
|
||||
#endif
|
||||
|
||||
public void UpdateText()
|
||||
{
|
||||
#if MM_TEXTMESHPRO
|
||||
ValueText.text = TargetSlider.value.ToString("F2");
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 08305052b7211574c820ea6cf61cb10e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,55 @@
|
||||
using MoreMountains.Feedbacks;
|
||||
using MoreMountains.Tools;
|
||||
#if MM_TEXTMESHPRO
|
||||
using TMPro;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Feel
|
||||
{
|
||||
[AddComponentMenu("")]
|
||||
public class FeelSpringsFloatDemo : MonoBehaviour
|
||||
{
|
||||
[Header("Spring")]
|
||||
public MMSpringFloat FloatSpring;
|
||||
|
||||
[Header("Bindings")]
|
||||
public FeelSpringsDemoSlider DampingSlider;
|
||||
public FeelSpringsDemoSlider FrequencySlider;
|
||||
public FeelSpringsDemoSlider BumpAmountSlider;
|
||||
public Transform MovingObject;
|
||||
|
||||
protected Vector3 _newPosition;
|
||||
protected float _range = 0.375f;
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
FloatSpring.CurrentValue = 0f;
|
||||
FloatSpring.TargetValue = 0f;
|
||||
FloatSpring.Velocity = 0f;
|
||||
}
|
||||
|
||||
public virtual void RandomMove()
|
||||
{
|
||||
FloatSpring.MoveTo(UnityEngine.Random.Range(-1f,1f));
|
||||
}
|
||||
|
||||
public virtual void RandomBump()
|
||||
{
|
||||
float bumpAmount = BumpAmountSlider.value;
|
||||
FloatSpring.BumpRandom(-bumpAmount, bumpAmount);
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
FloatSpring.Damping = DampingSlider.value;
|
||||
FloatSpring.Frequency = FrequencySlider.value;
|
||||
FloatSpring.UpdateSpringValue(Time.deltaTime);
|
||||
|
||||
_newPosition = MovingObject.transform.localPosition;
|
||||
_newPosition.x = MMMaths.Remap(FloatSpring.CurrentValue, -1f, 1f, -_range, _range);
|
||||
|
||||
MovingObject.transform.localPosition = _newPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 953cc62ff9a889d4eb09cfcd48d81c2d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,68 @@
|
||||
using MoreMountains.Feedbacks;
|
||||
using MoreMountains.Tools;
|
||||
#if MM_TEXTMESHPRO
|
||||
using TMPro;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Feel
|
||||
{
|
||||
[AddComponentMenu("")]
|
||||
public class FeelSpringsVector2Demo : MonoBehaviour
|
||||
{
|
||||
[Header("Spring")]
|
||||
public MMSpringFloat SpringX;
|
||||
public MMSpringFloat SpringY;
|
||||
|
||||
[Header("Bindings")]
|
||||
public FeelSpringsDemoSlider DampingXSlider;
|
||||
public FeelSpringsDemoSlider FrequencyXSlider;
|
||||
public FeelSpringsDemoSlider DampingYSlider;
|
||||
public FeelSpringsDemoSlider FrequencyYSlider;
|
||||
public FeelSpringsDemoSlider BumpAmountSlider;
|
||||
public Transform MovingObject;
|
||||
|
||||
protected Vector3 _newPosition;
|
||||
protected float _range = 0.375f;
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
SpringX.CurrentValue = 0f;
|
||||
SpringX.TargetValue = 0f;
|
||||
SpringX.Velocity = 0f;
|
||||
SpringY.CurrentValue = 0f;
|
||||
SpringY.TargetValue = 0f;
|
||||
SpringY.Velocity = 0f;
|
||||
}
|
||||
|
||||
public virtual void RandomMove()
|
||||
{
|
||||
SpringX.MoveTo(UnityEngine.Random.Range(-1f,1f));
|
||||
SpringY.MoveTo(UnityEngine.Random.Range(-1f,1f));
|
||||
}
|
||||
|
||||
public virtual void RandomBump()
|
||||
{
|
||||
float bumpAmount = BumpAmountSlider.value;
|
||||
SpringX.BumpRandom(-bumpAmount, bumpAmount);
|
||||
SpringY.BumpRandom(-bumpAmount, bumpAmount);
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
SpringX.Damping = DampingXSlider.value;
|
||||
SpringY.Damping = DampingYSlider.value;
|
||||
SpringX.Frequency = FrequencyXSlider.value;
|
||||
SpringY.Frequency = FrequencyYSlider.value;
|
||||
SpringX.UpdateSpringValue(Time.deltaTime);
|
||||
SpringY.UpdateSpringValue(Time.deltaTime);
|
||||
|
||||
_newPosition = MovingObject.transform.localPosition;
|
||||
|
||||
_newPosition.x = MMMaths.Remap(SpringX.CurrentValue, -1f, 1f, -_range, _range);
|
||||
_newPosition.y = MMMaths.Remap(SpringY.CurrentValue, -1f, 1f, -_range, _range);
|
||||
|
||||
MovingObject.transform.localPosition = _newPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1c405f0504334b45bfbda5cce01f282
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,81 @@
|
||||
using MoreMountains.Feedbacks;
|
||||
using MoreMountains.Tools;
|
||||
#if MM_TEXTMESHPRO
|
||||
using TMPro;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Feel
|
||||
{
|
||||
[AddComponentMenu("")]
|
||||
public class FeelSpringsVector3Demo : MonoBehaviour
|
||||
{
|
||||
[Header("Spring")]
|
||||
public MMSpringFloat SpringX;
|
||||
public MMSpringFloat SpringY;
|
||||
public MMSpringFloat SpringZ;
|
||||
|
||||
[Header("Bindings")]
|
||||
public FeelSpringsDemoSlider DampingXSlider;
|
||||
public FeelSpringsDemoSlider FrequencyXSlider;
|
||||
public FeelSpringsDemoSlider DampingYSlider;
|
||||
public FeelSpringsDemoSlider FrequencyYSlider;
|
||||
public FeelSpringsDemoSlider DampingZSlider;
|
||||
public FeelSpringsDemoSlider FrequencyZSlider;
|
||||
public FeelSpringsDemoSlider BumpAmountSlider;
|
||||
public Transform MovingObject;
|
||||
|
||||
protected Vector3 _newPosition;
|
||||
|
||||
protected float _range = 0.375f;
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
SpringX.CurrentValue = 0f;
|
||||
SpringX.TargetValue = 0f;
|
||||
SpringX.Velocity = 0f;
|
||||
SpringY.CurrentValue = 0f;
|
||||
SpringY.TargetValue = 0f;
|
||||
SpringY.Velocity = 0f;
|
||||
SpringZ.CurrentValue = 0f;
|
||||
SpringZ.TargetValue = 0f;
|
||||
SpringZ.Velocity = 0f;
|
||||
}
|
||||
|
||||
public virtual void RandomMove()
|
||||
{
|
||||
SpringX.MoveTo(UnityEngine.Random.Range(-1f,1f));
|
||||
SpringY.MoveTo(UnityEngine.Random.Range(-1f,1f));
|
||||
SpringZ.MoveTo(UnityEngine.Random.Range(-1f,1f));
|
||||
}
|
||||
|
||||
public virtual void RandomBump()
|
||||
{
|
||||
float bumpAmount = BumpAmountSlider.value;
|
||||
SpringX.BumpRandom(-bumpAmount, bumpAmount);
|
||||
SpringY.BumpRandom(-bumpAmount, bumpAmount);
|
||||
SpringZ.BumpRandom(-bumpAmount, bumpAmount);
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
SpringX.Damping = DampingXSlider.value;
|
||||
SpringY.Damping = DampingYSlider.value;
|
||||
SpringX.Frequency = FrequencyXSlider.value;
|
||||
SpringY.Frequency = FrequencyYSlider.value;
|
||||
SpringZ.Damping = DampingZSlider.value;
|
||||
SpringZ.Frequency = FrequencyZSlider.value;
|
||||
SpringX.UpdateSpringValue(Time.deltaTime);
|
||||
SpringY.UpdateSpringValue(Time.deltaTime);
|
||||
SpringZ.UpdateSpringValue(Time.deltaTime);
|
||||
|
||||
_newPosition = MovingObject.transform.localPosition;
|
||||
|
||||
_newPosition.x = MMMaths.Remap(SpringX.CurrentValue, -1f, 1f, -_range, _range);
|
||||
_newPosition.y = MMMaths.Remap(SpringY.CurrentValue, -1f, 1f, -_range, _range) + 1f;
|
||||
_newPosition.z = MMMaths.Remap(SpringZ.CurrentValue, -1f, 1f, -_range, _range);
|
||||
|
||||
MovingObject.transform.localPosition = _newPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f901ae3a9353e9d4182e9771ee9e2f98
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user