diff options
Diffstat (limited to 'Client/Assembly-CSharp/FingerBehaviour.cs')
-rw-r--r-- | Client/Assembly-CSharp/FingerBehaviour.cs | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/FingerBehaviour.cs b/Client/Assembly-CSharp/FingerBehaviour.cs new file mode 100644 index 0000000..b39ad65 --- /dev/null +++ b/Client/Assembly-CSharp/FingerBehaviour.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections; +using UnityEngine; + +public class FingerBehaviour : MonoBehaviour +{ + public SpriteRenderer Finger; + + public SpriteRenderer Click; + + public float liftedAngle = -20f; + + public static class Quadratic + { + public static float InOut(float k) + { + if (k < 0f) + { + k = 0f; + } + if (k > 1f) + { + k = 1f; + } + if ((k *= 2f) < 1f) + { + return 0.5f * k * k; + } + return -0.5f * ((k -= 1f) * (k - 2f) - 1f); + } + } + + public IEnumerator DoClick(float duration) + { + for (float time = 0f; time < duration; time += Time.deltaTime) + { + float num = time / duration; + if (num < 0.4f) + { + float num2 = num / 0.4f; + num2 = num2 * 2f - 1f; + if (num2 < 0f) + { + float fingerAngle = Mathf.Lerp(this.liftedAngle, this.liftedAngle * 2f, 1f + Mathf.Abs(num2)); + this.SetFingerAngle(fingerAngle); + } + else + { + float fingerAngle2 = Mathf.Lerp(this.liftedAngle * 2f, 0f, num2); + this.SetFingerAngle(fingerAngle2); + } + } + else if (num < 0.7f) + { + this.ClickOn(); + } + else + { + float t = (num - 0.7f) / 0.3f; + this.Click.enabled = false; + float fingerAngle3 = Mathf.Lerp(0f, this.liftedAngle, t); + this.SetFingerAngle(fingerAngle3); + } + yield return null; + } + this.ClickOff(); + yield break; + } + + private void SetFingerAngle(float angle) + { + this.Finger.transform.localRotation = Quaternion.Euler(0f, 0f, angle); + } + + public void ClickOff() + { + this.Click.enabled = false; + this.SetFingerAngle(this.liftedAngle); + } + + public void ClickOn() + { + this.Click.enabled = true; + this.SetFingerAngle(0f); + } + + public IEnumerator MoveTo(Vector2 target, float duration) + { + Vector3 startPos = base.transform.position; + Vector3 targetPos = target; + targetPos.z = startPos.z; + for (float time = 0f; time < duration; time += Time.deltaTime) + { + float t = time / duration; + base.transform.position = Vector3.Lerp(startPos, targetPos, t); + yield return null; + } + base.transform.position = targetPos; + yield break; + } +} |