基础内容
必要插件安装 缓动曲线和动画基础 ElementFolder,Track与其次级模块,PathNode重构
This commit is contained in:
89
Assets/Feel/FeelDemos/Wheel/Scripts/Wheel.cs
Normal file
89
Assets/Feel/FeelDemos/Wheel/Scripts/Wheel.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using MoreMountains.Feedbacks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Feel
|
||||
{
|
||||
[AddComponentMenu("")]
|
||||
public class Wheel : MonoBehaviour
|
||||
{
|
||||
[Header("Binding")]
|
||||
/// the part of the wheel that rotates
|
||||
[Tooltip("the part of the wheel that rotates")]
|
||||
public Transform RotatingPart;
|
||||
|
||||
[Header("Settings")]
|
||||
/// the speed at which the wheel should rotate
|
||||
[Tooltip("the speed at which the wheel should rotate")]
|
||||
public float RotationSpeed = 20f;
|
||||
|
||||
[Header("Feedbacks")]
|
||||
/// a feedback to call when the wheel starts turning
|
||||
[Tooltip("a feedback to call when the wheel starts turning")]
|
||||
public MMFeedbacks TurnFeedback;
|
||||
/// a feedback to call when the wheel stops turning
|
||||
[Tooltip("a feedback to call when the wheel stops turning")]
|
||||
public MMFeedbacks TurnStopFeedback;
|
||||
|
||||
protected bool _turning;
|
||||
|
||||
/// <summary>
|
||||
/// On Update we look for input
|
||||
/// </summary>
|
||||
protected virtual void Update()
|
||||
{
|
||||
HandleInput();
|
||||
HandleWheel();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detects input
|
||||
/// </summary>
|
||||
protected virtual void HandleInput()
|
||||
{
|
||||
if (FeelDemosInputHelper.CheckMainActionInputPressedThisFrame())
|
||||
{
|
||||
Turn();
|
||||
}
|
||||
if (FeelDemosInputHelper.CheckMainActionInputUpThisFrame())
|
||||
{
|
||||
TurnStop();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Every frame, rotates the wheel if needed
|
||||
/// </summary>
|
||||
protected virtual void HandleWheel()
|
||||
{
|
||||
if (_turning)
|
||||
{
|
||||
RotatingPart.transform.Rotate(this.transform.right, RotationSpeed * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes the wheel turn, plays a feedback if it's just starting to turn this frame
|
||||
/// </summary>
|
||||
protected virtual void Turn()
|
||||
{
|
||||
if (!_turning)
|
||||
{
|
||||
TurnFeedback?.PlayFeedbacks();
|
||||
}
|
||||
_turning = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the wheel from turning
|
||||
/// </summary>
|
||||
protected virtual void TurnStop()
|
||||
{
|
||||
TurnFeedback?.StopFeedbacks();
|
||||
TurnStopFeedback?.PlayFeedbacks();
|
||||
_turning = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Feel/FeelDemos/Wheel/Scripts/Wheel.cs.meta
Normal file
11
Assets/Feel/FeelDemos/Wheel/Scripts/Wheel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a5056a15a0bec0e41a3ccc3e1881eed7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user