mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 22:27:38 +02:00
Alternate Control Styles Support (#554)
* add mouse controller * support different control styles in options deprecate old input check methods * fully functional input actions system * btsds InputAction * blue bear InputAction * more games fix bugs with some input related systems * coin toss re-toss * cheer readers touch * dog ninja touch * multiple games * last of the easy games' touch * more specialized games * specialized games 2 * finish ktb games * remove legacy settings disclaimer * "only" two games left * karate man touch * rockers touch still needs fixes and bad judge strum * DSGuy flicking animation * playstyle chart property * improve performance of minigame preloading * improve look of cursor make assetbundles use chunk-based compression refactor assetbundle loading methods a bit * prime conductor stream playback to stabilize seeking operations * fix air rally swing on pad release * use virtual mouse pointer * add UniTask * make BeatAction use UniTask * implement UniTask to replace some coroutines * add touch style UI elements and effects games now support the ability to define two cursor colours if they need split screen touch inputs * update plugins and buildscript * implement thresholded pointer position clipping * fix clamping * instant show / hide fix discord game SDK crashes
This commit is contained in:
@ -3,29 +3,81 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
using DG.Tweening;
|
||||
using HeavenStudio.Games;
|
||||
|
||||
namespace HeavenStudio
|
||||
{
|
||||
public class CircleCursor : MonoBehaviour
|
||||
{
|
||||
static readonly GradientAlphaKey[] cursorAlphaKeys = new GradientAlphaKey[]
|
||||
{
|
||||
new GradientAlphaKey(0.5f, 0),
|
||||
new GradientAlphaKey(0, 1)
|
||||
};
|
||||
|
||||
[SerializeField] private bool follow = false;
|
||||
[SerializeField] private float mouseMoveSpeed;
|
||||
[SerializeField] private float sideChangeTrailTime;
|
||||
|
||||
[Header("DSGuy")]
|
||||
[SerializeField] private GameObject Eyes;
|
||||
[SerializeField] private GameObject OuterCircle;
|
||||
[SerializeField] private GameObject DSGuy;
|
||||
[SerializeField] private Animator DSGuyAnimator;
|
||||
[SerializeField] private float flickCoeff = 0.35f;
|
||||
[SerializeField] private float flickInitMul = 1.5f;
|
||||
[SerializeField] private TrailRenderer splitTouchSnapEffect;
|
||||
public GameObject InnerCircle;
|
||||
[SerializeField] private GameObject Circle;
|
||||
private Tween outerCircleTween, eyesTween;
|
||||
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;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Cursor.visible = false;
|
||||
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);
|
||||
Circle.SetActive(true);
|
||||
isOpen = false;
|
||||
}
|
||||
|
||||
private void Flick(Vector3 startPos, Vector3 newVel)
|
||||
{
|
||||
flickStart = startPos;
|
||||
vel = newVel;
|
||||
DSGuyAnimator.Play("Flick", -1);
|
||||
Circle.SetActive(true);
|
||||
isOpen = false;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
Vector3 pos = GameManager.instance.CursorCam.ScreenToWorldPoint(Input.mousePosition);
|
||||
Vector3 pos = PlayerInput.GetInputController(1).GetPointer();
|
||||
Vector3 deltaPos = pos - transform.position;
|
||||
|
||||
if (follow)
|
||||
{
|
||||
@ -34,32 +86,122 @@ namespace HeavenStudio
|
||||
}
|
||||
else
|
||||
{
|
||||
this.gameObject.transform.position = new Vector3(pos.x, pos.y, 0);
|
||||
|
||||
if (PlayerInput.Pressed())
|
||||
bool lrState = PlayerInput.GetInputController(1).GetPointerLeftRight();
|
||||
if (splitTouchSnapEffect != null && PlayerInput.CurrentControlStyle == InputSystem.InputController.ControlStyles.Touch && (GameManager.instance?.GameHasSplitColours ?? false))
|
||||
{
|
||||
// Cursor.visible = false;
|
||||
Circle.transform.DOScale(0, 0.5f).SetEase(Ease.OutExpo);
|
||||
InnerCircle.SetActive(true);
|
||||
outerCircleTween.Kill();
|
||||
outerCircleTween = OuterCircle.transform.DOScale(1, 0.15f).SetEase(Ease.OutExpo);
|
||||
if (lrState != lastLeftRightState)
|
||||
{
|
||||
lastLeftRightState = lrState;
|
||||
trailEnableTime = sideChangeTrailTime;
|
||||
splitTouchSnapEffect.emitting = true;
|
||||
|
||||
Eyes.SetActive(true);
|
||||
eyesTween.Kill();
|
||||
eyesTween = Eyes.transform.DOLocalMoveY(0.15f, 0.15f).SetEase(Ease.OutExpo);
|
||||
innerCircleRenderer.color = lastLeftRightState ? colorR : colorL;
|
||||
splitTouchSnapEffect.colorGradient = lastLeftRightState ? gradientR : gradientL;
|
||||
}
|
||||
|
||||
if (trailEnableTime <= 0)
|
||||
{
|
||||
trailEnableTime = 0;
|
||||
splitTouchSnapEffect.emitting = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
trailEnableTime -= Time.deltaTime;
|
||||
}
|
||||
}
|
||||
else if (PlayerInput.PressedUp())
|
||||
else if (splitTouchSnapEffect != null && splitTouchSnapEffect.emitting)
|
||||
{
|
||||
Circle.transform.DOScale(0.2f, 0.5f).SetEase(Ease.OutExpo);
|
||||
InnerCircle.SetActive(false);
|
||||
outerCircleTween.Kill();
|
||||
outerCircleTween = OuterCircle.transform.DOScale(0, 0.15f);
|
||||
ClearTrail();
|
||||
}
|
||||
|
||||
eyesTween.Kill();
|
||||
eyesTween = Eyes.transform.DOLocalMoveY(-0.66f, 0.15f).OnComplete(delegate { Eyes.SetActive(false); });
|
||||
gameObject.transform.position = pos;
|
||||
if (vel.magnitude > 0.05f)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void LockCursor(bool toggle)
|
||||
{
|
||||
PlayerInput.GetInputController(1).TogglePointerLock(toggle);
|
||||
ClearTrail();
|
||||
}
|
||||
|
||||
public void ClearTrail()
|
||||
{
|
||||
trailEnableTime = 0;
|
||||
if (splitTouchSnapEffect != null)
|
||||
{
|
||||
splitTouchSnapEffect.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user