조이스틱 동작 액션 수정
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class CharacterController : MonoBehaviour
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1e5d5ec74000134290431a712ebd683
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class EventSystemManager : MonoBehaviour
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab66d818efcc9d44da8900e18fef96e0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -8,6 +8,7 @@ namespace TON
|
||||
{
|
||||
public virtual void Show()
|
||||
{
|
||||
Instantiate(Resources.Load("EventSystem/Prefabs/TON.EventSystem"));
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace TON
|
||||
|
||||
TitleUI,
|
||||
IngameUI,
|
||||
ControllerUI,
|
||||
LogUI,
|
||||
|
||||
|
||||
|
||||
8
Gameton-06/Assets/Gameton/Scripts/Joystick.meta
Normal file
8
Gameton-06/Assets/Gameton/Scripts/Joystick.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd3d417ffc2079a4d93186904952ddd9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
153
Gameton-06/Assets/Gameton/Scripts/Joystick/Joystick.cs
Normal file
153
Gameton-06/Assets/Gameton/Scripts/Joystick/Joystick.cs
Normal file
@@ -0,0 +1,153 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class Joystick : MonoBehaviour, IPointerDownHandler, IDragHandler, IPointerUpHandler
|
||||
{
|
||||
public float Horizontal { get { return (snapX) ? SnapFloat(input.x, AxisOptions.Horizontal) : input.x; } }
|
||||
public float Vertical { get { return (snapY) ? SnapFloat(input.y, AxisOptions.Vertical) : input.y; } }
|
||||
public Vector2 Direction { get { return new Vector2(Horizontal, Vertical); } }
|
||||
|
||||
public float HandleRange
|
||||
{
|
||||
get { return handleRange; }
|
||||
set { handleRange = Mathf.Abs(value); }
|
||||
}
|
||||
|
||||
public float DeadZone
|
||||
{
|
||||
get { return deadZone; }
|
||||
set { deadZone = Mathf.Abs(value); }
|
||||
}
|
||||
|
||||
public AxisOptions AxisOptions { get { return AxisOptions; } set { axisOptions = value; } }
|
||||
public bool SnapX { get { return snapX; } set { snapX = value; } }
|
||||
public bool SnapY { get { return snapY; } set { snapY = value; } }
|
||||
|
||||
[SerializeField] private float handleRange = 1;
|
||||
[SerializeField] private float deadZone = 0;
|
||||
[SerializeField] private AxisOptions axisOptions = AxisOptions.Both;
|
||||
[SerializeField] private bool snapX = false;
|
||||
[SerializeField] private bool snapY = false;
|
||||
|
||||
[SerializeField] protected RectTransform background = null;
|
||||
[SerializeField] private RectTransform handle = null;
|
||||
private RectTransform baseRect = null;
|
||||
|
||||
private Canvas canvas;
|
||||
private Camera cam;
|
||||
|
||||
private Vector2 input = Vector2.zero;
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
HandleRange = handleRange;
|
||||
DeadZone = deadZone;
|
||||
baseRect = GetComponent<RectTransform>();
|
||||
canvas = GetComponentInParent<Canvas>();
|
||||
if (canvas == null)
|
||||
Debug.LogError("The Joystick is not placed inside a canvas");
|
||||
|
||||
Vector2 center = new Vector2(0.5f, 0.5f);
|
||||
background.pivot = center;
|
||||
handle.anchorMin = center;
|
||||
handle.anchorMax = center;
|
||||
handle.pivot = center;
|
||||
handle.anchoredPosition = Vector2.zero;
|
||||
}
|
||||
|
||||
public virtual void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
OnDrag(eventData);
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
cam = null;
|
||||
if (canvas.renderMode == RenderMode.ScreenSpaceCamera)
|
||||
cam = canvas.worldCamera;
|
||||
|
||||
Vector2 position = RectTransformUtility.WorldToScreenPoint(cam, background.position);
|
||||
Vector2 radius = background.sizeDelta / 2;
|
||||
input = (eventData.position - position) / (radius * canvas.scaleFactor);
|
||||
FormatInput();
|
||||
HandleInput(input.magnitude, input.normalized, radius, cam);
|
||||
handle.anchoredPosition = input * radius * handleRange;
|
||||
}
|
||||
|
||||
protected virtual void HandleInput(float magnitude, Vector2 normalised, Vector2 radius, Camera cam)
|
||||
{
|
||||
if (magnitude > deadZone)
|
||||
{
|
||||
if (magnitude > 1)
|
||||
input = normalised;
|
||||
}
|
||||
else
|
||||
input = Vector2.zero;
|
||||
}
|
||||
|
||||
private void FormatInput()
|
||||
{
|
||||
if (axisOptions == AxisOptions.Horizontal)
|
||||
input = new Vector2(input.x, 0f);
|
||||
else if (axisOptions == AxisOptions.Vertical)
|
||||
input = new Vector2(0f, input.y);
|
||||
}
|
||||
|
||||
private float SnapFloat(float value, AxisOptions snapAxis)
|
||||
{
|
||||
if (value == 0)
|
||||
return value;
|
||||
|
||||
if (axisOptions == AxisOptions.Both)
|
||||
{
|
||||
float angle = Vector2.Angle(input, Vector2.up);
|
||||
if (snapAxis == AxisOptions.Horizontal)
|
||||
{
|
||||
if (angle < 22.5f || angle > 157.5f)
|
||||
return 0;
|
||||
else
|
||||
return (value > 0) ? 1 : -1;
|
||||
}
|
||||
else if (snapAxis == AxisOptions.Vertical)
|
||||
{
|
||||
if (angle > 67.5f && angle < 112.5f)
|
||||
return 0;
|
||||
else
|
||||
return (value > 0) ? 1 : -1;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value > 0)
|
||||
return 1;
|
||||
if (value < 0)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public virtual void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
input = Vector2.zero;
|
||||
handle.anchoredPosition = Vector2.zero;
|
||||
}
|
||||
|
||||
protected Vector2 ScreenPointToAnchoredPosition(Vector2 screenPosition)
|
||||
{
|
||||
Vector2 localPoint = Vector2.zero;
|
||||
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(baseRect, screenPosition, cam, out localPoint))
|
||||
{
|
||||
Vector2 pivotOffset = baseRect.pivot * baseRect.sizeDelta;
|
||||
return localPoint - (background.anchorMax * baseRect.sizeDelta) + pivotOffset;
|
||||
}
|
||||
return Vector2.zero;
|
||||
}
|
||||
}
|
||||
|
||||
public enum AxisOptions { Both, Horizontal, Vertical }
|
||||
}
|
||||
11
Gameton-06/Assets/Gameton/Scripts/Joystick/Joystick.cs.meta
Normal file
11
Gameton-06/Assets/Gameton/Scripts/Joystick/Joystick.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5efeced8004470438cbd7c383b2a09e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,63 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class VariableJoystick : Joystick
|
||||
{
|
||||
public float MoveThreshold { get { return moveThreshold; } set { moveThreshold = Mathf.Abs(value); } }
|
||||
|
||||
[SerializeField] private float moveThreshold = 1;
|
||||
[SerializeField] private JoystickType joystickType = JoystickType.Fixed;
|
||||
|
||||
private Vector2 fixedPosition = Vector2.zero;
|
||||
|
||||
public void SetMode(JoystickType joystickType)
|
||||
{
|
||||
this.joystickType = joystickType;
|
||||
if (joystickType == JoystickType.Fixed)
|
||||
{
|
||||
background.anchoredPosition = fixedPosition;
|
||||
background.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
background.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
fixedPosition = background.anchoredPosition;
|
||||
SetMode(joystickType);
|
||||
}
|
||||
|
||||
public override void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
if (joystickType != JoystickType.Fixed)
|
||||
{
|
||||
background.anchoredPosition = ScreenPointToAnchoredPosition(eventData.position);
|
||||
background.gameObject.SetActive(true);
|
||||
}
|
||||
base.OnPointerDown(eventData);
|
||||
}
|
||||
|
||||
public override void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
if (joystickType != JoystickType.Fixed)
|
||||
background.gameObject.SetActive(false);
|
||||
|
||||
base.OnPointerUp(eventData);
|
||||
}
|
||||
|
||||
protected override void HandleInput(float magnitude, Vector2 normalised, Vector2 radius, Camera cam)
|
||||
{
|
||||
if (joystickType == JoystickType.Dynamic && magnitude > moveThreshold)
|
||||
{
|
||||
Vector2 difference = normalised * (magnitude - moveThreshold) * radius;
|
||||
background.anchoredPosition += difference;
|
||||
}
|
||||
base.HandleInput(magnitude, normalised, radius, cam);
|
||||
}
|
||||
}
|
||||
|
||||
public enum JoystickType { Fixed, Floating, Dynamic }
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e4c9f0304835c834382ad094ec9ab02a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Gameton-06/Assets/Gameton/Scripts/UI/ControllerUI.cs
Normal file
17
Gameton-06/Assets/Gameton/Scripts/UI/ControllerUI.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class ControllerUI : UIBase
|
||||
{
|
||||
public static ControllerUI Instance => UIManager.Singleton.GetUI<ControllerUI>(UIList.ControllerUI);
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Gameton-06/Assets/Gameton/Scripts/UI/ControllerUI.cs.meta
Normal file
11
Gameton-06/Assets/Gameton/Scripts/UI/ControllerUI.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3675204183f70fb48a77841d2b9055f4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user