V3.1.2 追加Train Button选择
引入DOTween Plugin 追加Train Button选择和其动画 优化代码
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
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;
|
||||
|
||||
public Vector3 mixDestination = new Vector3(-85, 29, 0);
|
||||
public Vector3 attackDestination = new Vector3(-100, 0, 0);
|
||||
public Vector3 gotoDestination = new Vector3(-115, -29, 0);
|
||||
public Vector3 freeDestination = new Vector3(-130, -58, 0);
|
||||
|
||||
public float maskScaleX = 1;
|
||||
public float maskScaleY = 0.4f;
|
||||
|
||||
private Vector3 mixOriginDestination;
|
||||
private Vector3 attackOriginDestination;
|
||||
private Vector3 gotoOriginDestination;
|
||||
private Vector3 freeOriginDestination;
|
||||
|
||||
private PolygonCollider2D parallelogramPolygon;
|
||||
private bool isMouseOverMask = false;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// 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
|
||||
mixDestination += mixButton.transform.parent.position;
|
||||
attackDestination += attackButton.transform.parent.position;
|
||||
gotoDestination += gotoButton.transform.parent.position;
|
||||
freeDestination += freeButton.transform.parent.position;
|
||||
|
||||
//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
|
||||
mixButton.transform.DOMove(mixDestination, animeDuration, true).SetEase(Ease.OutCirc).Play();
|
||||
attackButton.transform.DOMove(attackDestination, animeDuration, true).SetEase(Ease.OutCirc).Play();
|
||||
gotoButton.transform.DOMove(gotoDestination, animeDuration, true).SetEase(Ease.OutCirc).Play();
|
||||
freeButton.transform.DOMove(freeDestination, animeDuration, true).SetEase(Ease.OutCirc).Play();
|
||||
MaximizeMaskObj();
|
||||
}
|
||||
|
||||
private void OnMaskPointerExit()
|
||||
{
|
||||
// dotween move button batck to original position
|
||||
mixButton.transform.DOMove(mixOriginDestination, animeDuration, true).SetEase(Ease.OutCirc).Play();
|
||||
attackButton.transform.DOMove(attackOriginDestination, animeDuration, true).SetEase(Ease.OutCirc).Play();
|
||||
gotoButton.transform.DOMove(gotoOriginDestination, animeDuration, true).SetEase(Ease.OutCirc).Play();
|
||||
freeButton.transform.DOMove(freeOriginDestination, animeDuration, true).SetEase(Ease.OutCirc).Play();
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee00299c7bed34148860da6e69fca27a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -4,6 +4,10 @@ public class StartSeneData : MonoBehaviour
|
||||
{
|
||||
[Header("Game mode")]
|
||||
public int gamemode = 0;// default trainning mode
|
||||
[Header("Targets Prob")]
|
||||
public float attackProb = 0f;
|
||||
public float gotoProb = 0f;
|
||||
public float defenceProb = 0f;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
||||
@@ -31,16 +31,8 @@ public class StartUIManager : MonoBehaviour
|
||||
// if time limit is over, load Train Scene
|
||||
sceneLoader.LoadGameScene(SceneLoader.SceneType.Train);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// while Train-StartButton Pressed
|
||||
public void OnTrainStartButtonPressed()
|
||||
{
|
||||
startSceneData.gamemode = 0;
|
||||
sceneLoader.LoadGameScene(SceneLoader.SceneType.Train);
|
||||
messageTextObj.text = "Loading Train Scene...";
|
||||
}
|
||||
// while StartButton-Play Pressed
|
||||
public void OnPlayButtonPressed()
|
||||
{
|
||||
@@ -48,5 +40,38 @@ public class StartUIManager : MonoBehaviour
|
||||
sceneLoader.LoadGameScene(SceneLoader.SceneType.Play);
|
||||
messageTextObj.text = "Loading Play Scene...";
|
||||
}
|
||||
|
||||
public void OnAttackTrainButtonPressed()
|
||||
{
|
||||
// while Train-Attack-Button Pressed
|
||||
startSceneData.attackProb = 1f;
|
||||
LoadTrainScene();
|
||||
}
|
||||
public void OnGotoTrainButtonPressed()
|
||||
{
|
||||
// while Train-Goto-Button Pressed
|
||||
startSceneData.gotoProb = 1f;
|
||||
LoadTrainScene();
|
||||
}
|
||||
public void OnFreeTrainButtonPressed()
|
||||
{
|
||||
// while Train-Free-Button Pressed
|
||||
LoadTrainScene();
|
||||
}
|
||||
public void OnMixTrainButtonPressed()
|
||||
{
|
||||
// while Train-Mix-Button Pressed
|
||||
startSceneData.attackProb = 0.333f;
|
||||
startSceneData.gotoProb = 0.333f;
|
||||
LoadTrainScene();
|
||||
}
|
||||
private void LoadTrainScene()
|
||||
{
|
||||
// load Train Scene
|
||||
sceneLoader.LoadGameScene(SceneLoader.SceneType.Train);
|
||||
messageTextObj.text = "Loading Train Scene...";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user