오랜만입미다.
하는김에 패드도 지원하게끔 만들었는데 집에 있는 건 듀얼쇼크 뿐이라 다 잘 작동하면 좋겠네요..
조작키를 정리해보니 참 많더라고요...
그래서 패드 제어하는 스크립트를 만들어왔습니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using System.Linq;
using DG.Tweening;
public class RumbleManager : MonoBehaviour
{
public static RumbleManager instance;
private Gamepad pad;
private Coroutine stopRumbleAfterTimeCoroutine;
public Dictionary<int,Vector4> rumble_Vectors = new Dictionary<int, Vector4>();
int count = 0;
Vector3 maxVector;
private void Awake()
{
instance = this;
}
public void RumblePulse(float lowFrequency, float highFrequency, float _duration)
{
pad = Gamepad.current;
Debug.Log("Rumbling_Seq!!");
if (pad != null)
{
pad.SetMotorSpeeds(lowFrequency, highFrequency);
stopRumbleAfterTimeCoroutine = StartCoroutine(StopRumble(_duration, pad));
}
}
private void OnDestroy() {
instance = null;
}
public void RumblePulse(Vector3 _freqvec)
{
pad = Gamepad.current;
Vector4 _getvec = _freqvec;
_getvec.w = 0;
keyregen:
count++;
if (!Gamepad.ReferenceEquals(Gamepad.current,null))
{
if(!rumble_Vectors.ContainsKey(count))
{
rumble_Vectors.Add(count, _freqvec);
}
else
{
goto keyregen;
}
}
}
public void RumbleLerp(Vector3 _freqvec)
{
pad = Gamepad.current;
Vector4 _getvec = _freqvec;
_getvec.w = 1;
if (!Gamepad.ReferenceEquals(Gamepad.current,null))
{
keyregen:
var _key = count++;
//Debug.Log("Get Key : " + count);
if (!rumble_Vectors.ContainsKey(_key))
{
rumble_Vectors.Add(_key, _freqvec);
DOTween.To(() => rumble_Vectors[_key], x => rumble_Vectors[_key] = x, new Vector4(0, 0, 0, 1), rumble_Vectors[_key].z * 0.5f).SetEase(Ease.Linear).SetDelay(rumble_Vectors[_key].z * 0.5f);
}
else
{
goto keyregen;
}
}
}
private void Update()
{
if (!Gamepad.ReferenceEquals(pad,null))
{
maxVector = Vector3.zero;
if (rumble_Vectors.Count > 0 && Time.timeScale > 0)
{
for (int i = 0; i < rumble_Vectors.Count; i++)
{
var _dicvec_key = rumble_Vectors.ToList()[i].Key;
var _dicvec = rumble_Vectors[_dicvec_key];
if (_dicvec.z < 0)
{
//Debug.Log("Removed Key : " + _dicvec_key);
rumble_Vectors.Remove(_dicvec_key);
}
else
{
var _getfloat = _dicvec.x;
var _maxfloat = maxVector.x;
maxVector.x = _getfloat > _maxfloat ? _getfloat : _maxfloat;
_getfloat = _dicvec.y;
_maxfloat = maxVector.y;
maxVector.y = _getfloat > _maxfloat ? _getfloat : _maxfloat;
_getfloat = _dicvec.z;
_maxfloat = maxVector.z;
maxVector.z = _getfloat > _maxfloat ? _getfloat : _maxfloat;
_dicvec.z -= _dicvec.w == 1 ? 0 : Time.deltaTime;
rumble_Vectors[_dicvec_key] = _dicvec;
}
}
}
pad.SetMotorSpeeds(maxVector.x, maxVector.y);
}
}
private IEnumerator StopRumble(float duration, Gamepad pad)
{
float elapsedTime = 0f;
while(elapsedTime < duration)
{
elapsedTime += Time.deltaTime;
yield return null;
}
pad.SetMotorSpeeds(0f,0f);
}
}
구현은 쉽게 하실테지만 귀찮음을 덜어드리겠습미다.
그럼 그 마우스 위치를 var _vmousepos = Camera.main.ScreenToWorldPoint(vmous.position.value); 로 받아올 수 있어요
이제 그 마우스 위치부터 제 위치까지 쭉 RayCastHit2D[] _hit = Physics2D.CircleCastAll(....)을 사용하면
이래도 패드 유저들은 난이도가 높을 것 같아서 걱정이네요...
게임의 데모분량만큼 나왔다고 생각해서 신청해봤는데 붙여주셨어요.
미리 붙었다고 말하면 기다리실수도 있을 것 같아서 말 안하고 있었어요ㅋㅋ..
댓글 영역
획득법
① NFT 발행
작성한 게시물을 NFT로 발행하면 일주일 동안 사용할 수 있습니다. (최초 1회)
② NFT 구매
다른 이용자의 NFT를 구매하면 한 달 동안 사용할 수 있습니다. (구매 시마다 갱신)
사용법
디시콘에서지갑연결시 바로 사용 가능합니다.