переработка BoolView. Избавился от софтлока исходящего от SmoothDamp
This commit is contained in:
parent
ba66dc8d16
commit
7187c0e8e8
@ -19,9 +19,8 @@ public class BoolView : MonoBehaviour, IView
|
||||
[SerializeField] private AudioClip EnableSound;
|
||||
[SerializeField] private AudioClip DisableSound;
|
||||
|
||||
[SerializeField] private float switchDuration = 0.2f;
|
||||
[SerializeField] private float speed = 500f;
|
||||
|
||||
Vector2 toggleVelocity = Vector2.zero;
|
||||
|
||||
|
||||
bool value;
|
||||
@ -34,11 +33,10 @@ public class BoolView : MonoBehaviour, IView
|
||||
{
|
||||
bool newValue = SettingsManager.GetBool(settingId, false);
|
||||
if (newValue == value) return;
|
||||
|
||||
value = newValue;
|
||||
|
||||
if (coroutine == null)
|
||||
coroutine = StartCoroutine(Display(value, switchDuration, sounded: true));
|
||||
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(Display(value, speed, sounded: true));
|
||||
}
|
||||
|
||||
public void Initialize(string settingId)
|
||||
@ -60,11 +58,11 @@ public class BoolView : MonoBehaviour, IView
|
||||
|
||||
coroutine = null;
|
||||
if (coroutine == null)
|
||||
coroutine = StartCoroutine(Display(this.value, 0.001f, sounded: false));
|
||||
coroutine = StartCoroutine(Display(this.value, 10000, sounded: false));
|
||||
|
||||
}
|
||||
|
||||
IEnumerator Display(bool value, float duration, bool sounded)
|
||||
IEnumerator Display(bool value, float movespeed, bool sounded)
|
||||
{
|
||||
Vector2 targetPosition = value ? EnabledPosition : DisabledPosition;
|
||||
Vector2 startPosition = value ? DisabledPosition : EnabledPosition;
|
||||
@ -80,11 +78,7 @@ public class BoolView : MonoBehaviour, IView
|
||||
|
||||
while (ToggleRect.anchoredPosition != targetPosition)
|
||||
{
|
||||
ToggleRect.anchoredPosition =Vector2.SmoothDamp(current: ToggleRect.anchoredPosition,
|
||||
target: targetPosition,
|
||||
currentVelocity: ref toggleVelocity,
|
||||
smoothTime: switchDuration);
|
||||
|
||||
ToggleRect.anchoredPosition = Vector2.MoveTowards(ToggleRect.anchoredPosition, targetPosition, Time.deltaTime * movespeed);
|
||||
|
||||
//цвет
|
||||
float t = Vector2.Distance(ToggleRect.anchoredPosition, startPosition) / Vector2.Distance(startPosition, targetPosition);
|
||||
@ -93,18 +87,7 @@ public class BoolView : MonoBehaviour, IView
|
||||
foreach (Graphic g in ToggleGraphics)
|
||||
{
|
||||
g.color = targetColor;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//приблизительность флоата...
|
||||
if (Vector2.Distance(ToggleRect.anchoredPosition, targetPosition) < 0.001f)
|
||||
{
|
||||
ToggleRect.anchoredPosition = targetPosition; break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
@ -362,7 +362,7 @@ MonoBehaviour:
|
||||
DisabledPosition: {x: -20, y: 0}
|
||||
EnableSound: {fileID: 8300000, guid: 70982532191dd7346bf6999b59e666e3, type: 3}
|
||||
DisableSound: {fileID: 8300000, guid: af069d6da1cc68847b46eaab855901ca, type: 3}
|
||||
switchDuration: 0.02
|
||||
speed: 1000
|
||||
--- !u!1 &2616922182319823143
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user