2021-12-19 04:10:43 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2021-12-24 23:41:35 +00:00
|
|
|
using DG.Tweening;
|
2023-10-29 19:44:47 +00:00
|
|
|
using HeavenStudio.Games;
|
2021-12-19 04:10:43 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio
|
2021-12-24 23:41:35 +00:00
|
|
|
{
|
|
|
|
public class CircleCursor : MonoBehaviour
|
2021-12-19 04:10:43 +00:00
|
|
|
{
|
2023-10-29 19:44:47 +00:00
|
|
|
static readonly GradientAlphaKey[] cursorAlphaKeys = new GradientAlphaKey[]
|
|
|
|
{
|
|
|
|
new GradientAlphaKey(0.5f, 0),
|
|
|
|
new GradientAlphaKey(0, 1)
|
|
|
|
};
|
|
|
|
|
2021-12-24 23:41:35 +00:00
|
|
|
[SerializeField] private bool follow = false;
|
|
|
|
[SerializeField] private float mouseMoveSpeed;
|
2023-10-29 19:44:47 +00:00
|
|
|
[SerializeField] private float sideChangeTrailTime;
|
2021-12-19 04:10:43 +00:00
|
|
|
|
2021-12-24 23:41:35 +00:00
|
|
|
[Header("DSGuy")]
|
2023-10-29 19:44:47 +00:00
|
|
|
[SerializeField] private GameObject DSGuy;
|
|
|
|
[SerializeField] private Animator DSGuyAnimator;
|
|
|
|
[SerializeField] private float flickCoeff = 0.35f;
|
|
|
|
[SerializeField] private float flickInitMul = 1.5f;
|
|
|
|
[SerializeField] private TrailRenderer splitTouchSnapEffect;
|
2021-12-26 01:04:23 +00:00
|
|
|
public GameObject InnerCircle;
|
2021-12-24 23:41:35 +00:00
|
|
|
[SerializeField] private GameObject Circle;
|
2023-10-29 19:44:47 +00:00
|
|
|
private bool isOpen;
|
|
|
|
private Vector3 vel, flickStart, flickDeltaPos;
|
|
|
|
private Color colorMain, colorL, colorR;
|
|
|
|
private Gradient gradientL, gradientR;
|
|
|
|
private bool lastLeftRightState;
|
|
|
|
private float trailEnableTime;
|
|
|
|
|
|
|
|
private SpriteRenderer innerCircleRenderer;
|
2021-12-19 04:10:43 +00:00
|
|
|
|
2021-12-24 23:41:35 +00:00
|
|
|
private void Start()
|
2021-12-19 04:10:43 +00:00
|
|
|
{
|
2022-01-03 22:42:43 +00:00
|
|
|
// Cursor.visible = false;
|
2023-10-29 19:44:47 +00:00
|
|
|
if (splitTouchSnapEffect != null)
|
|
|
|
{
|
|
|
|
splitTouchSnapEffect.emitting = false;
|
|
|
|
}
|
|
|
|
if (InnerCircle != null)
|
|
|
|
{
|
|
|
|
innerCircleRenderer = InnerCircle.GetComponent<SpriteRenderer>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Open()
|
|
|
|
{
|
|
|
|
vel = Vector3.zero;
|
|
|
|
flickDeltaPos = Vector3.zero;
|
|
|
|
DSGuyAnimator.Play("Open", -1);
|
|
|
|
Circle.SetActive(false);
|
|
|
|
isOpen = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Close()
|
|
|
|
{
|
|
|
|
DSGuyAnimator.Play("Close", -1);
|
2023-12-26 05:22:51 +00:00
|
|
|
Circle.SetActive(true && PlayerInput.CurrentControlStyle == InputSystem.InputController.ControlStyles.Touch);
|
2023-10-29 19:44:47 +00:00
|
|
|
isOpen = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Flick(Vector3 startPos, Vector3 newVel)
|
|
|
|
{
|
|
|
|
flickStart = startPos;
|
|
|
|
vel = newVel;
|
|
|
|
DSGuyAnimator.Play("Flick", -1);
|
2023-12-26 05:22:51 +00:00
|
|
|
Circle.SetActive(true && PlayerInput.CurrentControlStyle == InputSystem.InputController.ControlStyles.Touch);
|
2023-10-29 19:44:47 +00:00
|
|
|
isOpen = false;
|
2021-12-19 04:10:43 +00:00
|
|
|
}
|
2021-12-24 23:41:35 +00:00
|
|
|
|
|
|
|
private void Update()
|
2021-12-19 04:10:43 +00:00
|
|
|
{
|
2023-10-29 19:44:47 +00:00
|
|
|
Vector3 pos = PlayerInput.GetInputController(1).GetPointer();
|
|
|
|
Vector3 deltaPos = pos - transform.position;
|
2021-12-24 23:41:35 +00:00
|
|
|
|
|
|
|
if (follow)
|
|
|
|
{
|
|
|
|
Vector2 direction = (pos - transform.position).normalized;
|
|
|
|
this.GetComponent<Rigidbody2D>().velocity = new Vector2(direction.x * mouseMoveSpeed, direction.y * mouseMoveSpeed);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-12-26 05:22:51 +00:00
|
|
|
DSGuy.SetActive(PlayerInput.CurrentControlStyle == InputSystem.InputController.ControlStyles.Touch);
|
|
|
|
Circle.SetActive(PlayerInput.CurrentControlStyle == InputSystem.InputController.ControlStyles.Touch);
|
|
|
|
if (PlayerInput.CurrentControlStyle != InputSystem.InputController.ControlStyles.Touch) return;
|
|
|
|
|
2023-10-29 19:44:47 +00:00
|
|
|
bool lrState = PlayerInput.GetInputController(1).GetPointerLeftRight();
|
|
|
|
if (splitTouchSnapEffect != null && PlayerInput.CurrentControlStyle == InputSystem.InputController.ControlStyles.Touch && (GameManager.instance?.GameHasSplitColours ?? false))
|
|
|
|
{
|
|
|
|
if (lrState != lastLeftRightState)
|
|
|
|
{
|
|
|
|
lastLeftRightState = lrState;
|
|
|
|
trailEnableTime = sideChangeTrailTime;
|
|
|
|
splitTouchSnapEffect.emitting = true;
|
2021-12-24 23:41:35 +00:00
|
|
|
|
2023-10-29 19:44:47 +00:00
|
|
|
innerCircleRenderer.color = lastLeftRightState ? colorR : colorL;
|
|
|
|
splitTouchSnapEffect.colorGradient = lastLeftRightState ? gradientR : gradientL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (trailEnableTime <= 0)
|
|
|
|
{
|
|
|
|
trailEnableTime = 0;
|
|
|
|
splitTouchSnapEffect.emitting = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
trailEnableTime -= Time.deltaTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (splitTouchSnapEffect != null && splitTouchSnapEffect.emitting)
|
2021-12-24 23:41:35 +00:00
|
|
|
{
|
2023-12-26 05:22:51 +00:00
|
|
|
ClearTrail(false);
|
2021-12-24 23:41:35 +00:00
|
|
|
}
|
2023-10-29 19:44:47 +00:00
|
|
|
|
|
|
|
gameObject.transform.position = pos;
|
|
|
|
if (vel.magnitude > 0.05f)
|
2021-12-24 23:41:35 +00:00
|
|
|
{
|
2023-10-29 19:44:47 +00:00
|
|
|
vel -= flickCoeff * Time.deltaTime * vel;
|
|
|
|
flickDeltaPos += vel * Time.deltaTime;
|
|
|
|
DSGuy.transform.position = flickStart + flickDeltaPos;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vel = Vector3.zero;
|
|
|
|
flickDeltaPos = Vector3.zero;
|
|
|
|
DSGuy.transform.position = pos;
|
|
|
|
}
|
2021-12-24 23:41:35 +00:00
|
|
|
|
2023-10-29 19:44:47 +00:00
|
|
|
if (PlayerInput.GetIsAction(Minigame.InputAction_BasicPress))
|
|
|
|
{
|
|
|
|
Open();
|
|
|
|
}
|
|
|
|
else if (PlayerInput.GetIsAction(Minigame.InputAction_BasicRelease))
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
else if (PlayerInput.GetIsAction(Minigame.InputAction_FlickRelease))
|
|
|
|
{
|
|
|
|
Flick(pos, deltaPos * flickInitMul);
|
|
|
|
ClearTrail();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((!PlayerInput.PlayerHasControl()) && isOpen)
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
ClearTrail();
|
|
|
|
if (splitTouchSnapEffect != null)
|
|
|
|
{
|
|
|
|
splitTouchSnapEffect.emitting = false;
|
|
|
|
}
|
2021-12-24 23:41:35 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-19 04:10:43 +00:00
|
|
|
}
|
2021-12-24 23:41:35 +00:00
|
|
|
|
2023-10-29 19:44:47 +00:00
|
|
|
public void LockCursor(bool toggle)
|
|
|
|
{
|
|
|
|
PlayerInput.GetInputController(1).TogglePointerLock(toggle);
|
|
|
|
ClearTrail();
|
|
|
|
}
|
|
|
|
|
2023-12-26 05:22:51 +00:00
|
|
|
public void ClearTrail(bool emm = false)
|
2023-10-29 19:44:47 +00:00
|
|
|
{
|
|
|
|
trailEnableTime = 0;
|
|
|
|
if (splitTouchSnapEffect != null)
|
|
|
|
{
|
|
|
|
splitTouchSnapEffect.Clear();
|
|
|
|
}
|
2023-12-26 05:22:51 +00:00
|
|
|
splitTouchSnapEffect.emitting = emm;
|
2023-10-29 19:44:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetCursorColors(Color main, Color left, Color right)
|
|
|
|
{
|
|
|
|
if (innerCircleRenderer == null) innerCircleRenderer = InnerCircle.GetComponent<SpriteRenderer>();
|
|
|
|
|
|
|
|
colorMain = main;
|
|
|
|
colorL = left;
|
|
|
|
colorR = right;
|
|
|
|
if (PlayerInput.CurrentControlStyle == InputSystem.InputController.ControlStyles.Touch && (GameManager.instance?.GameHasSplitColours ?? false))
|
|
|
|
{
|
|
|
|
innerCircleRenderer.color = lastLeftRightState ? colorR : colorL;
|
|
|
|
gradientL = new Gradient()
|
|
|
|
{
|
|
|
|
colorKeys = new GradientColorKey[]
|
|
|
|
{
|
|
|
|
new GradientColorKey(colorL, 0),
|
|
|
|
new GradientColorKey(colorL, 1)
|
|
|
|
},
|
|
|
|
alphaKeys = cursorAlphaKeys
|
|
|
|
};
|
|
|
|
gradientR = new Gradient()
|
|
|
|
{
|
|
|
|
colorKeys = new GradientColorKey[]
|
|
|
|
{
|
|
|
|
new GradientColorKey(colorR, 0),
|
|
|
|
new GradientColorKey(colorR, 1)
|
|
|
|
},
|
|
|
|
alphaKeys = cursorAlphaKeys
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
innerCircleRenderer.color = colorMain;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-24 23:41:35 +00:00
|
|
|
}
|