Доработка TakeOrRiskPanel

This commit is contained in:
se_ga 2026-04-02 13:29:59 +03:00
parent f1df0b2530
commit fb0bfc9d25
6 changed files with 351 additions and 57 deletions

View File

@ -11349,7 +11349,7 @@ Material:
- _ClipRect: {r: -32767, g: -32767, b: 32767, a: 32767}
- _EnvMatrixRotation: {r: 0, g: 0, b: 0, a: 0}
- _FaceColor: {r: 1, g: 1, b: 1, a: 1}
- _GlowColor: {r: 0, g: 0.8390024, b: 1, a: 1}
- _GlowColor: {r: 0, g: 1, b: 0.18946743, a: 1}
- _MaskCoord: {r: 0, g: 0, b: 32767, a: 32767}
- _OutlineColor: {r: 0.554717, g: 0.554717, b: 0.554717, a: 1}
- _ReflectFaceColor: {r: 0, g: 0, b: 0, a: 1}

View File

@ -34084,6 +34084,119 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1080949051}
m_CullTransparentMesh: 1
--- !u!1001 &1083634611
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 2720328458227109517}
m_Modifications:
- target: {fileID: 2875758851730211012, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_Name
value: PrizeView
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_Pivot.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_Pivot.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_AnchorMax.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_AnchorMax.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_AnchorMin.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_AnchorMin.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_SizeDelta.x
value: 350
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_SizeDelta.y
value: 350
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
--- !u!224 &1083634612 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
m_PrefabInstance: {fileID: 1083634611}
m_PrefabAsset: {fileID: 0}
--- !u!114 &1083634613 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 1203032466002125781, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
m_PrefabInstance: {fileID: 1083634611}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 006a8f6ee593bb94d96ebb190f38e418, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::PrizeView
--- !u!1 &1084639303
GameObject:
m_ObjectHideFlags: 0
@ -58187,6 +58300,119 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1985746125
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 8549428697360486891}
m_Modifications:
- target: {fileID: 2875758851730211012, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_Name
value: PrizeView
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_Pivot.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_Pivot.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_AnchorMax.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_AnchorMax.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_AnchorMin.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_AnchorMin.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_SizeDelta.x
value: 350
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_SizeDelta.y
value: 350
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
--- !u!224 &1985746126 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 4769901412115232176, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
m_PrefabInstance: {fileID: 1985746125}
m_PrefabAsset: {fileID: 0}
--- !u!114 &1985746127 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 1203032466002125781, guid: f8172e74629723c4e993e8ac2f322bdf, type: 3}
m_PrefabInstance: {fileID: 1985746125}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 006a8f6ee593bb94d96ebb190f38e418, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::PrizeView
--- !u!1 &1997844673
GameObject:
m_ObjectHideFlags: 0
@ -68180,7 +68406,8 @@ RectTransform:
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Children:
- {fileID: 1083634612}
m_Father: {fileID: 7072048023201074136}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
@ -74964,10 +75191,12 @@ MonoBehaviour:
m_EditorClassIdentifier: Assembly-CSharp::TakeOrRiskPanel
CurrentPrizeFrame: {fileID: 2944032316663602777}
NextPrizeFrame: {fileID: 1501477561599320377}
CurrentPrizeView: {fileID: 1985746127}
NextPrizeView: {fileID: 1083634613}
DisabledColor: {r: 0.16981131, g: 0.16981131, b: 0.16981131, a: 1}
HSV_speed: 0.3
HsvSpeed: 0.3
TimerRing: {fileID: 3146362536925492841}
timerFillCurve:
TimerFillCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
@ -74991,6 +75220,10 @@ MonoBehaviour:
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
TimeToAccept: 2
ScalingSpeed: 1
SelectedScale: 1.05
IdleScale: 0.95
--- !u!114 &7987471542231822866
MonoBehaviour:
m_ObjectHideFlags: 0
@ -75460,7 +75693,8 @@ RectTransform:
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Children:
- {fileID: 1985746126}
m_Father: {fileID: 7072048023201074136}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}

View File

@ -19,6 +19,11 @@ public class PrizeView : MonoBehaviour
_label.text = GetText(prize);
}
public void Clear()
{
_image.sprite = null;
_label.text = "";
}

View File

@ -0,0 +1,5 @@
public enum TakeOrRiskOption
{
Take,
Risk
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a9370e38099c787468dae572b24b0401
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,73 +1,112 @@
using Newtonsoft.Json.Linq;
using System;
using UnityEngine;
using UnityEngine.UI;
public class TakeOrRiskPanel : MonoBehaviour
namespace PrizeSystem
{
[SerializeField] Image CurrentPrizeFrame;
[SerializeField] Image NextPrizeFrame;
[SerializeField] private Color DisabledColor;
[SerializeField] float HSV_speed = 2;
[SerializeField] private Image TimerRing;
[SerializeField] private AnimationCurve timerFillCurve;
private Image activeFrame;
private Image inactiveFrame;
private int index = 0;
private float acceptTimer = 0;
private void OnEnable()
public class TakeOrRiskPanel : MonoBehaviour
{
activeFrame = CurrentPrizeFrame;
inactiveFrame = NextPrizeFrame;
index = 0;
}
[Header("Ссылки на панели")]
[SerializeField] private Image CurrentPrizeFrame;
[SerializeField] private Image NextPrizeFrame;
[SerializeField] private PrizeView CurrentPrizeView;
[SerializeField] private PrizeView NextPrizeView;
[Header("Цветовая анимация")]
[SerializeField] private Color DisabledColor;
[SerializeField] float HsvSpeed = 0.3f;
void Update()
{
// добавить скалирование
//подсветку на кнопку принять
[Header("Настройка таймера")]
[SerializeField] private Image TimerRing;
[SerializeField] private AnimationCurve TimerFillCurve;
[SerializeField] private float TimeToAccept = 2;
ProcessInput();
DisplayGraphics();
[Header("Анимация размера панелей")]
[SerializeField] private float ScalingSpeed = 1;
[SerializeField] private float SelectedScale = 1.05f;
[SerializeField] private float IdleScale = 0.95f;
private TakeOrRiskOption SelectedOption;
public event Action<TakeOrRiskOption> OnComplete;
}
private Image activeFrame;
private Image inactiveFrame;
private float acceptTimer = 0;
private void ProcessInput()
{
if (In.GetButtonAnyPlayer(PlayerAction.left)) index = 0;
if (In.GetButtonAnyPlayer(PlayerAction.right)) index = 1;
if (index == 0)
private void OnEnable()
{
SelectedOption = TakeOrRiskOption.Take;
activeFrame = CurrentPrizeFrame;
inactiveFrame = NextPrizeFrame;
acceptTimer = 0;
}
else
private void OnDisable()
{
activeFrame = NextPrizeFrame;
inactiveFrame = CurrentPrizeFrame;
ClearPrizes();
}
void Update()
{
var inputs = ProcessInput();
UpdateState(inputs.selectedOption, inputs.timerDelta);
DisplayGraphics();
}
acceptTimer += Time.deltaTime * (In.GetButtonAnyPlayer(PlayerAction.down) ? 1 : -1);
acceptTimer = Mathf.Clamp01(acceptTimer);
public void SetPrizes(Prize CurrentPrize, Prize NextPrize)
{
CurrentPrizeView.SetPrize(CurrentPrize);
NextPrizeView.SetPrize(NextPrize);
}
private void ClearPrizes()
{
CurrentPrizeView.Clear();
NextPrizeView.Clear();
}
private (TakeOrRiskOption selectedOption, float timerDelta) ProcessInput()
{
if (In.GetButtonAnyPlayer(PlayerAction.left))
SelectedOption = TakeOrRiskOption.Take;
if (In.GetButtonAnyPlayer(PlayerAction.right))
SelectedOption = TakeOrRiskOption.Risk;
float timerDelta = Time.deltaTime * (In.GetButtonAnyPlayer(PlayerAction.down) ? 1 : -1);
return (SelectedOption, timerDelta);
}
private void UpdateState(TakeOrRiskOption selectedOption, float timerDelta)
{
activeFrame = selectedOption == TakeOrRiskOption.Take ? CurrentPrizeFrame : NextPrizeFrame;
inactiveFrame = selectedOption == TakeOrRiskOption.Take ? NextPrizeFrame : CurrentPrizeFrame;
acceptTimer = Mathf.Clamp(acceptTimer + timerDelta, 0, TimeToAccept);
if (acceptTimer >= TimeToAccept) Accept();
}
private void DisplayGraphics()
{
// Скалирование
activeFrame.transform.localScale = Vector2.MoveTowards(activeFrame.transform.localScale, Vector2.one * SelectedScale, Time.deltaTime * ScalingSpeed);
inactiveFrame.transform.localScale = Vector2.MoveTowards(inactiveFrame.transform.localScale, Vector2.one * IdleScale, Time.deltaTime * ScalingSpeed);
//Цвет рамки
float hue = (Time.time * HsvSpeed) % 1f;
activeFrame.color = Color.HSVToRGB(hue, 1, 1);
inactiveFrame.color = DisabledColor;
//Круговой таймер
float timerPercent = acceptTimer / TimeToAccept;
TimerRing.fillAmount = TimerFillCurve.Evaluate(timerPercent);
}
private void Accept()
{
OnComplete?.Invoke(SelectedOption);
gameObject.SetActive(false);
}
}
private void DisplayGraphics()
{
float hue = (Time.time * HSV_speed) % 1f;
activeFrame.color = Color.HSVToRGB(hue, 1, 1);
inactiveFrame.color = DisabledColor;
TimerRing.fillAmount = timerFillCurve.Evaluate(acceptTimer);
}
}