Imported basic unity packages yeehaw
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class UIVirtualButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerClickHandler
|
||||
{
|
||||
|
||||
[Header("Output")]
|
||||
public UnityEvent<bool> buttonStateOutputEvent;
|
||||
public UnityEvent buttonClickOutputEvent;
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
OutputButtonStateValue(true);
|
||||
}
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
OutputButtonStateValue(false);
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
OutputButtonClickEvent();
|
||||
}
|
||||
|
||||
void OutputButtonStateValue(bool buttonState)
|
||||
{
|
||||
buttonStateOutputEvent.Invoke(buttonState);
|
||||
}
|
||||
|
||||
void OutputButtonClickEvent()
|
||||
{
|
||||
buttonClickOutputEvent.Invoke();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 448cd6d8e2f2cb04096e777d99974bc4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,114 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class UIVirtualJoystick : MonoBehaviour, IPointerDownHandler, IDragHandler, IPointerUpHandler
|
||||
{
|
||||
|
||||
|
||||
[Header("Rect References")]
|
||||
public RectTransform containerRect;
|
||||
public RectTransform handleRect;
|
||||
|
||||
[Header("Settings")]
|
||||
public float joystickRange = 50f;
|
||||
public float magnitudeMultiplier = 1f;
|
||||
public bool invertXOutputValue;
|
||||
public bool invertYOutputValue;
|
||||
|
||||
[Header("Output")]
|
||||
public UnityEvent<Vector2> joystickOutputEvent;
|
||||
|
||||
void Start()
|
||||
{
|
||||
SetupHandle();
|
||||
}
|
||||
|
||||
private void SetupHandle()
|
||||
{
|
||||
if(handleRect)
|
||||
{
|
||||
UpdateHandleRectPosition(Vector2.zero);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
OnDrag(eventData);
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(containerRect, eventData.position, eventData.pressEventCamera, out Vector2 position);
|
||||
|
||||
position = ApplySizeDelta(position);
|
||||
|
||||
Vector2 clampedPosition = ClampValuesToMagnitude(position);
|
||||
|
||||
Vector2 outputPosition = ApplyInversionFilter(position);
|
||||
|
||||
OutputPointerEventValue(outputPosition * magnitudeMultiplier);
|
||||
|
||||
if(handleRect)
|
||||
{
|
||||
UpdateHandleRectPosition(clampedPosition * joystickRange);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
OutputPointerEventValue(Vector2.zero);
|
||||
|
||||
if(handleRect)
|
||||
{
|
||||
UpdateHandleRectPosition(Vector2.zero);
|
||||
}
|
||||
}
|
||||
|
||||
private void OutputPointerEventValue(Vector2 pointerPosition)
|
||||
{
|
||||
joystickOutputEvent.Invoke(pointerPosition);
|
||||
}
|
||||
|
||||
private void UpdateHandleRectPosition(Vector2 newPosition)
|
||||
{
|
||||
handleRect.anchoredPosition = newPosition;
|
||||
}
|
||||
|
||||
Vector2 ApplySizeDelta(Vector2 position)
|
||||
{
|
||||
float x = (position.x/containerRect.sizeDelta.x) * 2.5f;
|
||||
float y = (position.y/containerRect.sizeDelta.y) * 2.5f;
|
||||
return new Vector2(x, y);
|
||||
}
|
||||
|
||||
Vector2 ClampValuesToMagnitude(Vector2 position)
|
||||
{
|
||||
return Vector2.ClampMagnitude(position, 1);
|
||||
}
|
||||
|
||||
Vector2 ApplyInversionFilter(Vector2 position)
|
||||
{
|
||||
if(invertXOutputValue)
|
||||
{
|
||||
position.x = InvertValue(position.x);
|
||||
}
|
||||
|
||||
if(invertYOutputValue)
|
||||
{
|
||||
position.y = InvertValue(position.y);
|
||||
}
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
float InvertValue(float value)
|
||||
{
|
||||
return -value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2cb8c4d669392748bb924209de33b85
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,125 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class UIVirtualTouchZone : MonoBehaviour, IPointerDownHandler, IDragHandler, IPointerUpHandler
|
||||
{
|
||||
|
||||
[Header("Rect References")]
|
||||
public RectTransform containerRect;
|
||||
public RectTransform handleRect;
|
||||
|
||||
[Header("Settings")]
|
||||
public bool clampToMagnitude;
|
||||
public float magnitudeMultiplier = 1f;
|
||||
public bool invertXOutputValue;
|
||||
public bool invertYOutputValue;
|
||||
|
||||
//Stored Pointer Values
|
||||
private Vector2 pointerDownPosition;
|
||||
private Vector2 currentPointerPosition;
|
||||
|
||||
[Header("Output")]
|
||||
public UnityEvent<Vector2> touchZoneOutputEvent;
|
||||
|
||||
void Start()
|
||||
{
|
||||
SetupHandle();
|
||||
}
|
||||
|
||||
private void SetupHandle()
|
||||
{
|
||||
if(handleRect)
|
||||
{
|
||||
SetObjectActiveState(handleRect.gameObject, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(containerRect, eventData.position, eventData.pressEventCamera, out pointerDownPosition);
|
||||
|
||||
if(handleRect)
|
||||
{
|
||||
SetObjectActiveState(handleRect.gameObject, true);
|
||||
UpdateHandleRectPosition(pointerDownPosition);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(containerRect, eventData.position, eventData.pressEventCamera, out currentPointerPosition);
|
||||
|
||||
Vector2 positionDelta = GetDeltaBetweenPositions(pointerDownPosition, currentPointerPosition);
|
||||
|
||||
Vector2 clampedPosition = ClampValuesToMagnitude(positionDelta);
|
||||
|
||||
Vector2 outputPosition = ApplyInversionFilter(clampedPosition);
|
||||
|
||||
OutputPointerEventValue(outputPosition * magnitudeMultiplier);
|
||||
}
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
pointerDownPosition = Vector2.zero;
|
||||
currentPointerPosition = Vector2.zero;
|
||||
|
||||
OutputPointerEventValue(Vector2.zero);
|
||||
|
||||
if(handleRect)
|
||||
{
|
||||
SetObjectActiveState(handleRect.gameObject, false);
|
||||
UpdateHandleRectPosition(Vector2.zero);
|
||||
}
|
||||
}
|
||||
|
||||
void OutputPointerEventValue(Vector2 pointerPosition)
|
||||
{
|
||||
touchZoneOutputEvent.Invoke(pointerPosition);
|
||||
}
|
||||
|
||||
void UpdateHandleRectPosition(Vector2 newPosition)
|
||||
{
|
||||
handleRect.anchoredPosition = newPosition;
|
||||
}
|
||||
|
||||
void SetObjectActiveState(GameObject targetObject, bool newState)
|
||||
{
|
||||
targetObject.SetActive(newState);
|
||||
}
|
||||
|
||||
Vector2 GetDeltaBetweenPositions(Vector2 firstPosition, Vector2 secondPosition)
|
||||
{
|
||||
return secondPosition - firstPosition;
|
||||
}
|
||||
|
||||
Vector2 ClampValuesToMagnitude(Vector2 position)
|
||||
{
|
||||
return Vector2.ClampMagnitude(position, 1);
|
||||
}
|
||||
|
||||
Vector2 ApplyInversionFilter(Vector2 position)
|
||||
{
|
||||
if(invertXOutputValue)
|
||||
{
|
||||
position.x = InvertValue(position.x);
|
||||
}
|
||||
|
||||
if(invertYOutputValue)
|
||||
{
|
||||
position.y = InvertValue(position.y);
|
||||
}
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
float InvertValue(float value)
|
||||
{
|
||||
return -value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 65870f34fef70aa44b0f562cfc810220
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user