Cute_demon_attacks/meng_yao/Assets/script/JumpScene/SceneBtn.cs
2024-10-30 01:08:16 +08:00

171 lines
4.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
public class SceneBtn : MonoBehaviour
{
public Button shopbtn;
public Button Developbtn;
public Button Troughbtn;
public Button Herobtn;
public Button Treebtn;
public Sprite showtextbg;
public Sprite showtextup;
public Sprite removetextbg;
public Sprite removetextup;
private RectTransform Developpanel;
private RectTransform shoppanel;
private RectTransform Troughpanel;
private RectTransform heropanel;
private RectTransform treepanel;
private Image shopimagebg;
private Image shopimagerup;
private Image Developimagebg;
private Image Developimagerup;
private Image Troughimagebg;
private Image Troughmagerup;
private Image Heroimagebg;
private Image Heroimagerup;
private Image Treeimagebg;
private Image Treeimagerup;
Vector3 Deflate = new Vector3(0.5f, 0.5f, 0.5f);
void Start()
{
shopbtn.onClick.AddListener(shopClick);
Developbtn.onClick.AddListener(DevelopClick);
Troughbtn.onClick.AddListener(TroughClick);
Herobtn.onClick.AddListener(HeroClick);
Treebtn.onClick.AddListener(TreeClick);
Developpanel = Developbtn.GetComponent<RectTransform>();
shoppanel = shopbtn.GetComponent<RectTransform>();
Troughpanel = Troughbtn.GetComponent<RectTransform>();
heropanel = Herobtn.GetComponent<RectTransform>();
treepanel = Treebtn.GetComponent<RectTransform>();
shopimagebg = shopbtn.transform.Find("Bg").GetComponent<Image>();
shopimagerup= shopbtn.transform.Find("TxtBorder").GetComponent<Image>();
Developimagebg = Developbtn.transform.Find("Bg").GetComponent<Image>();
Developimagerup = Developbtn.transform.Find("TxtBorder").GetComponent<Image>();
Troughimagebg = Troughbtn.transform.Find("Bg").GetComponent<Image>();
Troughmagerup = Troughbtn.transform.Find("TxtBorder").GetComponent<Image>();
Heroimagebg =Herobtn.transform.Find("Bg").GetComponent<Image>();
Heroimagerup = Herobtn.transform.Find("TxtBorder").GetComponent<Image>();
Treeimagebg = Treebtn.transform.Find("Bg").GetComponent<Image>();
Treeimagerup = Treebtn.transform.Find("TxtBorder").GetComponent<Image>();
BeginLoad(JumpScene.jumpbool);
}
void shopClick()
{
RemoveImage();
Showimage(shopimagebg, shopimagerup);
shoppanel.DOScale(Deflate, 0.3f).SetEase(Ease.OutBack);
StartCoroutine(Magnify(shoppanel));
UIScreenMgr.instance.ShowScreen(0);
}
void DevelopClick()
{
RemoveImage();
Showimage(Developimagebg, Developimagerup);
Developpanel.DOScale(Deflate,0.3f).SetEase(Ease.OutBack);
StartCoroutine(Magnify(Developpanel));
UIScreenMgr.instance.ShowScreen(1);
}
void TroughClick()
{
RemoveImage();
Showimage(Troughimagebg, Troughmagerup);
Troughpanel.DOScale(Deflate, 0.3f).SetEase(Ease.OutBack);
StartCoroutine(Magnify(Troughpanel));
UIScreenMgr.instance.ShowScreen(2);
}
void HeroClick()
{
RemoveImage();
Showimage(Heroimagebg, Heroimagerup);
heropanel.DOScale(Deflate, 0.3f).SetEase(Ease.OutBack);
StartCoroutine(Magnify(heropanel));
UIScreenMgr.instance.ShowScreen(3);
}
void TreeClick()
{
}
void Showimage(Image im,Image im2)
{
im.sprite = showtextbg;
im2.sprite = showtextup;
}
public void RemoveImage()
{
shopimagebg.sprite = removetextbg;
shopimagerup.sprite = removetextup;
Developimagebg.sprite = removetextbg;
Developimagerup.sprite = removetextup;
Troughimagebg.sprite = removetextbg;
Troughmagerup.sprite = removetextup;
Heroimagebg.sprite = removetextbg;
Heroimagerup.sprite = removetextup;
Treeimagebg.sprite = removetextbg;
Treeimagerup.sprite = removetextup;
}
IEnumerator Magnify(RectTransform allpanel)
{
yield return null;
allpanel.DOScale(Vector3.one, 0.5f).SetEase(Ease.OutBack);
}
public void BeginLoad(int i)
{
RemoveImage();
switch (i)
{
case 0:
Showimage(shopimagebg, shopimagerup);
break;
case 1:
Showimage(Developimagebg, Developimagerup);
break;
case 2:
Showimage(Troughimagebg, Troughmagerup);
break;
case 3:
Showimage(Heroimagebg, Heroimagerup);
break;
}
}
}