修复Canvas大小变更时UI不随之移动错误。使用UIColorContainer来储存Color信息。
(cherry picked from commit 5ccaeefa5c)
This commit is contained in:
@@ -10,29 +10,25 @@ public class ButtonActivateColorChanger : MonoBehaviour
|
||||
public List<Button> clickableButton = new List<Button>();
|
||||
public List<Button> unclickableButton = new List<Button>();
|
||||
|
||||
public Color32 normalTextColor = new Color32(236, 236, 236, 255);
|
||||
public Color32 normalBGColor = new Color32(255, 255, 255, 0);
|
||||
public Color32 highLightTextColor = new Color32(41, 41, 41, 230);
|
||||
public Color32 highLightBGColor = new Color32(255, 255, 255, 103);
|
||||
public Color32 pressedTextColor = new Color32(0, 0, 0, 240);
|
||||
public Color32 pressedBGColor = new Color32(255, 255, 255, 160);
|
||||
public Color32 disableTextColor = new Color32(180, 180, b: 180, 80);
|
||||
public Color32 disableBGColor = new Color32(255, 255, b: 255, 0);
|
||||
public float colorChangeSpeed = 0.1f;
|
||||
|
||||
public bool clickable = true;
|
||||
|
||||
[SerializeField] private UIColorContainer uiColor;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
foreach (Button btn in clickableButton)
|
||||
{
|
||||
InitializeEventTriggers(btn, true);
|
||||
InitializeButtonColor(btn);
|
||||
}
|
||||
|
||||
foreach (Button btn in unclickableButton)
|
||||
{
|
||||
InitializeEventTriggers(btn, false);
|
||||
InitializeButtonColor(btn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +54,15 @@ public class ButtonActivateColorChanger : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeButtonColor(Button btn)
|
||||
{
|
||||
if (btn.interactable)
|
||||
{
|
||||
btn.image.DOColor(uiColor.normal.bg, colorChangeSpeed);
|
||||
btn.GetComponentInChildren<TextMeshProUGUI>().DOColor(uiColor.normal.text, colorChangeSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an event trigger entry to an event trigger.
|
||||
/// </summary>
|
||||
@@ -76,8 +81,8 @@ public class ButtonActivateColorChanger : MonoBehaviour
|
||||
{
|
||||
if (btn.interactable)
|
||||
{
|
||||
btn.image.DOColor(highLightBGColor, colorChangeSpeed);
|
||||
btn.GetComponentInChildren<TextMeshProUGUI>().DOColor(highLightTextColor, colorChangeSpeed);
|
||||
btn.image.DOColor(uiColor.highLight.bg, colorChangeSpeed);
|
||||
btn.GetComponentInChildren<TextMeshProUGUI>().DOColor(uiColor.highLight.text, colorChangeSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,8 +90,8 @@ public class ButtonActivateColorChanger : MonoBehaviour
|
||||
{
|
||||
if (btn.interactable)
|
||||
{
|
||||
btn.image.DOColor(normalBGColor, colorChangeSpeed);
|
||||
btn.GetComponentInChildren<TextMeshProUGUI>().DOColor(normalTextColor, colorChangeSpeed);
|
||||
btn.image.DOColor(uiColor.normal.bg, colorChangeSpeed);
|
||||
btn.GetComponentInChildren<TextMeshProUGUI>().DOColor(uiColor.normal.text, colorChangeSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,8 +99,8 @@ public class ButtonActivateColorChanger : MonoBehaviour
|
||||
{
|
||||
if (btn.interactable)
|
||||
{
|
||||
btn.image.DOColor(pressedBGColor, colorChangeSpeed);
|
||||
btn.GetComponentInChildren<TextMeshProUGUI>().DOColor(pressedTextColor, colorChangeSpeed);
|
||||
btn.image.DOColor(uiColor.pressed.bg, colorChangeSpeed);
|
||||
btn.GetComponentInChildren<TextMeshProUGUI>().DOColor(uiColor.pressed.text, colorChangeSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,8 +108,8 @@ public class ButtonActivateColorChanger : MonoBehaviour
|
||||
{
|
||||
if (btn.interactable)
|
||||
{
|
||||
btn.image.DOColor(highLightBGColor, colorChangeSpeed);
|
||||
btn.GetComponentInChildren<TextMeshProUGUI>().DOColor(normalTextColor, colorChangeSpeed);
|
||||
btn.image.DOColor(uiColor.highLight.bg, colorChangeSpeed);
|
||||
btn.GetComponentInChildren<TextMeshProUGUI>().DOColor(uiColor.highLight.text, colorChangeSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,13 +123,13 @@ public class ButtonActivateColorChanger : MonoBehaviour
|
||||
btn.interactable = changeTo;
|
||||
if (changeTo)
|
||||
{
|
||||
btn.image.DOColor(normalBGColor, colorChangeSpeed);
|
||||
btn.GetComponentInChildren<TextMeshProUGUI>().DOColor(normalTextColor, colorChangeSpeed);
|
||||
btn.image.DOColor(uiColor.normal.bg, colorChangeSpeed);
|
||||
btn.GetComponentInChildren<TextMeshProUGUI>().DOColor(uiColor.normal.text, colorChangeSpeed);
|
||||
}
|
||||
else
|
||||
{
|
||||
btn.image.DOColor(disableBGColor, colorChangeSpeed);
|
||||
btn.GetComponentInChildren<TextMeshProUGUI>().DOColor(disableTextColor, colorChangeSpeed);
|
||||
btn.image.DOColor(uiColor.disabled.bg, colorChangeSpeed);
|
||||
btn.GetComponentInChildren<TextMeshProUGUI>().DOColor(uiColor.disabled.text, colorChangeSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,13 +156,13 @@ public class ButtonActivateColorChanger : MonoBehaviour
|
||||
{
|
||||
foreach (Button btn in clickableButton)
|
||||
{
|
||||
btn.image.color = normalBGColor;
|
||||
btn.GetComponentInChildren<TextMeshProUGUI>().color = normalTextColor;
|
||||
btn.image.color = uiColor.normal.bg;
|
||||
btn.GetComponentInChildren<TextMeshProUGUI>().color = uiColor.normal.bg;
|
||||
}
|
||||
foreach (Button btn in unclickableButton)
|
||||
{
|
||||
btn.image.color = disableBGColor;
|
||||
btn.GetComponentInChildren<TextMeshProUGUI>().color = disableTextColor;
|
||||
btn.image.color = uiColor.disabled.bg;
|
||||
btn.GetComponentInChildren<TextMeshProUGUI>().color = uiColor.disabled.text;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
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 float animeMoveXDistance = 20f;
|
||||
public float animeMoveYDistance = 20f;
|
||||
|
||||
public float animeScaleX = 1.2f;
|
||||
public float animeScaleY = 1.2f;
|
||||
|
||||
public float maskScaleX = 1;
|
||||
public float maskScaleY = 0.4f;
|
||||
|
||||
private Vector3 mixOriginDestination;
|
||||
private Vector3 attackOriginDestination;
|
||||
private Vector3 gotoOriginDestination;
|
||||
private Vector3 freeOriginDestination;
|
||||
|
||||
private Vector3 mixDestination;
|
||||
private Vector3 attackDestination;
|
||||
private Vector3 gotoDestination;
|
||||
private Vector3 freeDestination;
|
||||
|
||||
private Vector3 originalCanvas;
|
||||
|
||||
private PolygonCollider2D parallelogramPolygon;
|
||||
private bool isMouseOverMask = false;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
originalCanvas = transform.parent.position;
|
||||
// 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.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);
|
||||
|
||||
//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(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();
|
||||
MaximizeMaskObj();
|
||||
}
|
||||
|
||||
private void OnMaskPointerExit()
|
||||
{
|
||||
// dotween move button batck to original position
|
||||
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();
|
||||
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();
|
||||
}
|
||||
|
||||
private Vector3 fixCanvas(Vector3 vector)
|
||||
{
|
||||
// fix position of button while canvas is changed
|
||||
Vector3 fixedV = vector;
|
||||
fixedV += (transform.parent.position - originalCanvas);
|
||||
return fixedV;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee00299c7bed34148860da6e69fca27a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class StartUIManager : MonoBehaviour
|
||||
{
|
||||
public int waitTimeLimit = 45;
|
||||
public GameObject sceneLoaderObj;
|
||||
public GameObject startSceneDataObj;
|
||||
public GameObject targetLevelProbabilityPanelOBJ;
|
||||
public TextMeshProUGUI messageTextObj;
|
||||
public TextMeshProUGUI waitTimeTextObj;
|
||||
|
||||
private SceneLoader sceneLoader;
|
||||
private StartSeneData startSceneData;
|
||||
private ButtonActivateColorChanger buttonActivateColorChanger;
|
||||
private StartMenuProbabilityPanel startMenuProbabilityPanel;
|
||||
private float startTime;
|
||||
private float nowTime;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
sceneLoader = sceneLoaderObj.GetComponent<SceneLoader>();
|
||||
startSceneData = startSceneDataObj.GetComponent<StartSeneData>();
|
||||
buttonActivateColorChanger = GetComponent<ButtonActivateColorChanger>();
|
||||
startMenuProbabilityPanel = targetLevelProbabilityPanelOBJ.GetComponent<StartMenuProbabilityPanel>();
|
||||
messageTextObj.text = "";
|
||||
buttonActivateColorChanger.InitializeAllButtonColor();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// update time limit left;
|
||||
float leftTime = waitTimeLimit - Time.realtimeSinceStartup;
|
||||
waitTimeTextObj.text = ((int)Math.Round(leftTime)).ToString();
|
||||
if (leftTime <= 1)
|
||||
{
|
||||
// if time limit is over, load Train Scene
|
||||
sceneLoader.LoadGameScene(SceneLoader.SceneType.Train);
|
||||
}
|
||||
}
|
||||
|
||||
// while StartButton-Play Pressed
|
||||
public void OnPlayButtonPressed()
|
||||
{
|
||||
startSceneData.gameMode = 1;
|
||||
sceneLoader.LoadGameScene(SceneLoader.SceneType.Play);
|
||||
messageTextObj.text = "Loading Play Scene...";
|
||||
}
|
||||
|
||||
public void OnAttackTrainButtonPressed()
|
||||
{
|
||||
// while Train-Attack-Button Pressed
|
||||
startSceneData.attackProb = 1f;
|
||||
ApplicateProbabilityToData();
|
||||
LoadTrainScene();
|
||||
}
|
||||
public void OnGotoTrainButtonPressed()
|
||||
{
|
||||
// while Train-Goto-Button Pressed
|
||||
startSceneData.gotoProb = 1f;
|
||||
ApplicateProbabilityToData();
|
||||
LoadTrainScene();
|
||||
}
|
||||
public void OnFreeTrainButtonPressed()
|
||||
{
|
||||
// while Train-Free-Button Pressed
|
||||
startSceneData.attackProb = 0f;
|
||||
startSceneData.gotoProb = 0f;
|
||||
startSceneData.defenceProb = 0f;
|
||||
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...";
|
||||
}
|
||||
|
||||
private void ApplicateProbabilityToData()
|
||||
{
|
||||
for (int i = 0; i < startSceneData.scenePrefabSet.targetLevels[0].levelSize; i++)
|
||||
{
|
||||
startSceneData.gotoLevelProbs.Add(startMenuProbabilityPanel.targetLevelProbabilityPanel[0].singleLevelPanels[i].ProbabilityValue);
|
||||
}
|
||||
for(int i = 0; i < startSceneData.scenePrefabSet.targetLevels[1].levelSize; i++)
|
||||
{
|
||||
startSceneData.attackLevelProbs.Add(startMenuProbabilityPanel.targetLevelProbabilityPanel[1].singleLevelPanels[i].ProbabilityValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7761fd42cad2b9544a15df1264649677
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,18 +1,36 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class UIColorContainer : MonoBehaviour
|
||||
[CreateAssetMenu(fileName = "UIColors", menuName = "UI/UIColors")]
|
||||
public class UIColorContainer : ScriptableObject
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
[System.Serializable]
|
||||
public struct UIButtonStateColors
|
||||
{
|
||||
|
||||
public Color32 text;
|
||||
public Color32 bg;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
public UIButtonStateColors normal = new UIButtonStateColors()
|
||||
{
|
||||
|
||||
}
|
||||
text = new Color32(236, 236, 236, 255),
|
||||
bg = new Color32(255, 255, 255, 0)
|
||||
};
|
||||
|
||||
public UIButtonStateColors highLight = new UIButtonStateColors()
|
||||
{
|
||||
text = new Color32(41, 41, 41, 230),
|
||||
bg = new Color32(255, 255, 255, 103)
|
||||
};
|
||||
|
||||
public UIButtonStateColors pressed = new UIButtonStateColors()
|
||||
{
|
||||
text = new Color32(0, 0, 0, 240),
|
||||
bg = new Color32(255, 255, 255, 160)
|
||||
};
|
||||
|
||||
public UIButtonStateColors disabled = new UIButtonStateColors()
|
||||
{
|
||||
text = new Color32(180, 180, b: 180, 80),
|
||||
bg = new Color32(255, 255, b: 255, 0)
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user