Пофиксил баг с армией котов. Начал рефакторинг меню анимации

This commit is contained in:
_sega 2026-01-16 14:08:36 +03:00
parent fc1be019ef
commit be02b4720b
7 changed files with 259 additions and 50 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.6280117, g: 0, b: 1, a: 1}
- _GlowColor: {r: 0.33392012, g: 1, b: 0, 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

@ -23715,7 +23715,7 @@ GameObject:
m_Component:
- component: {fileID: 916045828}
- component: {fileID: 916045830}
- component: {fileID: 916045829}
- component: {fileID: 916045831}
m_Layer: 5
m_Name: Main menu
m_TagString: Untagged
@ -23746,36 +23746,6 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &916045829
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 916045827}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
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_Sprite: {fileID: 0}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &916045830
CanvasRenderer:
m_ObjectHideFlags: 0
@ -23784,6 +23754,35 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 916045827}
m_CullTransparentMesh: 1
--- !u!114 &916045831
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 916045827}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dfb30f3a8a5e4b14c8105d4176f4594b, type: 3}
m_Name:
m_EditorClassIdentifier:
blockMoveDuration: 0.6
TopContainer: {fileID: 0}
TopGameplayOffset: {x: 0, y: 0}
BottomContainer: {fileID: 0}
BottomGameplayOffset: {x: 0, y: 0}
PveContainer: {fileID: 0}
PveGameplayOffset: {x: 0, y: 0}
PvpContainer: {fileID: 0}
PvpGameplayOffset: {x: 0, y: 0}
PrizesOut: {fileID: 0}
PrizesOutGameplayOffset: {x: 0, y: 0}
PrizesOutGameplayPosition: {x: 0, y: 0}
PrizesOutGameplaySizeDelta: {x: 0, y: 0}
CoinCounter: {fileID: 0}
CoinCounterGameplayPosition: {x: 0, y: 0}
Board: {fileID: 0}
BoardGameplayPosition: {x: 0, y: 0}
--- !u!1 &917670191
GameObject:
m_ObjectHideFlags: 0
@ -51879,7 +51878,7 @@ MonoBehaviour:
m_PersistentCalls:
m_Calls: []
m_text: "\u041F\u043E\u0432\u0442\u043E\u0440\u043D\u0430\u044F \u0438\u0433\u0440\u0430:<br>5
\u0419\u0423\u0413\u0420\u0418\u041A\u041E\u0412"
\u0440\u0443\u0431."
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 6eadce2d7083d384dbcb7e2f40fc590d, type: 2}
m_sharedMaterial: {fileID: -8978430179854350208, guid: 6eadce2d7083d384dbcb7e2f40fc590d, type: 2}
@ -51888,8 +51887,8 @@ MonoBehaviour:
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
rgba: 4278255408
m_fontColor: {r: 0.1898483, g: 1, b: 0, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
@ -51906,19 +51905,19 @@ MonoBehaviour:
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 0.32
m_fontSizeBase: 0.32
m_fontSize: 0.4
m_fontSizeBase: 0.4
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 0.11
m_fontSizeMax: 72
m_fontStyle: 0
m_fontStyle: 1
m_HorizontalAlignment: 2
m_VerticalAlignment: 512
m_textAlignment: 65535
m_characterSpacing: 0
m_wordSpacing: 0
m_lineSpacing: 0
m_lineSpacing: -50
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0

View File

@ -100,7 +100,7 @@ public class MenuState : IState
CharacterController.HideCharacter();
CharacterController.I.SetAllCharactersPrizeAvailable(true);
DualAvatarController.Instance.KillCharacters();
DualAvatarController.Instance.HideCharacters();
DifficultyManager.instance.ResetDifficulty();

View File

@ -265,7 +265,7 @@ public class ShowWinnerState : IState
break;
case EndOption.Menu://чистим поле и переходим в меню с параметром чтобы панельки съехались обратно
CharacterController.HideCharacter();
DualAvatarController.Instance.KillCharacters();
DualAvatarController.Instance.HideCharacters();
GameManager.stateMachine.ChangeState(new ClearFieldState(true, CellState.Player1));
break;
}

194
Assets/Scripts/MenuUi.cs Normal file
View File

@ -0,0 +1,194 @@
using System.Collections;
using UnityEngine;
public class MenuUi : MonoBehaviour
{
[Header("Время перемещения блока")]
[SerializeField] float blockMoveDuration = 0.6f;
[Header("Верхний блок")]
[SerializeField] RectTransform TopContainer;
private Vector2 TopMenuPosition;
[SerializeField] Vector2 TopGameplayOffset;
[Header("Нижний блок")]
[SerializeField] RectTransform BottomContainer;
private Vector2 BottomMenuPosition;
[SerializeField] Vector2 BottomGameplayOffset;
[Header("Режим на одного")]
[SerializeField] RectTransform PveContainer;
private Vector2 PveMenuPosition;
[SerializeField] Vector2 PveGameplayOffset;
[Header("Режим на двоих")]
[SerializeField] RectTransform PvpContainer;
private Vector2 PvpMenuPosition;
[SerializeField] Vector2 PvpGameplayOffset;
[Header("Надпись призы закончились")]
[SerializeField] RectTransform PrizesOut;
private Vector2 PrizesOutMenuPosition;
[SerializeField] Vector2 PrizesOutGameplayOffset;
[SerializeField] Vector2 PrizesOutGameplayPosition;
private Vector2 PrizesOutMenuSizeDelta;
[SerializeField] Vector2 PrizesOutGameplaySizeDelta;
[Header("Счетчик монет")]
[SerializeField] Transform CoinCounter;
private Vector2 CoinCounterMenuPosition;
[SerializeField] Vector2 CoinCounterGameplayPosition;
[Header("Доска")]
[SerializeField] Transform Board;
private Vector2 BoardMenuPosition;
[SerializeField] Vector2 BoardGameplayPosition;
private bool _cached = false;
bool processing = false;
bool Menu;
bool Gameplay;
void InitializeIfNeed()
{
if (!_cached) CacheStartParametrs();
}
void CacheStartParametrs()
{
//Кэшируем стартовые позиции и размеры
TopMenuPosition = TopContainer.anchoredPosition;
BottomMenuPosition = BottomContainer.anchoredPosition;
PveMenuPosition = PveContainer.anchoredPosition;
PvpMenuPosition = PvpContainer.anchoredPosition;
PrizesOutMenuPosition = PrizesOut.anchoredPosition;
PrizesOutMenuSizeDelta = PrizesOut.sizeDelta;
CoinCounterMenuPosition = CoinCounter.localPosition;
BoardMenuPosition = Board.localPosition;
_cached = true;
}
public void OpenMenu()
{
InitializeIfNeed();
}
public void CloseMenu()
{
InitializeIfNeed();
}
IEnumerator OpenGameplayAnim()
{
float t;
//ШАГ 1. ПРЯЧЕМ МЕНЮ
t = 0;
while (t < 1)
{
t += Time.deltaTime * 2;
t = Mathf.Clamp01(t);
TopContainer.anchoredPosition = Vector2.Lerp(TopMenuPosition, TopMenuPosition + TopGameplayOffset, t);
PveContainer.anchoredPosition = Vector2.Lerp(PveMenuPosition, PveMenuPosition + PveGameplayOffset, t);
PvpContainer.anchoredPosition = Vector2.Lerp(PvpMenuPosition, PvpMenuPosition + PvpGameplayOffset, t);
BottomContainer.anchoredPosition = Vector2.Lerp(BottomMenuPosition, BottomMenuPosition + BottomGameplayOffset, t);
PrizesOut.anchoredPosition = Vector2.Lerp(PrizesOutMenuPosition, PrizesOutMenuPosition + PrizesOutGameplayOffset, t);
PrizesOut.sizeDelta = Vector2.Lerp(PrizesOutMenuSizeDelta, PrizesOutGameplaySizeDelta, t);
CoinCounter.localPosition = Vector2.Lerp(CoinCounterMenuPosition, CoinCounterGameplayPosition, t);
yield return null;
}
//ШАГ 1. Показываем доску
t = 0;
while (t < 1)
{
t += Time.deltaTime * 2;//скорость надо высчитывать
t = Mathf.Clamp01(t);
Board.localPosition = Vector2.Lerp(BoardMenuPosition, BoardGameplayPosition, t);
PrizesOut.anchoredPosition = Vector3.Lerp(PrizesOutMenuPosition + PrizesOutGameplayOffset, PrizesOutGameplayPosition, t);
yield return null;
}
}
IEnumerator OpenMenuAnim()
{
//ШАГ 1. УБРАТЬ ДОСКУ
float t = 0;
while (t < 1)
{
t += Time.deltaTime * 2;//скорости править
t = Mathf.Clamp01(t);
Board.localPosition = Vector2.Lerp(BoardGameplayPosition, BoardMenuPosition, t);
PrizesOut.anchoredPosition = Vector2.Lerp(PrizesOutGameplayPosition, PrizesOutMenuPosition + PrizesOutGameplayOffset, t);
yield return null;
}
//ШАГ 2. ПОКАЗАТЬ МЕНЮ
t = 0;
while (t < 1)
{
t += Time.deltaTime * 2;
t = Mathf.Clamp01(t);
TopContainer.anchoredPosition = Vector2.Lerp(TopMenuPosition + TopGameplayOffset, TopMenuPosition, t);
//перемещение кнопок
PveContainer.anchoredPosition = Vector2.Lerp(PveMenuPosition + PvpGameplayOffset, PveMenuPosition, t);
PvpContainer.anchoredPosition = Vector2.Lerp(PvpMenuPosition + PvpGameplayOffset, PvpMenuPosition, t);
PrizesOut.anchoredPosition = Vector2.Lerp(PrizesOutMenuPosition+PrizesOutGameplayOffset, PrizesOutMenuPosition, t);
//монетка
//float startDistance = Vector3.Distance(coinPanel.position, sCoin);
//while (Vector3.Distance(coinPanel.position, sCoin) > 0.01f)
//{
// float coinspeed = startDistance * Time.deltaTime * 2;
// coinPanel.localPosition = Vector3.MoveTowards(coinPanel.localPosition, sCoin, coinspeed);
// yield return null;
//}
//coinPanel.localPosition = sCoin;
//label2.localPosition = Vector3.Lerp(sLabel2, eLabel2, t);
//SmallPrizesOut.sizeDelta = Vector2.Lerp(sSmallPrizesOutSize, eSmallPrizesOutSize, t);
yield return null;
}
//animationEnded = true;
//gm.botScale.gameObject.SetActive(false);
//gm.Player1Scale.gameObject.SetActive(false);
//gm.Player2Scale.gameObject.SetActive(false);
}
}

View File

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

View File

@ -38,6 +38,14 @@ public class DualAvatarController : MonoBehaviour
public void Initialize()
{
Instance = this;
if (!spawned)
{
avatars[PLAYER1] = CreateAvatar(characterPrefabs[0], AvatarsParent, PLAYER1);
avatars[PLAYER2] = CreateAvatar(characterPrefabs[1], AvatarsParent, PLAYER2);
spawned = true;
}
bus = AvatarEventBus.Instance;
BindEvents();
}
@ -47,25 +55,22 @@ public class DualAvatarController : MonoBehaviour
public void ShowCharacters() //заспвавнить и показать
{
if (spawned) return;
if (characterPrefabs != null && characterPrefabs.Count < 2)
Debug.LogError("Меньше 2 персонажей в списке аватаров.");
//Тут возможно будет рандомизация персонажей
avatars[PLAYER1] = CreateAvatar(characterPrefabs[0], AvatarsParent, PLAYER1);
avatars[PLAYER2] = CreateAvatar(characterPrefabs[1], AvatarsParent, PLAYER2);
StartCoroutine(MoveLocal(avatars[PLAYER1], GetShownPosition(PLAYER1), CharacterMovementSpeed, OnComplete: AvatarAppeared));
StartCoroutine(MoveLocal(avatars[PLAYER2], GetShownPosition(PLAYER2), CharacterMovementSpeed, OnComplete: AvatarAppeared));
spawned = true;
}
public void KillCharacters()
public void HideCharacters()
{
if (!spawned) return;
StartCoroutine(MoveLocal(avatars[PLAYER1], GetHiddenPosition(PLAYER1), CharacterMovementSpeed, OnComplete: () => Destroy(avatars[PLAYER1].gameObject)));
StartCoroutine(MoveLocal(avatars[PLAYER2], GetHiddenPosition(PLAYER2), CharacterMovementSpeed, OnComplete: () => Destroy(avatars[PLAYER1].gameObject)));
spawned = false;
StopAllCoroutines();
StartCoroutine(MoveLocal(avatars[PLAYER1], GetHiddenPosition(PLAYER1), CharacterMovementSpeed, OnComplete: () => print("hided")));
StartCoroutine(MoveLocal(avatars[PLAYER2], GetHiddenPosition(PLAYER2), CharacterMovementSpeed, OnComplete: () => print("hided")));
}
Avatar CreateAvatar(GameObject prefab, Transform parent, CellState team)