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 Image targetimage; // public bool isIPointer; //是否放上去 // Start is called before the first frame update void Start() { Toggle_Subject = GetComponent(); //targetimage = GetControl("实验对应图片"); Toggle_Subject.onValueChanged.AddListener((ison) => { switch (transform.name) { case "Subject1": break; case "Subject2": break; case "Subject3": break; case "Subject4": break; } }); } public void OnPointerEnter(PointerEventData eventData) { isIPointer = true; StartCoroutine(ToggleDoScale(isIPointer)); 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; 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加载失败,当前文件夹未找到"); } } 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); } } }