修复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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+33
-16
@@ -11,10 +11,11 @@ public class StartMenuAnimations : MonoBehaviour
|
||||
|
||||
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 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;
|
||||
@@ -24,11 +25,19 @@ public class StartMenuAnimations : MonoBehaviour
|
||||
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;
|
||||
@@ -36,10 +45,10 @@ public class StartMenuAnimations : MonoBehaviour
|
||||
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;
|
||||
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>();
|
||||
@@ -66,20 +75,20 @@ public class StartMenuAnimations : MonoBehaviour
|
||||
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();
|
||||
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(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();
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -96,4 +105,12 @@ public class StartMenuAnimations : MonoBehaviour
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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