ND_SimulationAutomaticControl/Assets/Scripts/SubjectToggle.cs

106 lines
2.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<Toggle>();
//targetimage = GetControl<Image>("实验对应图片");
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));
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));
}
/// <summary>
/// 加载文件夹中图片
/// </summary>
/// <param name="path"></param>
public void LoadImage(string path)
{
Sprite sprite = Resources.Load<Sprite>(path);
if (sprite != null)
{
ChooesPanel.targetimage.sprite = sprite;
Debug.Log("sprite加载成功");
}
else
{
Debug.Log("sprite加载失败当前文件夹未找到");
}
}
/// <summary>
/// toggle变大
/// </summary>
/// <param name="isOn"></param>
/// <returns></returns>
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);
}
}
}