1.2. Джойстики движения и атаки: Сделан возврат джойстиков в исходную позицию на канвасе, когда игрок убирает с них палец
This commit is contained in:
parent
fa354c1140
commit
b9ca80b5d6
@ -36,6 +36,8 @@ public class Joystick : MonoBehaviour, IPointerDownHandler, IDragHandler, IPoint
|
||||
|
||||
[SerializeField] protected RectTransform background = null;
|
||||
[SerializeField] protected RectTransform handle = null;
|
||||
|
||||
[SerializeField] private bool backToStartOnTouchUp;
|
||||
|
||||
private RectTransform baseRect = null;
|
||||
|
||||
@ -44,6 +46,8 @@ public class Joystick : MonoBehaviour, IPointerDownHandler, IDragHandler, IPoint
|
||||
|
||||
private Vector2 input = Vector2.zero;
|
||||
|
||||
private Vector2 startPosition;
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
//IsTouchedUP = true;
|
||||
@ -60,6 +64,8 @@ public class Joystick : MonoBehaviour, IPointerDownHandler, IDragHandler, IPoint
|
||||
handle.anchorMax = center;
|
||||
handle.pivot = center;
|
||||
handle.anchoredPosition = Vector2.zero;
|
||||
|
||||
startPosition = background.anchoredPosition;
|
||||
}
|
||||
|
||||
public virtual void OnPointerDown(PointerEventData eventData)
|
||||
@ -140,6 +146,10 @@ public class Joystick : MonoBehaviour, IPointerDownHandler, IDragHandler, IPoint
|
||||
input = Vector2.zero;
|
||||
handle.anchoredPosition = Vector2.zero;
|
||||
OnTouchUp?.Invoke();
|
||||
if (backToStartOnTouchUp)
|
||||
{
|
||||
MoveBackToStartPosition();
|
||||
}
|
||||
}
|
||||
|
||||
protected Vector2 ScreenPointToAnchoredPosition(Vector2 screenPosition)
|
||||
@ -152,6 +162,11 @@ public class Joystick : MonoBehaviour, IPointerDownHandler, IDragHandler, IPoint
|
||||
}
|
||||
return Vector2.zero;
|
||||
}
|
||||
|
||||
private void MoveBackToStartPosition()
|
||||
{
|
||||
background.anchoredPosition = startPosition;
|
||||
}
|
||||
}
|
||||
|
||||
public enum AxisOptions { Both, Horizontal, Vertical }
|
@ -13,6 +13,7 @@ public class JoystickEditor : Editor
|
||||
private SerializedProperty snapY;
|
||||
protected SerializedProperty background;
|
||||
private SerializedProperty handle;
|
||||
private SerializedProperty backToStartOnTouchUp;
|
||||
|
||||
protected Vector2 center = new Vector2(0.5f, 0.5f);
|
||||
|
||||
@ -25,6 +26,7 @@ public class JoystickEditor : Editor
|
||||
snapY = serializedObject.FindProperty("snapY");
|
||||
background = serializedObject.FindProperty("background");
|
||||
handle = serializedObject.FindProperty("handle");
|
||||
backToStartOnTouchUp = serializedObject.FindProperty("backToStartOnTouchUp");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
@ -54,6 +56,7 @@ public class JoystickEditor : Editor
|
||||
EditorGUILayout.PropertyField(axisOptions, new GUIContent("Axis Options", "Which axes the joystick uses."));
|
||||
EditorGUILayout.PropertyField(snapX, new GUIContent("Snap X", "Snap the horizontal input to a whole value."));
|
||||
EditorGUILayout.PropertyField(snapY, new GUIContent("Snap Y", "Snap the vertical input to a whole value."));
|
||||
EditorGUILayout.PropertyField(backToStartOnTouchUp, new GUIContent("Back To Start On TouchUp", "Moves Joystic back to the start position when player stops touch it."));
|
||||
}
|
||||
|
||||
protected virtual void DrawComponents()
|
||||
|
@ -19,6 +19,7 @@ MonoBehaviour:
|
||||
snapY: 0
|
||||
background: {fileID: 1415495983658094506}
|
||||
handle: {fileID: 1415495981690910128}
|
||||
backToStartOnTouchUp: 1
|
||||
_idleStateOpacity: 0.3
|
||||
_activeStateOpacity: 1
|
||||
moveThreshold: 1
|
||||
@ -2920,6 +2921,11 @@ PrefabInstance:
|
||||
propertyPath: _idleStateOpacity
|
||||
value: 0.3
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8170153791668043265, guid: 0d230cc8be529a542a08cb878ab14b18,
|
||||
type: 3}
|
||||
propertyPath: backToStartOnTouchUp
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8170153791668043268, guid: 0d230cc8be529a542a08cb878ab14b18,
|
||||
type: 3}
|
||||
propertyPath: m_Pivot.x
|
||||
|
@ -3565,11 +3565,101 @@ PrefabInstance:
|
||||
m_Modification:
|
||||
m_TransformParent: {fileID: 0}
|
||||
m_Modifications:
|
||||
- target: {fileID: 3195387929267588557, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3195387929267588557, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3195387929267588557, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_SizeDelta.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3195387929267588557, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_SizeDelta.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3195387929267588557, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3195387929267588557, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 5557455103468811314, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: bonusController
|
||||
value:
|
||||
objectReference: {fileID: 1801060033}
|
||||
- target: {fileID: 5643681896748709694, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 5643681896748709694, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 5643681896748709694, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_SizeDelta.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 5643681896748709694, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_SizeDelta.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 5643681896748709694, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 5643681896748709694, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6305254850507510473, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6305254850507510473, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6305254850507510473, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_SizeDelta.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6305254850507510473, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_SizeDelta.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6305254850507510473, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6305254850507510473, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7117637459326710691, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_Name
|
||||
@ -3680,6 +3770,36 @@ PrefabInstance:
|
||||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8859217424454144084, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMax.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8859217424454144084, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_AnchorMin.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8859217424454144084, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_SizeDelta.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8859217424454144084, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_SizeDelta.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8859217424454144084, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8859217424454144084, guid: a72be70db1163c14b8b7a3cb1c00a59d,
|
||||
type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: a72be70db1163c14b8b7a3cb1c00a59d, type: 3}
|
||||
--- !u!1 &1129072375 stripped
|
||||
|
Loading…
x
Reference in New Issue
Block a user