using DG.Tweening; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class SubjectToggle : BaseItem, IPointerEnterHandler, IPointerExitHandler { public Toggle Toggle_Subject; public UI_ChooesPanel ChooesPanel; public UI_TopTitlePanel TopTitlePanel; //public Image targetimage; // public bool isIPointer; //是否放上去 // Start is called before the first frame update void Start() { Toggle_Subject = GetComponent(); Toggle_Subject.onValueChanged.AddListener((ison) => { switch (transform.name) { case "Subject1": Bootstrap.Instance.uiManager.HidePanel(); Bootstrap.Instance.uiManager.ShowPanel(this, E_UI_Layer.System, (panel) => { Bootstrap.Instance.eventCenter.EventTrigger(Enum_EventType.UpdateProgress, 0.5f); Bootstrap.Instance.scenesManager.LoadSceneAsyn(this, "xianchang-TSQ", () => { Bootstrap.Instance.uiManager.ShowPanel(this, E_UI_Layer.Top, (panel) => { Bootstrap.Instance.eventCenter.EventTrigger(Enum_EventType.UpdateProgress, 0.5f); Bootstrap.Instance.scenesManager.LoadSceneAsyn(this, "xianchang-TSQ", () => { Bootstrap.Instance.uiManager.HidePanel(); Debug.Log("加载场景成功"); Bootstrap.Instance.eventCenter.EventTrigger(Enum_EventType.UpdateProgress, 2f); }); }); }); }); break; case "Subject2": break; case "Subject3": break; case "Subject4": break; } }); } public void OnPointerEnter(PointerEventData eventData) { isIPointer = true; StartCoroutine(ToggleDoScale(isIPointer)); ChooesPanel.targetimage.gameObject.SetActive(true); switch (transform.name) { case "Subject1": LoadImage("Sprite/1"); Debug.Log("1111"); break; case "Subject2": LoadImage("Sprite/2"); Debug.Log("2222"); break; case "Subject3": LoadImage("Sprite/3"); Debug.Log("3333"); break; case "Subject4": Debug.Log("4444"); break; } } public void OnPointerExit(PointerEventData eventData) { isIPointer = false; ChooesPanel.targetimage.gameObject.SetActive(isIPointer); StartCoroutine(ToggleDoScale(isIPointer)); } /// /// 加载文件夹中图片 /// /// public void LoadImage(string path) { Sprite sprite = Resources.Load(path); if (sprite != null) { ChooesPanel.targetimage.sprite = sprite; Debug.Log("sprite加载成功"); } else { Debug.Log("sprite加载失败,当前文件夹未找到"); } } /// /// toggle变大 /// /// /// IEnumerator ToggleDoScale(bool isOn) { yield return new WaitForSeconds(0.2f); if (isOn) { Toggle_Subject.transform.DOScale(1.5f, 0.1f); } else { Toggle_Subject.transform.DOScale(1f, 0.1f); } } }