113 lines
3.2 KiB
C#
113 lines
3.2 KiB
C#
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>();
|
||
Toggle_Subject.onValueChanged.AddListener((ison) =>
|
||
{
|
||
switch (transform.name)
|
||
{
|
||
case "Subject1":
|
||
Bootstrap.Instance.uiManager.ShowPanel<UI_LoadingPanel>(this, E_UI_Layer.System, (panel) =>
|
||
{
|
||
Bootstrap.Instance.eventCenter.EventTrigger(Enum_EventType.UpdateProgress, 0.5f);
|
||
Bootstrap.Instance.scenesManager.LoadSceneAsyn(this, "Line", () =>
|
||
{
|
||
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));
|
||
}
|
||
|
||
/// <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);
|
||
}
|
||
}
|
||
}
|