1.2. Джойстики движения и атаки: Прозрачность. При нажатом alpha = 1, при отпущенном alpha = 0,3

This commit is contained in:
Maxim-Godovikov 2021-10-12 20:58:53 +03:00
parent f0f8178915
commit fa354c1140
14 changed files with 268 additions and 75 deletions

View File

@ -35,7 +35,8 @@ public class Joystick : MonoBehaviour, IPointerDownHandler, IDragHandler, IPoint
[SerializeField] private bool snapY = false;
[SerializeField] protected RectTransform background = null;
[SerializeField] private RectTransform handle = null;
[SerializeField] protected RectTransform handle = null;
private RectTransform baseRect = null;
private Canvas canvas;

View File

@ -1,10 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LoadedAssets.Joystick_Pack.Scripts.Editor;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(DynamicJoystick))]
public class DynamicJoystickEditor : JoystickEditor
public class DynamicJoystickEditor : OpacityJoystickEditor
{
private SerializedProperty moveThreshold;

View File

@ -1,10 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LoadedAssets.Joystick_Pack.Scripts.Editor;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(FloatingJoystick))]
public class FloatingJoystickEditor : JoystickEditor
public class FloatingJoystickEditor : OpacityJoystickEditor
{
public override void OnInspectorGUI()
{
@ -12,7 +11,7 @@ public class FloatingJoystickEditor : JoystickEditor
if (background != null)
{
RectTransform backgroundRect = (RectTransform)background.objectReferenceValue;
RectTransform backgroundRect = (RectTransform) background.objectReferenceValue;
backgroundRect.anchorMax = Vector2.zero;
backgroundRect.anchorMin = Vector2.zero;
backgroundRect.pivot = center;

View File

@ -0,0 +1,28 @@
using LoadedAssets.Joystick_Pack.Scripts.Joysticks;
using UnityEditor;
using UnityEngine;
namespace LoadedAssets.Joystick_Pack.Scripts.Editor
{
[CustomEditor(typeof(OpacityJoystick), true)]
public class OpacityJoystickEditor : JoystickEditor
{
private SerializedProperty _idleStateOpacity;
private SerializedProperty _activeStateOpacity;
protected override void OnEnable()
{
base.OnEnable();
_idleStateOpacity = serializedObject.FindProperty("_idleStateOpacity");
_activeStateOpacity = serializedObject.FindProperty("_activeStateOpacity");
}
protected override void DrawValues()
{
base.DrawValues();
EditorGUILayout.PropertyField(_idleStateOpacity, new GUIContent("Idle State Opacity", "Joystick opacity when player doesn't touch it."));
EditorGUILayout.PropertyField(_activeStateOpacity, new GUIContent("Active State Opacity", "Joystick opacity when player touches it."));
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5a2026769f544d69991c8dd5dc12399b
timeCreated: 1634048125

View File

@ -1,11 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using LoadedAssets.Joystick_Pack.Scripts.Editor;
using UnityEditor;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(VariableJoystick))]
public class VariableJoystickEditor : JoystickEditor
public class VariableJoystickEditor : OpacityJoystickEditor
{
private SerializedProperty moveThreshold;
private SerializedProperty joystickType;

View File

@ -1,9 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using LoadedAssets.Joystick_Pack.Scripts.Joysticks;
using UnityEngine;
using UnityEngine.EventSystems;
public class DynamicJoystick : Joystick
public class DynamicJoystick : OpacityJoystick
{
public float MoveThreshold { get { return moveThreshold; } set { moveThreshold = Mathf.Abs(value); } }
@ -13,22 +12,14 @@ public class DynamicJoystick : Joystick
{
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)

View File

@ -1,8 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LoadedAssets.Joystick_Pack.Scripts.Joysticks;
public class FixedJoystick : Joystick
public class FixedJoystick : OpacityJoystick
{
}

View File

@ -1,31 +1,11 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LoadedAssets.Joystick_Pack.Scripts.Joysticks;
using UnityEngine.EventSystems;
public class FloatingJoystick : Joystick
public class FloatingJoystick : OpacityJoystick
{
//public Action OnTouchDown, OnTouchUp;
public bool isPressed { get; set; }
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);
//OnTouchDown?.Invoke();
}
public override void OnPointerUp(PointerEventData eventData)
{
background.gameObject.SetActive(false);
base.OnPointerUp(eventData);
//OnTouchUp?.Invoke();
}
}

View File

@ -0,0 +1,62 @@
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace LoadedAssets.Joystick_Pack.Scripts.Joysticks
{
public class OpacityJoystick : Joystick
{
[SerializeField] private float _idleStateOpacity = 1f;
[SerializeField] private float _activeStateOpacity = 1f;
private Image _backgroundImage;
private Image _handleImage;
private bool _hasBackgroundImage;
private bool _hasHandleImage;
protected override void Start()
{
_backgroundImage = background.GetComponent<Image>();
_handleImage = handle.GetComponent<Image>();
_hasBackgroundImage = _backgroundImage != null;
_hasHandleImage = _handleImage != null;
SetOpacity(_idleStateOpacity);
base.Start();
}
public override void OnPointerDown(PointerEventData eventData)
{
SetOpacity(_activeStateOpacity);
base.OnPointerDown(eventData);
}
public override void OnPointerUp(PointerEventData eventData)
{
SetOpacity(_idleStateOpacity);
base.OnPointerUp(eventData);
}
private void SetOpacity(float opacity)
{
if (_hasBackgroundImage)
{
var backgroundColor = _backgroundImage.color;
backgroundColor.a = opacity;
_backgroundImage.color = backgroundColor;
}
if (_hasHandleImage)
{
var handleColor = _handleImage.color;
handleColor.a = opacity;
_handleImage.color = handleColor;
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: eb73ee9cab394bc3bdcc13b1e39be28b
timeCreated: 1634045936

View File

@ -1,9 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using LoadedAssets.Joystick_Pack.Scripts.Joysticks;
using UnityEngine;
using UnityEngine.EventSystems;
public class VariableJoystick : Joystick
public class VariableJoystick : OpacityJoystick
{
public float MoveThreshold { get { return moveThreshold; } set { moveThreshold = Mathf.Abs(value); } }

View File

@ -1,5 +1,27 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &7117637459513898660
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1415495982521125429}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ba0d0e7a039f526499c356a3c5cd6d3f, type: 3}
m_Name:
m_EditorClassIdentifier:
handleRange: 1
deadZone: 0.3
axisOptions: 0
snapX: 0
snapY: 0
background: {fileID: 1415495983658094506}
handle: {fileID: 1415495981690910128}
_idleStateOpacity: 0.3
_activeStateOpacity: 1
moveThreshold: 1
--- !u!1 &7117637457422693166
GameObject:
m_ObjectHideFlags: 0
@ -1586,26 +1608,6 @@ Animator:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorControllerStateOnDisable: 0
--- !u!114 &7117637459513898660
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1415495982521125429}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ba0d0e7a039f526499c356a3c5cd6d3f, type: 3}
m_Name:
m_EditorClassIdentifier:
handleRange: 1
deadZone: 0.3
axisOptions: 0
snapX: 0
snapY: 0
background: {fileID: 1415495983658094506}
handle: {fileID: 1415495981690910128}
moveThreshold: 1
--- !u!1 &7117637459520280379
GameObject:
m_ObjectHideFlags: 0
@ -2913,6 +2915,11 @@ PrefabInstance:
propertyPath: deadZone
value: 0.3
objectReference: {fileID: 0}
- target: {fileID: 8170153791668043265, guid: 0d230cc8be529a542a08cb878ab14b18,
type: 3}
propertyPath: _idleStateOpacity
value: 0.3
objectReference: {fileID: 0}
- target: {fileID: 8170153791668043268, guid: 0d230cc8be529a542a08cb878ab14b18,
type: 3}
propertyPath: m_Pivot.x

View File

@ -55771,11 +55771,106 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1415495983215601304, guid: a72be70db1163c14b8b7a3cb1c00a59d,
type: 3}
propertyPath: _idleStateOpacity
value: 1
objectReference: {fileID: 0}
- 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: 7117637458793366621, guid: a72be70db1163c14b8b7a3cb1c00a59d,
type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Target
@ -55911,6 +56006,36 @@ PrefabInstance:
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Target
value:
objectReference: {fileID: 185995048}
- 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 &7121823489171206717