2023-07-08 14:22:31 +00:00
|
|
|
using DG.Tweening;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class StartMenuAnimations : MonoBehaviour
|
|
|
|
{
|
|
|
|
public GameObject maskObj;
|
|
|
|
public GameObject mixButton;
|
|
|
|
public GameObject attackButton;
|
|
|
|
public GameObject gotoButton;
|
|
|
|
public GameObject freeButton;
|
|
|
|
|
|
|
|
public float animeDuration = 0.2f;
|
|
|
|
|
2023-10-16 10:41:25 +00:00
|
|
|
public float animeMoveXDistance = 20f;
|
|
|
|
public float animeMoveYDistance = 20f;
|
|
|
|
|
|
|
|
public float animeScaleX = 1.2f;
|
|
|
|
public float animeScaleY = 1.2f;
|
2023-07-08 14:22:31 +00:00
|
|
|
|
|
|
|
public float maskScaleX = 1;
|
|
|
|
public float maskScaleY = 0.4f;
|
|
|
|
|
|
|
|
private Vector3 mixOriginDestination;
|
|
|
|
private Vector3 attackOriginDestination;
|
|
|
|
private Vector3 gotoOriginDestination;
|
|
|
|
private Vector3 freeOriginDestination;
|
|
|
|
|
2023-10-16 10:41:25 +00:00
|
|
|
private Vector3 mixDestination;
|
|
|
|
private Vector3 attackDestination;
|
|
|
|
private Vector3 gotoDestination;
|
|
|
|
private Vector3 freeDestination;
|
|
|
|
|
|
|
|
private Vector3 originalCanvas;
|
|
|
|
|
2023-07-08 14:22:31 +00:00
|
|
|
private PolygonCollider2D parallelogramPolygon;
|
|
|
|
private bool isMouseOverMask = false;
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
{
|
2023-10-16 10:41:25 +00:00
|
|
|
originalCanvas = transform.parent.position;
|
2023-07-08 14:22:31 +00:00
|
|
|
// get start position
|
|
|
|
mixOriginDestination = mixButton.transform.position;
|
|
|
|
attackOriginDestination = attackButton.transform.position;
|
|
|
|
gotoOriginDestination = gotoButton.transform.position;
|
|
|
|
freeOriginDestination = freeButton.transform.position;
|
|
|
|
|
|
|
|
// transform local vector3 to world vector3 by parent
|
2023-10-16 10:41:25 +00:00
|
|
|
mixDestination = mixButton.transform.position + new Vector3(animeScaleX * animeMoveXDistance, animeScaleY * animeMoveYDistance, 0);
|
|
|
|
attackDestination = attackButton.transform.position + new Vector3(animeMoveXDistance, animeMoveYDistance, 0);
|
|
|
|
gotoDestination = gotoButton.transform.position - new Vector3(animeMoveXDistance, animeMoveYDistance, 0);
|
|
|
|
freeDestination = freeButton.transform.position - new Vector3(animeScaleX * animeMoveXDistance, animeScaleY * animeMoveYDistance, 0);
|
2023-07-08 14:22:31 +00:00
|
|
|
|
|
|
|
//get polygon from maskOBJ
|
|
|
|
parallelogramPolygon = maskObj.GetComponent<PolygonCollider2D>();
|
|
|
|
|
|
|
|
// minimize mask object
|
|
|
|
MinimizeMaskObj();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
// check if mouse is in parallelogram
|
|
|
|
if (!isMouseOverMask && parallelogramPolygon.OverlapPoint(Input.mousePosition))
|
|
|
|
{
|
|
|
|
isMouseOverMask = true;
|
|
|
|
OnMaskPointerEnter();
|
|
|
|
}
|
|
|
|
else if (isMouseOverMask && !parallelogramPolygon.OverlapPoint(Input.mousePosition))
|
|
|
|
{
|
|
|
|
isMouseOverMask = false;
|
|
|
|
OnMaskPointerExit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnMaskPointerEnter()
|
|
|
|
{
|
|
|
|
// dotween move button
|
2023-10-16 10:41:25 +00:00
|
|
|
mixButton.transform.DOMove(fixCanvas(mixDestination), animeDuration, true).SetEase(Ease.OutCirc).Play();
|
|
|
|
attackButton.transform.DOMove(fixCanvas(attackDestination), animeDuration, true).SetEase(Ease.OutCirc).Play();
|
|
|
|
gotoButton.transform.DOMove(fixCanvas(gotoDestination), animeDuration, true).SetEase(Ease.OutCirc).Play();
|
|
|
|
freeButton.transform.DOMove(fixCanvas(freeDestination), animeDuration, true).SetEase(Ease.OutCirc).Play();
|
2023-07-08 14:22:31 +00:00
|
|
|
MaximizeMaskObj();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnMaskPointerExit()
|
|
|
|
{
|
|
|
|
// dotween move button batck to original position
|
2023-10-16 10:41:25 +00:00
|
|
|
mixButton.transform.DOMove(fixCanvas(mixOriginDestination), animeDuration, true).SetEase(Ease.OutCirc).Play();
|
|
|
|
attackButton.transform.DOMove(fixCanvas(attackOriginDestination), animeDuration, true).SetEase(Ease.OutCirc).Play();
|
|
|
|
gotoButton.transform.DOMove(fixCanvas(gotoOriginDestination), animeDuration, true).SetEase(Ease.OutCirc).Play();
|
|
|
|
freeButton.transform.DOMove(fixCanvas(freeOriginDestination), animeDuration, true).SetEase(Ease.OutCirc).Play();
|
2023-07-08 14:22:31 +00:00
|
|
|
MinimizeMaskObj();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void MinimizeMaskObj()
|
|
|
|
{
|
|
|
|
// minimize mask object use dotween doscale
|
|
|
|
maskObj.transform.DOScaleX(maskScaleX, animeDuration).SetEase(Ease.OutCirc).Play();
|
|
|
|
maskObj.transform.DOScaleY(maskScaleY, animeDuration).SetEase(Ease.OutCirc).Play();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void MaximizeMaskObj()
|
|
|
|
{
|
|
|
|
// maximize mask object use dotween doscale
|
|
|
|
maskObj.transform.DOScaleX(1, animeDuration).SetEase(Ease.OutCirc).Play();
|
|
|
|
maskObj.transform.DOScaleY(1, animeDuration).SetEase(Ease.OutCirc).Play();
|
|
|
|
}
|
2023-10-16 10:41:25 +00:00
|
|
|
|
|
|
|
private Vector3 fixCanvas(Vector3 vector)
|
|
|
|
{
|
|
|
|
// fix position of button while canvas is changed
|
2023-10-20 19:54:42 +00:00
|
|
|
return vector.FixCanvas(originalCanvas,transform.parent.position);
|
2023-10-16 10:41:25 +00:00
|
|
|
}
|
2023-07-08 14:22:31 +00:00
|
|
|
}
|