Верстка и скриптинг сигнальной кнопки

This commit is contained in:
Сергей Бондарь 2026-08-20 14:57:04 +03:00
parent c3dca37c70
commit ddd39a7624
18 changed files with 500 additions and 43 deletions

49
Assets/MSignalButton.cs Normal file
View File

@ -0,0 +1,49 @@
using DG.Tweening;
using System;
using UnityEngine;
using UnityEngine.UI;
public class MSignalButton : MonoBehaviour
{
public event Action OnClick;
[SerializeField] private Image _image;
[SerializeField] private Color _normalColor;
[SerializeField] private Color _pressedColor;
[SerializeField] private AudioClip _clip;
private bool _lastPressed = false;
private Sequence _animation;
public void TakeInput(bool pressed)
{
if (_lastPressed != pressed)
{
if (pressed)
{
OnClick?.Invoke();
PlayAnimation();
}
_lastPressed = pressed;
}
}
public void PlayAnimation()
{
if (_animation != null)
{
_animation.Kill();
_animation = null;
}
_animation = DOTween.Sequence();
_animation.Append(_image.DOColor(_pressedColor, 0.1f));
_animation.AppendCallback(() => SoundManager.instance.playClip(_clip));
_animation.Append(_image.DOColor(_normalColor, 0.1f));
_animation.PlayForward();
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 6422f146b37ef714db72d2550697c362

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fcd09f3d8d0189146aa944165564dd1a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,186 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &87492550789449837
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1494698429595343414}
- component: {fileID: 7426346546271364008}
- component: {fileID: 5705755200995082994}
m_Layer: 5
m_Name: SignalSetting
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1494698429595343414
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 87492550789449837}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 9159338027149713966}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 891.44995, y: 38.25}
m_Pivot: {x: 0, y: 1}
--- !u!222 &7426346546271364008
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 87492550789449837}
m_CullTransparentMesh: 1
--- !u!114 &5705755200995082994
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 87492550789449837}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0ac5ce41d41becf4db103a3b68f7ccf0, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::SignalView
_settingNameLabel: {fileID: 1890240610685982407}
_signalButton: {fileID: 6034858491677103217}
--- !u!1001 &520807226183219737
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 1494698429595343414}
m_Modifications:
- target: {fileID: 3568601542204023552, guid: c244207dd10914141af206f200c91b0a, type: 3}
propertyPath: m_Name
value: SignalButton
objectReference: {fileID: 0}
- target: {fileID: 8657825045506627639, guid: c244207dd10914141af206f200c91b0a, type: 3}
propertyPath: m_Pivot.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 8657825045506627639, guid: c244207dd10914141af206f200c91b0a, type: 3}
propertyPath: m_Pivot.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 8657825045506627639, guid: c244207dd10914141af206f200c91b0a, type: 3}
propertyPath: m_AnchorMax.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 8657825045506627639, guid: c244207dd10914141af206f200c91b0a, type: 3}
propertyPath: m_AnchorMax.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 8657825045506627639, guid: c244207dd10914141af206f200c91b0a, type: 3}
propertyPath: m_AnchorMin.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 8657825045506627639, guid: c244207dd10914141af206f200c91b0a, type: 3}
propertyPath: m_AnchorMin.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 8657825045506627639, guid: c244207dd10914141af206f200c91b0a, type: 3}
propertyPath: m_SizeDelta.x
value: 321.29
objectReference: {fileID: 0}
- target: {fileID: 8657825045506627639, guid: c244207dd10914141af206f200c91b0a, type: 3}
propertyPath: m_SizeDelta.y
value: 54.02
objectReference: {fileID: 0}
- target: {fileID: 8657825045506627639, guid: c244207dd10914141af206f200c91b0a, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8657825045506627639, guid: c244207dd10914141af206f200c91b0a, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8657825045506627639, guid: c244207dd10914141af206f200c91b0a, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8657825045506627639, guid: c244207dd10914141af206f200c91b0a, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8657825045506627639, guid: c244207dd10914141af206f200c91b0a, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8657825045506627639, guid: c244207dd10914141af206f200c91b0a, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8657825045506627639, guid: c244207dd10914141af206f200c91b0a, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8657825045506627639, guid: c244207dd10914141af206f200c91b0a, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8657825045506627639, guid: c244207dd10914141af206f200c91b0a, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8657825045506627639, guid: c244207dd10914141af206f200c91b0a, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8657825045506627639, guid: c244207dd10914141af206f200c91b0a, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8657825045506627639, guid: c244207dd10914141af206f200c91b0a, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: c244207dd10914141af206f200c91b0a, type: 3}
--- !u!114 &1890240610685982407 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 2090018479069457630, guid: c244207dd10914141af206f200c91b0a, type: 3}
m_PrefabInstance: {fileID: 520807226183219737}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier: Unity.TextMeshPro::TMPro.TextMeshProUGUI
--- !u!114 &6034858491677103217 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 6123304204807351912, guid: c244207dd10914141af206f200c91b0a, type: 3}
m_PrefabInstance: {fileID: 520807226183219737}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6422f146b37ef714db72d2550697c362, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::MSignalButton
--- !u!224 &9159338027149713966 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 8657825045506627639, guid: c244207dd10914141af206f200c91b0a, type: 3}
m_PrefabInstance: {fileID: 520807226183219737}
m_PrefabAsset: {fileID: 0}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 2c8bfc2a5cf808441b0358fe6324fc11
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,57 +1,21 @@
using System;
using UnityEngine;
using UnityEngine.UI;
public class SignalView : BaseSettingView
{
public static event Action<string> SignalEmmited;
[Header("Layout ссылки")]
[SerializeField] private Image ButtonImage;
[Header("Настройки анимации")]
[SerializeField] private Color ButtonColorPressed;
[SerializeField] private Color ButtonColorNormal;
[Header("Звуки")]
[SerializeField] private AudioClip AcceptedClip;
[SerializeField] private MSignalButton _signalButton;
private string signal;
private bool pressed;
private bool acted = false;
public override void Initialize(SettingDTO setting)
{
base.Initialize(setting);
signal = setting.SignalValue;
_signalButton.OnClick += EmitSignal;
}
public override void TakeInput(int _, bool action)
{
pressed = action;
}
public override void TakeInput(int _, bool action) => _signalButton.TakeInput(action);
private void LateUpdate()
{
Display();
if (pressed && !acted)
EmmitSignal();
if(!pressed && acted)
acted = false;
}
private void Display()
{
ButtonImage.color = pressed ? ButtonColorPressed : ButtonColorNormal;
}
private void EmmitSignal()
{
acted = true;
SoundManager.instance.playClip(AcceptedClip);
SignalEmmited?.Invoke(signal);
}
}
private void EmitSignal() => SignalEmmited?.Invoke(signal);
}

View File

@ -16,4 +16,4 @@ MonoBehaviour:
intView: {fileID: 8208155087606663890, guid: 4958128c98f1ac249ae15d1b0f9ab888, type: 3}
floatView: {fileID: 6349691222830257612, guid: cc871af4efc773343800f9ca7503f0cc, type: 3}
stringView: {fileID: 3290846134693264660, guid: 0ee3a3a6908b93042919767f25e1b4e7, type: 3}
signalView: {fileID: 0}
signalView: {fileID: 5705755200995082994, guid: 2c8bfc2a5cf808441b0358fe6324fc11, type: 3}

234
Assets/SignalButton.prefab Normal file
View File

@ -0,0 +1,234 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &264899321274819122
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8956293476614556395}
- component: {fileID: 6995531981089011483}
- component: {fileID: 2090018479069457630}
m_Layer: 5
m_Name: Text (TMP)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &8956293476614556395
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 264899321274819122}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8657825045506627639}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: -50, y: -10}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &6995531981089011483
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 264899321274819122}
m_CullTransparentMesh: 1
--- !u!114 &2090018479069457630
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 264899321274819122}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier: Unity.TextMeshPro::TMPro.TextMeshProUGUI
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: "\u0421\u0431\u0440\u043E\u0441\u0438\u0442\u044C \u0432\u044B\u0434\u0430\u0447\u0443
\u0432\u044B\u0434\u0430\u0447\u0438 \u043F\u043E\u0434\u0432\u044B\u0434\u0430\u0447\u0438
\u0432\u044B\u0434\u0430\u0447\u0435\u0439 \u0432\u0441\u0435\u044A \u0432\u044B\u0434\u0430\u0447"
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 35bb1c004e5e55c4daaacc21b74e1741, type: 2}
m_sharedMaterial: {fileID: 4824725623324572421, guid: 35bb1c004e5e55c4daaacc21b74e1741, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4278190080
m_fontColor: {r: 0, g: 0, b: 0, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 20.05
m_fontSizeBase: 35
m_fontWeight: 400
m_enableAutoSizing: 1
m_fontSizeMin: 16
m_fontSizeMax: 35
m_fontStyle: 0
m_HorizontalAlignment: 2
m_VerticalAlignment: 512
m_textAlignment: 65535
m_characterSpacing: 0
m_characterHorizontalScale: 1
m_wordSpacing: 0
m_lineSpacing: 0
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_TextWrappingMode: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 0
m_ActiveFontFeatures: 6e72656b
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_EmojiFallbackSupport: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 1
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: 0, w: 0}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!1 &3568601542204023552
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8657825045506627639}
- component: {fileID: 2293965002738895521}
- component: {fileID: 3946266212054413381}
- component: {fileID: 6123304204807351912}
m_Layer: 5
m_Name: SignalButton
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &8657825045506627639
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3568601542204023552}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 8956293476614556395}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 321.29, y: 54.02}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &2293965002738895521
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3568601542204023552}
m_CullTransparentMesh: 1
--- !u!114 &3946266212054413381
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3568601542204023552}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier: UnityEngine.UI::UnityEngine.UI.Image
m_Material: {fileID: 0}
m_Color: {r: 0.972549, g: 0.91764706, b: 0.23529412, a: 1}
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 0
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: -8496147902177969847, guid: cf234dbb1551ec647959db3ae7c0a6b5, type: 3}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 4
--- !u!114 &6123304204807351912
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3568601542204023552}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6422f146b37ef714db72d2550697c362, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::MSignalButton
_image: {fileID: 3946266212054413381}
_normalColor: {r: 0.972549, g: 0.91764706, b: 0.23529412, a: 1}
_pressedColor: {r: 0.6301887, g: 0.5941508, b: 0.14625129, a: 1}
_clip: {fileID: 8300000, guid: 1c48900c9ab0aa8418920a8193050870, type: 3}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c244207dd10914141af206f200c91b0a
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -315,7 +315,7 @@ TextureImporter:
height: 219
alignment: 0
pivot: {x: 0.5, y: 0.5}
border: {x: 0, y: 0, z: 0, w: 0}
border: {x: 89, y: 0, z: 89, w: 0}
customData:
outline: []
physicsShape: []