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

237 lines
6.5 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);
public List<GameObject> Scenelist = new List<GameObject>();
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);
}
private void Update()
{
switch (JumpScene.jumpbool)
{
case 0: //
RemoveImage();
Showimage(shopimagebg, shopimagerup);
Removlist();
Appear();
break;
case 1://1
RemoveImage();
Showimage(Developimagebg, Developimagerup);
Removlist();
Appear();
break;
case 2://0
RemoveImage();
Showimage(Troughimagebg, Troughmagerup);
Removlist();
Appear();
break;
case 3://3
RemoveImage();
Showimage(Heroimagebg, Heroimagerup);
Removlist();
Appear();
break;
case 4://4
RemoveImage();
Showimage(Treeimagebg, Treeimagerup);
Removlist();
Appear();
break;
case 5:
Removlist();
Appear();
break;
default:
break;
}
}
void shopClick()
{
shoppanel.DOScale(Deflate, 0.3f).SetEase(Ease.OutBack);
StartCoroutine(Magnify(shoppanel));
JumpScene.jumpbool = 0;
//SceneGuodu.instance.SlideInAndLoadScene(JumpScene.shop_scene);
}
void DevelopClick()
{
Developpanel.DOScale(Deflate,0.3f).SetEase(Ease.OutBack);
StartCoroutine(Magnify(Developpanel));
JumpScene.jumpbool = 1;
//SceneGuodu.instance.SlideInAndLoadScene(JumpScene.develop_the_main_interface_slices);
}
void TroughClick()
{
Troughpanel.DOScale(Deflate, 0.3f).SetEase(Ease.OutBack);
StartCoroutine(Magnify(Troughpanel));
JumpScene.jumpbool = 2;
//SceneGuodu.instance.SlideInAndLoadScene(JumpScene.main_scene);
}
void HeroClick()
{
heropanel.DOScale(Deflate, 0.3f).SetEase(Ease.OutBack);
StartCoroutine(Magnify(heropanel));
JumpScene.jumpbool = 3;
//SceneGuodu.instance.SlideInAndLoadScene(JumpScene.heroBg);
}
void TreeClick()
{
treepanel.DOScale(Deflate, 0.3f).SetEase(Ease.OutBack);
StartCoroutine(Magnify(treepanel));
JumpScene.jumpbool = 4;
//SceneGuodu.instance.SlideInAndLoadScene(JumpScene.EcoTree);
}
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);
}
private void Removlist()
{
foreach (var i in Scenelist)
{
i.gameObject.SetActive(false);
}
}
private void Appear()
{
switch (JumpScene.jumpbool)
{
case 0:
Scenelist[0].gameObject.SetActive(true);
break;
case 1:
Scenelist[1].gameObject.SetActive(true);
break;
case 2:
Scenelist[2].gameObject.SetActive(true);
break;
case 3:
Scenelist[3].gameObject.SetActive(true);
break;
case 4:
Scenelist[4].gameObject.SetActive(true);
break;
case 5:
Scenelist[5].gameObject.SetActive(true);
break;
}
}
}