add smoother demo
This commit is contained in:
parent
f47aa9b4ea
commit
c87301bf67
2 changed files with 177 additions and 178 deletions
|
@ -120,71 +120,6 @@ NavMeshSettings:
|
||||||
debug:
|
debug:
|
||||||
m_Flags: 0
|
m_Flags: 0
|
||||||
m_NavMeshData: {fileID: 0}
|
m_NavMeshData: {fileID: 0}
|
||||||
--- !u!1 &127705016
|
|
||||||
GameObject:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
serializedVersion: 6
|
|
||||||
m_Component:
|
|
||||||
- component: {fileID: 127705019}
|
|
||||||
- component: {fileID: 127705017}
|
|
||||||
m_Layer: 0
|
|
||||||
m_Name: SpectrumBind
|
|
||||||
m_TagString: Untagged
|
|
||||||
m_Icon: {fileID: 0}
|
|
||||||
m_NavMeshLayer: 0
|
|
||||||
m_StaticEditorFlags: 0
|
|
||||||
m_IsActive: 1
|
|
||||||
--- !u!114 &127705017
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 127705016}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: 54ab37d032df403e881d6a7a78141815, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
pdBackend: {fileID: 987772533}
|
|
||||||
selection:
|
|
||||||
serializedVersion: 2
|
|
||||||
x: 0
|
|
||||||
y: 36
|
|
||||||
width: 43.544582
|
|
||||||
height: 210
|
|
||||||
energyChanged:
|
|
||||||
m_PersistentCalls:
|
|
||||||
m_Calls:
|
|
||||||
- m_Target: {fileID: 428795649}
|
|
||||||
m_MethodName: OnValueChanged
|
|
||||||
m_Mode: 0
|
|
||||||
m_Arguments:
|
|
||||||
m_ObjectArgument: {fileID: 0}
|
|
||||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
|
||||||
m_IntArgument: 0
|
|
||||||
m_FloatArgument: 0
|
|
||||||
m_StringArgument:
|
|
||||||
m_BoolArgument: 0
|
|
||||||
m_CallState: 2
|
|
||||||
channel: 0
|
|
||||||
--- !u!4 &127705019
|
|
||||||
Transform:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 127705016}
|
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
|
||||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
|
||||||
m_Children: []
|
|
||||||
m_Father: {fileID: 0}
|
|
||||||
m_RootOrder: 2
|
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
|
||||||
--- !u!1 &267275365
|
--- !u!1 &267275365
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -263,7 +198,7 @@ Transform:
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 267275365}
|
m_GameObject: {fileID: 267275365}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: 0, y: 1.85, z: -5}
|
m_LocalPosition: {x: -0.39, y: 0.09, z: -0.44}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
|
@ -574,44 +509,13 @@ GameObject:
|
||||||
- component: {fileID: 428795651}
|
- component: {fileID: 428795651}
|
||||||
- component: {fileID: 428795650}
|
- component: {fileID: 428795650}
|
||||||
- component: {fileID: 428795653}
|
- component: {fileID: 428795653}
|
||||||
- component: {fileID: 428795649}
|
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: BoomBall
|
m_Name: NoSmooth
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
m_StaticEditorFlags: 0
|
m_StaticEditorFlags: 0
|
||||||
m_IsActive: 1
|
m_IsActive: 1
|
||||||
--- !u!114 &428795649
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 428795648}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: 9de1490c361f2bd48b4a81ad0457a4e7, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
threshold: 500
|
|
||||||
attackTime: 0.01
|
|
||||||
releaseTime: 0.5
|
|
||||||
holdTime: 0.2
|
|
||||||
onSmoothProcessed:
|
|
||||||
m_PersistentCalls:
|
|
||||||
m_Calls:
|
|
||||||
- m_Target: {fileID: 428795653}
|
|
||||||
m_MethodName: set_Size
|
|
||||||
m_Mode: 0
|
|
||||||
m_Arguments:
|
|
||||||
m_ObjectArgument: {fileID: 0}
|
|
||||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
|
||||||
m_IntArgument: 0
|
|
||||||
m_FloatArgument: 0
|
|
||||||
m_StringArgument:
|
|
||||||
m_BoolArgument: 0
|
|
||||||
m_CallState: 2
|
|
||||||
--- !u!23 &428795650
|
--- !u!23 &428795650
|
||||||
MeshRenderer:
|
MeshRenderer:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -666,11 +570,11 @@ Transform:
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 428795648}
|
m_GameObject: {fileID: 428795648}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: 0, y: 0, z: 3.25}
|
m_LocalPosition: {x: -3.16, y: 0, z: 3.25}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 3
|
m_RootOrder: 2
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!114 &428795653
|
--- !u!114 &428795653
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
|
@ -694,6 +598,8 @@ GameObject:
|
||||||
m_Component:
|
m_Component:
|
||||||
- component: {fileID: 987772534}
|
- component: {fileID: 987772534}
|
||||||
- component: {fileID: 987772533}
|
- component: {fileID: 987772533}
|
||||||
|
- component: {fileID: 987772536}
|
||||||
|
- component: {fileID: 987772535}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: PdBackend
|
m_Name: PdBackend
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
|
@ -734,3 +640,161 @@ Transform:
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 1
|
m_RootOrder: 1
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!114 &987772535
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 987772532}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 9de1490c361f2bd48b4a81ad0457a4e7, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
attackSmooth: 1
|
||||||
|
releaseSmooth: 1
|
||||||
|
onSmoothProcessed:
|
||||||
|
m_PersistentCalls:
|
||||||
|
m_Calls:
|
||||||
|
- m_Target: {fileID: 2040356463}
|
||||||
|
m_MethodName: set_Size
|
||||||
|
m_Mode: 0
|
||||||
|
m_Arguments:
|
||||||
|
m_ObjectArgument: {fileID: 0}
|
||||||
|
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
||||||
|
m_IntArgument: 0
|
||||||
|
m_FloatArgument: 0
|
||||||
|
m_StringArgument:
|
||||||
|
m_BoolArgument: 0
|
||||||
|
m_CallState: 2
|
||||||
|
--- !u!114 &987772536
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 987772532}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: a1a556319a642d143b7dbcdbace71ad9, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
pdbackend: {fileID: 987772533}
|
||||||
|
channel: 1
|
||||||
|
levelChanged:
|
||||||
|
m_PersistentCalls:
|
||||||
|
m_Calls:
|
||||||
|
- m_Target: {fileID: 987772535}
|
||||||
|
m_MethodName: OnValueChanged
|
||||||
|
m_Mode: 0
|
||||||
|
m_Arguments:
|
||||||
|
m_ObjectArgument: {fileID: 0}
|
||||||
|
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
||||||
|
m_IntArgument: 0
|
||||||
|
m_FloatArgument: 0
|
||||||
|
m_StringArgument:
|
||||||
|
m_BoolArgument: 0
|
||||||
|
m_CallState: 2
|
||||||
|
- m_Target: {fileID: 428795653}
|
||||||
|
m_MethodName: set_Size
|
||||||
|
m_Mode: 0
|
||||||
|
m_Arguments:
|
||||||
|
m_ObjectArgument: {fileID: 0}
|
||||||
|
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
||||||
|
m_IntArgument: 0
|
||||||
|
m_FloatArgument: 0
|
||||||
|
m_StringArgument:
|
||||||
|
m_BoolArgument: 0
|
||||||
|
m_CallState: 2
|
||||||
|
--- !u!1 &2040356462
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 2040356466}
|
||||||
|
- component: {fileID: 2040356465}
|
||||||
|
- component: {fileID: 2040356464}
|
||||||
|
- component: {fileID: 2040356463}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: Smooth
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!114 &2040356463
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2040356462}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 87673687b9b5a10488287f6faecad9d0, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
--- !u!23 &2040356464
|
||||||
|
MeshRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2040356462}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_CastShadows: 1
|
||||||
|
m_ReceiveShadows: 1
|
||||||
|
m_DynamicOccludee: 1
|
||||||
|
m_MotionVectors: 1
|
||||||
|
m_LightProbeUsage: 1
|
||||||
|
m_ReflectionProbeUsage: 1
|
||||||
|
m_RenderingLayerMask: 1
|
||||||
|
m_RendererPriority: 0
|
||||||
|
m_Materials:
|
||||||
|
- {fileID: 2100000, guid: f044463ea66a19c47aef13261142b54e, type: 2}
|
||||||
|
m_StaticBatchInfo:
|
||||||
|
firstSubMesh: 0
|
||||||
|
subMeshCount: 0
|
||||||
|
m_StaticBatchRoot: {fileID: 0}
|
||||||
|
m_ProbeAnchor: {fileID: 0}
|
||||||
|
m_LightProbeVolumeOverride: {fileID: 0}
|
||||||
|
m_ScaleInLightmap: 1
|
||||||
|
m_ReceiveGI: 1
|
||||||
|
m_PreserveUVs: 0
|
||||||
|
m_IgnoreNormalsForChartDetection: 0
|
||||||
|
m_ImportantGI: 0
|
||||||
|
m_StitchLightmapSeams: 0
|
||||||
|
m_SelectedEditorRenderState: 3
|
||||||
|
m_MinimumChartSize: 4
|
||||||
|
m_AutoUVMaxDistance: 0.5
|
||||||
|
m_AutoUVMaxAngle: 89
|
||||||
|
m_LightmapParameters: {fileID: 0}
|
||||||
|
m_SortingLayerID: 0
|
||||||
|
m_SortingLayer: 0
|
||||||
|
m_SortingOrder: 0
|
||||||
|
--- !u!33 &2040356465
|
||||||
|
MeshFilter:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2040356462}
|
||||||
|
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
|
--- !u!4 &2040356466
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2040356462}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 2.23, y: 0, z: 3.25}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_RootOrder: 3
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Timers;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
|
|
||||||
|
@ -9,89 +10,23 @@ public class UnitySmoothEvent : UnityEvent<float>
|
||||||
|
|
||||||
public class Smoother : MonoBehaviour
|
public class Smoother : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] private float threshold;
|
[SerializeField, Range(1f, 10f)] private float attackSmooth = 1f;
|
||||||
[SerializeField] private float attackTime;
|
[SerializeField, Range(1f, 10f)] private float releaseSmooth = 1f;
|
||||||
[SerializeField] private float releaseTime;
|
|
||||||
[SerializeField] private float holdTime;
|
|
||||||
[SerializeField] private UnitySmoothEvent onSmoothProcessed;
|
[SerializeField] private UnitySmoothEvent onSmoothProcessed;
|
||||||
|
|
||||||
enum State
|
private float input_;
|
||||||
{
|
private float previous_;
|
||||||
StandBy,
|
|
||||||
Attack,
|
|
||||||
Hold,
|
|
||||||
Release
|
|
||||||
};
|
|
||||||
|
|
||||||
private State state_ = State.StandBy;
|
|
||||||
private float attackStart_ = 0f;
|
|
||||||
private float holdStart_ = 0f;
|
|
||||||
private float releaseStart_ = 0f;
|
|
||||||
private float attackValue_ = 0f;
|
|
||||||
private bool releaseReady_ = false;
|
|
||||||
|
|
||||||
public void OnValueChanged(float value)
|
public void OnValueChanged(float value)
|
||||||
{
|
{
|
||||||
if (CanStartAttackPhase(value))
|
input_ = value;
|
||||||
{
|
|
||||||
state_ = State.Attack;
|
|
||||||
Debug.Log("Attack");
|
|
||||||
attackStart_ = Time.time;
|
|
||||||
attackValue_ = value;
|
|
||||||
}
|
|
||||||
else if (CanStartReleasePhase(value))
|
|
||||||
{
|
|
||||||
state_ = State.Release;
|
|
||||||
Debug.Log("Release");
|
|
||||||
releaseStart_ = Time.time;
|
|
||||||
releaseReady_ = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
|
var distance = input_ - previous_;
|
||||||
var now = Time.time;
|
previous_ += distance > 0f? (1f/attackSmooth) * distance : (1f/releaseSmooth) * distance;
|
||||||
switch (state_)
|
onSmoothProcessed.Invoke(previous_);
|
||||||
{
|
|
||||||
case State.Attack:
|
|
||||||
{
|
|
||||||
var timeSinceAttackStart = now - attackStart_;
|
|
||||||
onSmoothProcessed.Invoke(attackValue_ * (timeSinceAttackStart / attackTime));
|
|
||||||
|
|
||||||
if (timeSinceAttackStart >= attackTime)
|
|
||||||
{
|
|
||||||
state_ = State.Hold;
|
|
||||||
Debug.Log("Hold");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case State.Hold:
|
|
||||||
{
|
|
||||||
releaseReady_ = (now - holdStart_) > holdTime;
|
|
||||||
onSmoothProcessed.Invoke(attackValue_);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case State.Release:
|
|
||||||
{
|
|
||||||
var timeSinceReleaseStart = now - releaseStart_;
|
|
||||||
onSmoothProcessed.Invoke(attackValue_ * (1.0f - (timeSinceReleaseStart / releaseTime)));
|
|
||||||
if (timeSinceReleaseStart >= releaseTime)
|
|
||||||
{
|
|
||||||
state_ = State.StandBy;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private bool CanStartAttackPhase(float value)
|
|
||||||
{
|
|
||||||
return value < threshold && state_ == State.StandBy;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool CanStartReleasePhase(float value)
|
|
||||||
{
|
|
||||||
return state_ == State.Hold && value < threshold && releaseReady_;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue