TO SQUASH: menu key movement.
This commit is contained in:
@@ -78,4 +78,11 @@ AnimationClip:
|
||||
m_EulerEditorCurves: []
|
||||
m_HasGenericRootTransform: 0
|
||||
m_HasMotionFloatCurves: 0
|
||||
m_Events: []
|
||||
m_Events:
|
||||
- time: 0.33333334
|
||||
functionName: PlayKeyTurnClose
|
||||
data:
|
||||
objectReferenceParameter: {fileID: 0}
|
||||
floatParameter: 0
|
||||
intParameter: 0
|
||||
messageOptions: 0
|
||||
|
||||
@@ -147,7 +147,7 @@ Transform:
|
||||
m_GameObject: {fileID: 113981076}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: -3.235, y: -1.354, z: 0}
|
||||
m_LocalPosition: {x: 0, y: -2.76, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
@@ -225,7 +225,8 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::MenuButton
|
||||
isButtonPressed: 0
|
||||
keyAnimator: {fileID: 1133197549}
|
||||
key: {fileID: 1133197552}
|
||||
row: 4
|
||||
--- !u!61 &113981080
|
||||
BoxCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -300,7 +301,7 @@ Transform:
|
||||
m_GameObject: {fileID: 150339122}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: -3.235, y: -2.055, z: 0}
|
||||
m_LocalPosition: {x: 0, y: -3.45, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
@@ -378,7 +379,8 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::MenuButton
|
||||
isButtonPressed: 0
|
||||
keyAnimator: {fileID: 1133197549}
|
||||
key: {fileID: 1133197552}
|
||||
row: 5
|
||||
--- !u!61 &150339126
|
||||
BoxCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -453,7 +455,7 @@ Transform:
|
||||
m_GameObject: {fileID: 339072663}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: -3.235, y: -0.005, z: 0}
|
||||
m_LocalPosition: {x: 0, y: -1.38, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
@@ -531,7 +533,8 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::MenuButton
|
||||
isButtonPressed: 0
|
||||
keyAnimator: {fileID: 1133197549}
|
||||
key: {fileID: 1133197552}
|
||||
row: 2
|
||||
--- !u!61 &339072667
|
||||
BoxCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -586,6 +589,10 @@ PrefabInstance:
|
||||
serializedVersion: 3
|
||||
m_TransformParent: {fileID: 0}
|
||||
m_Modifications:
|
||||
- target: {fileID: 2455465290438712436, guid: 37cccc8c2583c8987851bdc00b56a09e, type: 3}
|
||||
propertyPath: orthographic size
|
||||
value: 5
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 2455465290438712436, guid: 37cccc8c2583c8987851bdc00b56a09e, type: 3}
|
||||
propertyPath: m_BackGroundColor.b
|
||||
value: 0
|
||||
@@ -638,6 +645,14 @@ PrefabInstance:
|
||||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6499039351711337429, guid: 37cccc8c2583c8987851bdc00b56a09e, type: 3}
|
||||
propertyPath: m_AssetsPPU
|
||||
value: 100
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6499039351711337429, guid: 37cccc8c2583c8987851bdc00b56a09e, type: 3}
|
||||
propertyPath: m_UpscaleRT
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8250641719934303711, guid: 37cccc8c2583c8987851bdc00b56a09e, type: 3}
|
||||
propertyPath: m_Name
|
||||
value: Main Camera
|
||||
@@ -672,7 +687,7 @@ Transform:
|
||||
m_GameObject: {fileID: 521759022}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 1.11, y: 0, z: 0}
|
||||
m_LocalPosition: {x: -2.125, y: 1.396, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
@@ -712,7 +727,7 @@ Transform:
|
||||
m_GameObject: {fileID: 857124429}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: -3.235, y: 0.694, z: 0}
|
||||
m_LocalPosition: {x: 0, y: -0.69, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
@@ -790,7 +805,8 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::MenuButton
|
||||
isButtonPressed: 0
|
||||
keyAnimator: {fileID: 1133197549}
|
||||
key: {fileID: 1133197552}
|
||||
row: 1
|
||||
--- !u!61 &857124433
|
||||
BoxCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -994,7 +1010,7 @@ Transform:
|
||||
m_GameObject: {fileID: 1085380534}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: -3.235, y: -0.674, z: 0}
|
||||
m_LocalPosition: {x: 0, y: -2.07, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
@@ -1072,7 +1088,8 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::MenuButton
|
||||
isButtonPressed: 0
|
||||
keyAnimator: {fileID: 1133197549}
|
||||
key: {fileID: 1133197552}
|
||||
row: 3
|
||||
--- !u!61 &1085380538
|
||||
BoxCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -1465,7 +1482,7 @@ Transform:
|
||||
m_GameObject: {fileID: 1823887661}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: -3.235, y: 1.395, z: 0}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
@@ -1543,7 +1560,8 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::MenuButton
|
||||
isButtonPressed: 1
|
||||
keyAnimator: {fileID: 1133197549}
|
||||
key: {fileID: 1133197552}
|
||||
row: 0
|
||||
--- !u!61 &1823887665
|
||||
BoxCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -5,7 +5,9 @@ public class MenuButton : MonoBehaviour
|
||||
{
|
||||
public bool isButtonPressed = false;
|
||||
|
||||
public Animator keyAnimator;
|
||||
public MenuKey key;
|
||||
|
||||
public int row;
|
||||
|
||||
private SpriteRenderer spriteRenderer;
|
||||
|
||||
@@ -33,7 +35,7 @@ public class MenuButton : MonoBehaviour
|
||||
if (boxCollider.OverlapPoint(worldMousePosition))
|
||||
{
|
||||
isButtonPressed = true;
|
||||
keyAnimator.SetTrigger("buttonChanged");
|
||||
key.TranslateTo(row);
|
||||
} else {
|
||||
isButtonPressed = false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class MenuCallbackHolder
|
||||
{
|
||||
private System.Action[] callbacks;
|
||||
|
||||
public MenuCallbackHolder()
|
||||
{
|
||||
callbacks = new System.Action[]
|
||||
{
|
||||
PlayButtonCallback,
|
||||
InstruccionsButtonCallback,
|
||||
SetupButtonCallback,
|
||||
ZapButtonCallback,
|
||||
AboutButtonCallback,
|
||||
QuitButtonCallback
|
||||
};
|
||||
}
|
||||
|
||||
public void InvokeCallback(int index)
|
||||
{
|
||||
if (index >= 0 && index < callbacks.Length)
|
||||
{
|
||||
callbacks[index].Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"MenuCallbackHolder: Invalid callback index {index}");
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayButtonCallback()
|
||||
{
|
||||
Debug.Log("Play button pressed");
|
||||
UnityEngine.SceneManagement.SceneManager.LoadScene("Game");
|
||||
}
|
||||
|
||||
public void InstruccionsButtonCallback()
|
||||
{
|
||||
Debug.Log("Instructions button pressed");
|
||||
// UnityEngine.SceneManagement.SceneManager.LoadScene("Instructions");
|
||||
}
|
||||
|
||||
public void SetupButtonCallback()
|
||||
{
|
||||
Debug.Log("Setup button pressed");
|
||||
// UnityEngine.SceneManagement.SceneManager.LoadScene("Setup");
|
||||
}
|
||||
|
||||
public void ZapButtonCallback()
|
||||
{
|
||||
Debug.Log("Zap Scores button pressed");
|
||||
// UnityEngine.SceneManagement.SceneManager.LoadScene("Zap");
|
||||
}
|
||||
|
||||
public void AboutButtonCallback()
|
||||
{
|
||||
Debug.Log("About button pressed");
|
||||
// UnityEngine.SceneManagement.SceneManager.LoadScene("About");
|
||||
}
|
||||
|
||||
public void QuitButtonCallback()
|
||||
{
|
||||
Debug.Log("Quit button pressed");
|
||||
Application.Quit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e6c3bcd6a2eb7ec5aab68f9b18daea7
|
||||
@@ -10,26 +10,100 @@ public class MenuKey : MonoBehaviour
|
||||
|
||||
private Animator animator;
|
||||
|
||||
private int currentRow = 0;
|
||||
|
||||
private int targetRow = 0;
|
||||
|
||||
private bool isTranslating = false;
|
||||
|
||||
private float translationElapsed = 0f;
|
||||
|
||||
private float translationStartY = 0f;
|
||||
|
||||
private float translationTargetY = 0f;
|
||||
|
||||
private MenuCallbackHolder callbackHolder;
|
||||
|
||||
private static float animationDuration = 0.45f;
|
||||
|
||||
private static float[] rowPositions = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
animator = GetComponent<Animator>();
|
||||
callbackHolder = new MenuCallbackHolder();
|
||||
|
||||
// Precompute the row positions based on the number of rows and the desired spacing.
|
||||
for (int i = 0; i < rowPositions.Length; i++)
|
||||
{
|
||||
rowPositions[i] = 1.462f - (i * 0.69f);
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (!isTranslating && currentRow != targetRow)
|
||||
{
|
||||
animator.SetTrigger("buttonChanged");
|
||||
|
||||
translationElapsed = 0f;
|
||||
translationStartY = rowPositions[currentRow];
|
||||
translationTargetY = rowPositions[targetRow];
|
||||
isTranslating = true;
|
||||
}
|
||||
|
||||
if (isTranslating)
|
||||
{
|
||||
translationElapsed += Time.deltaTime;
|
||||
|
||||
float t = Mathf.Clamp01(translationElapsed / animationDuration);
|
||||
float easedT = EaseOutQuad(t);
|
||||
float y = Mathf.Lerp(translationStartY, translationTargetY, easedT);
|
||||
|
||||
Vector3 position = transform.position;
|
||||
position.y = y;
|
||||
transform.position = position;
|
||||
|
||||
if (t >= 1f)
|
||||
{
|
||||
currentRow = targetRow;
|
||||
isTranslating = false;
|
||||
|
||||
position.y = translationTargetY;
|
||||
transform.position = position;
|
||||
|
||||
animator.ResetTrigger("buttonChanged");
|
||||
animator.SetTrigger("inserted");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void playKeyTurnOpen(int _)
|
||||
public void PlayKeyTurnOpen(int _)
|
||||
{
|
||||
audioSource.PlayOneShot(keyTurnOpen);
|
||||
}
|
||||
|
||||
public void playKeyTurnClose(int _)
|
||||
public void PlayKeyTurnClose(int _)
|
||||
{
|
||||
audioSource.PlayOneShot(keyTurnClose);
|
||||
}
|
||||
|
||||
public void TranslateTo(int row)
|
||||
{
|
||||
targetRow = row;
|
||||
}
|
||||
|
||||
public void InvokeCallback(int _)
|
||||
{
|
||||
callbackHolder.InvokeCallback(currentRow);
|
||||
}
|
||||
|
||||
private float EaseOutQuad(float t)
|
||||
{
|
||||
// Quadratic easing out - deceleration until the end
|
||||
return 1 - (1 - t) * (1 - t);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ TextureImporter:
|
||||
rect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
y: 275
|
||||
y: 276
|
||||
width: 216
|
||||
height: 69
|
||||
alignment: 0
|
||||
@@ -174,7 +174,7 @@ TextureImporter:
|
||||
rect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
y: 205
|
||||
y: 207
|
||||
width: 216
|
||||
height: 69
|
||||
alignment: 0
|
||||
@@ -218,7 +218,7 @@ TextureImporter:
|
||||
rect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
y: 70
|
||||
y: 69
|
||||
width: 216
|
||||
height: 69
|
||||
alignment: 0
|
||||
|
||||
Reference in New Issue
Block a user