joystick pack assets 추가
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class DynamicJoystick : Joystick
|
||||
{
|
||||
public float MoveThreshold { get { return moveThreshold; } set { moveThreshold = Mathf.Abs(value); } }
|
||||
|
||||
[SerializeField] private float moveThreshold = 1;
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
MoveThreshold = moveThreshold;
|
||||
base.Start();
|
||||
background.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public override void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
background.anchoredPosition = ScreenPointToAnchoredPosition(eventData.position);
|
||||
background.gameObject.SetActive(true);
|
||||
base.OnPointerDown(eventData);
|
||||
}
|
||||
|
||||
public override void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
background.gameObject.SetActive(false);
|
||||
base.OnPointerUp(eventData);
|
||||
}
|
||||
|
||||
protected override void HandleInput(float magnitude, Vector2 normalised, Vector2 radius, Camera cam)
|
||||
{
|
||||
if (magnitude > moveThreshold)
|
||||
{
|
||||
Vector2 difference = normalised * (magnitude - moveThreshold) * radius;
|
||||
background.anchoredPosition += difference;
|
||||
}
|
||||
base.HandleInput(magnitude, normalised, radius, cam);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba0d0e7a039f526499c356a3c5cd6d3f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FixedJoystick : Joystick
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 45977bbae16431c46a013576a1aea384
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class FloatingJoystick : Joystick
|
||||
{
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
background.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public override void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
background.anchoredPosition = ScreenPointToAnchoredPosition(eventData.position);
|
||||
background.gameObject.SetActive(true);
|
||||
base.OnPointerDown(eventData);
|
||||
}
|
||||
|
||||
public override void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
background.gameObject.SetActive(false);
|
||||
base.OnPointerUp(eventData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a47f546fc70ec8428172694e78e4288
|
||||
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: 42844a4fccbd54746b90cade4ff70f73
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user