TO SQUASH: started menu callback calling
This commit is contained in:
@@ -87,6 +87,7 @@ AnimatorState:
|
||||
m_CycleOffset: 0
|
||||
m_Transitions:
|
||||
- {fileID: 8965335544505806041}
|
||||
- {fileID: 2834628233172928353}
|
||||
m_StateMachineBehaviours: []
|
||||
m_Position: {x: 50, y: 50, z: 0}
|
||||
m_IKOnFeet: 0
|
||||
@@ -198,7 +199,7 @@ AnimatorStateMachine:
|
||||
m_Position: {x: 420, y: -80, z: 0}
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: -5817495590797541015}
|
||||
m_Position: {x: 710, y: -80, z: 0}
|
||||
m_Position: {x: 700, y: -80, z: 0}
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: -1959566173440114212}
|
||||
m_Position: {x: 420, y: 300, z: 0}
|
||||
@@ -268,31 +269,6 @@ AnimatorController:
|
||||
m_SyncedLayerAffectsTiming: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_EvaluateTransitionsOnStart: 1
|
||||
--- !u!1101 &2643679439216305563
|
||||
AnimatorStateTransition:
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name:
|
||||
m_Conditions:
|
||||
- m_ConditionMode: 1
|
||||
m_ConditionEvent: buttonReleased
|
||||
m_EventTreshold: 0
|
||||
m_DstStateMachine: {fileID: 0}
|
||||
m_DstState: {fileID: -8163611017812609999}
|
||||
m_Solo: 0
|
||||
m_Mute: 0
|
||||
m_IsExit: 0
|
||||
serializedVersion: 3
|
||||
m_TransitionDuration: 0
|
||||
m_TransitionOffset: 0
|
||||
m_ExitTime: 0.516129
|
||||
m_HasExitTime: 0
|
||||
m_HasFixedDuration: 1
|
||||
m_InterruptionSource: 0
|
||||
m_OrderedInterruption: 1
|
||||
m_CanTransitionToSelf: 1
|
||||
--- !u!1101 &2649200199184588423
|
||||
AnimatorStateTransition:
|
||||
m_ObjectHideFlags: 1
|
||||
@@ -318,6 +294,56 @@ AnimatorStateTransition:
|
||||
m_InterruptionSource: 0
|
||||
m_OrderedInterruption: 1
|
||||
m_CanTransitionToSelf: 1
|
||||
--- !u!1101 &2834628233172928353
|
||||
AnimatorStateTransition:
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name:
|
||||
m_Conditions:
|
||||
- m_ConditionMode: 1
|
||||
m_ConditionEvent: buttonReleased
|
||||
m_EventTreshold: 0
|
||||
m_DstStateMachine: {fileID: 0}
|
||||
m_DstState: {fileID: -8163611017812609999}
|
||||
m_Solo: 0
|
||||
m_Mute: 0
|
||||
m_IsExit: 0
|
||||
serializedVersion: 3
|
||||
m_TransitionDuration: 0
|
||||
m_TransitionOffset: 0
|
||||
m_ExitTime: 0.516129
|
||||
m_HasExitTime: 0
|
||||
m_HasFixedDuration: 1
|
||||
m_InterruptionSource: 0
|
||||
m_OrderedInterruption: 1
|
||||
m_CanTransitionToSelf: 1
|
||||
--- !u!1101 &3460560277892747234
|
||||
AnimatorStateTransition:
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name:
|
||||
m_Conditions:
|
||||
- m_ConditionMode: 1
|
||||
m_ConditionEvent: buttonReleased
|
||||
m_EventTreshold: 0
|
||||
m_DstStateMachine: {fileID: 0}
|
||||
m_DstState: {fileID: -5817495590797541015}
|
||||
m_Solo: 0
|
||||
m_Mute: 0
|
||||
m_IsExit: 0
|
||||
serializedVersion: 3
|
||||
m_TransitionDuration: 0
|
||||
m_TransitionOffset: 0
|
||||
m_ExitTime: 0.28571433
|
||||
m_HasExitTime: 0
|
||||
m_HasFixedDuration: 1
|
||||
m_InterruptionSource: 0
|
||||
m_OrderedInterruption: 1
|
||||
m_CanTransitionToSelf: 1
|
||||
--- !u!1102 &4344599983006799549
|
||||
AnimatorState:
|
||||
serializedVersion: 6
|
||||
@@ -330,7 +356,7 @@ AnimatorState:
|
||||
m_CycleOffset: 0
|
||||
m_Transitions:
|
||||
- {fileID: -7814800188518307059}
|
||||
- {fileID: 2643679439216305563}
|
||||
- {fileID: 3460560277892747234}
|
||||
m_StateMachineBehaviours: []
|
||||
m_Position: {x: 50, y: 50, z: 0}
|
||||
m_IKOnFeet: 0
|
||||
|
||||
@@ -22,11 +22,11 @@ AnimationClip:
|
||||
curve:
|
||||
- time: 0
|
||||
value: {fileID: -507724509468476920, guid: 5dd5cb85e1611b711bb4e87af673045e, type: 3}
|
||||
- time: 0.16666667
|
||||
- time: 0.11666667
|
||||
value: {fileID: 7717131122486000048, guid: 5dd5cb85e1611b711bb4e87af673045e, type: 3}
|
||||
- time: 0.33333334
|
||||
- time: 0.21666667
|
||||
value: {fileID: -1539647790023181718, guid: 5dd5cb85e1611b711bb4e87af673045e, type: 3}
|
||||
- time: 0.5
|
||||
- time: 0.33333334
|
||||
value: {fileID: 7237685753823095570, guid: 5dd5cb85e1611b711bb4e87af673045e, type: 3}
|
||||
attribute: m_Sprite
|
||||
path:
|
||||
@@ -59,7 +59,7 @@ AnimationClip:
|
||||
m_AdditiveReferencePoseClip: {fileID: 0}
|
||||
m_AdditiveReferencePoseTime: 0
|
||||
m_StartTime: 0
|
||||
m_StopTime: 0.51666665
|
||||
m_StopTime: 0.35000002
|
||||
m_OrientationOffsetY: 0
|
||||
m_Level: 0
|
||||
m_CycleOffset: 0
|
||||
@@ -86,8 +86,8 @@ AnimationClip:
|
||||
floatParameter: 0
|
||||
intParameter: 0
|
||||
messageOptions: 0
|
||||
- time: 0.5
|
||||
functionName: playKeyTurnClose
|
||||
- time: 0.33333334
|
||||
functionName: PlayKeyTurnClose
|
||||
data:
|
||||
objectReferenceParameter: {fileID: 0}
|
||||
floatParameter: 0
|
||||
|
||||
@@ -22,11 +22,11 @@ AnimationClip:
|
||||
curve:
|
||||
- time: 0
|
||||
value: {fileID: 7237685753823095570, guid: 5dd5cb85e1611b711bb4e87af673045e, type: 3}
|
||||
- time: 0.16666667
|
||||
- time: 0.11666667
|
||||
value: {fileID: -1539647790023181718, guid: 5dd5cb85e1611b711bb4e87af673045e, type: 3}
|
||||
- time: 0.33333334
|
||||
- time: 0.21666667
|
||||
value: {fileID: 7717131122486000048, guid: 5dd5cb85e1611b711bb4e87af673045e, type: 3}
|
||||
- time: 0.5
|
||||
- time: 0.33333334
|
||||
value: {fileID: -507724509468476920, guid: 5dd5cb85e1611b711bb4e87af673045e, type: 3}
|
||||
attribute: m_Sprite
|
||||
path:
|
||||
@@ -59,7 +59,7 @@ AnimationClip:
|
||||
m_AdditiveReferencePoseClip: {fileID: 0}
|
||||
m_AdditiveReferencePoseTime: 0
|
||||
m_StartTime: 0
|
||||
m_StopTime: 0.51666665
|
||||
m_StopTime: 0.35000002
|
||||
m_OrientationOffsetY: 0
|
||||
m_Level: 0
|
||||
m_CycleOffset: 0
|
||||
@@ -114,8 +114,15 @@ AnimationClip:
|
||||
floatParameter: 0
|
||||
intParameter: 0
|
||||
messageOptions: 0
|
||||
- time: 0
|
||||
functionName: playKeyTurnOpen
|
||||
- time: 0.21666667
|
||||
functionName: PlayKeyTurnOpen
|
||||
data:
|
||||
objectReferenceParameter: {fileID: 0}
|
||||
floatParameter: 0
|
||||
intParameter: 0
|
||||
messageOptions: 0
|
||||
- time: 0.33333334
|
||||
functionName: TriggerCallback
|
||||
data:
|
||||
objectReferenceParameter: {fileID: 0}
|
||||
floatParameter: 0
|
||||
|
||||
@@ -1367,7 +1367,7 @@ SpriteRenderer:
|
||||
m_GlobalIlluminationMeshLod: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 10
|
||||
m_SortingOrder: 9
|
||||
m_MaskInteraction: 0
|
||||
m_Sprite: {fileID: -9013117296752963025, guid: 5dd5cb85e1611b711bb4e87af673045e, type: 3}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
|
||||
@@ -17,6 +17,16 @@ public class MenuButton : MonoBehaviour
|
||||
|
||||
private static Color opaque = new Color(1f, 1f, 1f, 1f);
|
||||
|
||||
private const float holdThreshold = 0.15f;
|
||||
|
||||
private bool pointerDownOnButton = false;
|
||||
|
||||
private bool holdInteraction = false;
|
||||
|
||||
private bool pointerInsideDuringHold = false;
|
||||
|
||||
private float pointerDownTime = 0f;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
@@ -27,18 +37,83 @@ public class MenuButton : MonoBehaviour
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Mouse.current == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for mouse button press to request key translation and handle hold interactions
|
||||
if (Mouse.current.leftButton.wasPressedThisFrame)
|
||||
{
|
||||
Vector2 mousePosition = Mouse.current.position.ReadValue();
|
||||
Vector2 worldMousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
|
||||
|
||||
if (boxCollider.OverlapPoint(worldMousePosition))
|
||||
if (IsPointerInsideButton())
|
||||
{
|
||||
isButtonPressed = true;
|
||||
key.TranslateTo(row);
|
||||
} else {
|
||||
isButtonPressed = false;
|
||||
pointerDownOnButton = true;
|
||||
holdInteraction = false;
|
||||
pointerInsideDuringHold = true;
|
||||
pointerDownTime = Time.unscaledTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
isButtonPressed = false;
|
||||
pointerDownOnButton = false;
|
||||
holdInteraction = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (pointerDownOnButton && Mouse.current.leftButton.isPressed)
|
||||
{
|
||||
bool pointerInside = IsPointerInsideButton();
|
||||
|
||||
if (!holdInteraction && (Time.unscaledTime - pointerDownTime) >= holdThreshold)
|
||||
{
|
||||
holdInteraction = true;
|
||||
key.OpenKey(false);
|
||||
pointerInsideDuringHold = pointerInside;
|
||||
|
||||
if (!pointerInside)
|
||||
{
|
||||
key.CloseKey();
|
||||
}
|
||||
}
|
||||
|
||||
if (holdInteraction)
|
||||
{
|
||||
if (pointerInside && !pointerInsideDuringHold)
|
||||
{
|
||||
key.OpenKey(false);
|
||||
}
|
||||
else if (!pointerInside && pointerInsideDuringHold)
|
||||
{
|
||||
key.CloseKey();
|
||||
}
|
||||
|
||||
pointerInsideDuringHold = pointerInside;
|
||||
}
|
||||
}
|
||||
|
||||
if (pointerDownOnButton && Mouse.current.leftButton.wasReleasedThisFrame)
|
||||
{
|
||||
bool pointerInside = IsPointerInsideButton();
|
||||
|
||||
if (holdInteraction)
|
||||
{
|
||||
if (pointerInside)
|
||||
{
|
||||
key.InvokeCallback();
|
||||
}
|
||||
|
||||
key.ReleaseKey();
|
||||
}
|
||||
else
|
||||
{
|
||||
key.OpenKey(true);
|
||||
}
|
||||
|
||||
pointerDownOnButton = false;
|
||||
holdInteraction = false;
|
||||
pointerInsideDuringHold = false;
|
||||
}
|
||||
|
||||
if (isButtonPressed)
|
||||
@@ -50,4 +125,16 @@ public class MenuButton : MonoBehaviour
|
||||
spriteRenderer.color = transparent;
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsPointerInsideButton()
|
||||
{
|
||||
if (Camera.main == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector2 mousePosition = Mouse.current.position.ReadValue();
|
||||
Vector2 worldMousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
|
||||
return boxCollider.OverlapPoint(worldMousePosition);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ public class MenuKey : MonoBehaviour
|
||||
|
||||
private bool isTranslating = false;
|
||||
|
||||
private bool triggered = false;
|
||||
|
||||
private float translationElapsed = 0f;
|
||||
|
||||
private float translationStartY = 0f;
|
||||
@@ -95,10 +97,43 @@ public class MenuKey : MonoBehaviour
|
||||
targetRow = row;
|
||||
}
|
||||
|
||||
public void InvokeCallback(int _)
|
||||
public void OpenKey(bool trigger)
|
||||
{
|
||||
this.triggered = trigger;
|
||||
animator.ResetTrigger("buttonReleased");
|
||||
animator.SetTrigger("buttonClicked");
|
||||
if (!trigger)
|
||||
animator.SetBool("inButton", true);
|
||||
}
|
||||
|
||||
public void CloseKey()
|
||||
{
|
||||
animator.SetBool("inButton", false);
|
||||
}
|
||||
|
||||
public void ReleaseKey()
|
||||
{
|
||||
animator.ResetTrigger("buttonClicked");
|
||||
animator.SetTrigger("buttonReleased");
|
||||
}
|
||||
|
||||
public void InvokeCallback()
|
||||
{
|
||||
if (!isTranslating)
|
||||
{
|
||||
callbackHolder.InvokeCallback(currentRow);
|
||||
}
|
||||
}
|
||||
|
||||
public void TriggerCallback(int _)
|
||||
{
|
||||
if (!isTranslating && triggered)
|
||||
{
|
||||
triggered = false;
|
||||
callbackHolder.InvokeCallback(currentRow);
|
||||
ReleaseKey();
|
||||
}
|
||||
}
|
||||
|
||||
private float EaseOutQuad(float t)
|
||||
{
|
||||
|
||||
@@ -144,8 +144,7 @@ PlayerSettings:
|
||||
visionOSBundleVersion: 1.0
|
||||
tvOSBundleVersion: 1.0
|
||||
bundleVersion: 0.1
|
||||
preloadedAssets:
|
||||
- {fileID: -944628639613478452, guid: 3590b91b4603b465dbb4216d601bff33, type: 3}
|
||||
preloadedAssets: []
|
||||
metroInputSource: 0
|
||||
wsaTransparentSwapchain: 0
|
||||
xboxOneDisableKinectGpuReservation: 1
|
||||
|
||||
Reference in New Issue
Block a user