_xiaofang/xiaofang/Assets/Res/HYLUI/TaskPanel.cs

151 lines
3.4 KiB
C#
Raw Normal View History

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
2024-12-06 11:52:15 +08:00
using System.Threading.Tasks;
public class TaskPanel : Base
{
2024-12-11 20:16:45 +08:00
public static TaskPanel instance;
2024-12-05 20:21:15 +08:00
public List<int> taskId = new List<int>();
public Transform contentTrans;
public GameObject taskPrefab;
public JSONReader JSONReader;
public Dictionary<int, Language> taskDic = new Dictionary<int, Language>();
2024-12-06 16:24:45 +08:00
public RectTransform buttonRect; // <20><><EFBFBD>İ<EFBFBD>ť RectTransform
public Button hideBtn;
private bool isHidden = false; // <20><><EFBFBD><EFBFBD><EFBFBD>жϰ<D0B6>ť<EFBFBD>Ƿ<EFBFBD><C7B7>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>
public float moveDuration = 0.5f; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
public float hidePositionX = 125f; // <20><><EFBFBD>ص<EFBFBD><D8B5>ұߵ<D2B1> X <20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
public float showPositionX = -198f; // <20><>ʾʱ<CABE><CAB1>ť<EFBFBD><C5A5> X <20><><EFBFBD><EFBFBD>ֵ
2024-12-11 14:24:06 +08:00
public List<Button> buttons; // <20><><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>
public Color selectedColor = new Color(0.5f, 0.5f, 1f, 1f); // <20><>ɫ
public Color defaultColor = Color.white; // <20><>ɫ
// Start is called before the first frame update
void Start()
{
instance = this;
2024-12-05 20:21:15 +08:00
2024-12-06 16:24:45 +08:00
hideBtn.onClick.AddListener(OnClickHideButton);
2024-12-09 09:46:52 +08:00
2024-12-06 16:24:45 +08:00
}
2024-12-12 11:04:48 +08:00
2024-12-06 16:24:45 +08:00
2024-12-12 11:04:48 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
2024-12-06 16:24:45 +08:00
public void OnClickHideButton()
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
if (isHidden)
{
// <20>ָ<EFBFBD><D6B8><EFBFBD>ť<EFBFBD><C5A5>ԭλ<D4AD><CEBB>
buttonRect.DOAnchorPosX(showPositionX, moveDuration).SetEase(Ease.InOutCubic);
2024-12-09 09:46:52 +08:00
hideBtn.transform.Rotate(0, 0, 180f);
2024-12-06 16:24:45 +08:00
isHidden = false; // <20><><EFBFBD><EFBFBD>״̬Ϊδ<CEAA><CEB4><EFBFBD><EFBFBD>
}
else
{
// <20><><EFBFBD>ذ<EFBFBD>ť
buttonRect.DOAnchorPosX(hidePositionX, moveDuration).SetEase(Ease.InOutCubic);
2024-12-09 09:46:52 +08:00
hideBtn.transform.Rotate(0, 0, 180f);
2024-12-06 16:24:45 +08:00
isHidden = true; // <20><><EFBFBD><EFBFBD>״̬Ϊ<CCAC><CEAA><EFBFBD><EFBFBD>
}
2024-12-05 20:21:15 +08:00
}
2024-12-11 14:24:06 +08:00
//ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-12-06 11:52:15 +08:00
public async void InitTask()
2024-12-05 20:21:15 +08:00
{
2024-12-06 11:52:15 +08:00
await DestroyTaskAsync();
2024-12-05 20:21:15 +08:00
for(int i = 0; i < taskId.Count;i++)
{
GameObject go = GameObject.Instantiate(taskPrefab, contentTrans);
go.transform.name = "Task_" + i;
TaskItem item = go.GetComponent<TaskItem>();
item.SetInfo(taskId[i], JSONReader);
2024-12-11 14:24:06 +08:00
Button button = go.GetComponent<Button>();
button.onClick.AddListener(() => OnButtonClicked(button));
buttons.Add(button);
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
void OnButtonClicked(Button clickedButton)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>а<EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
foreach (Button button in buttons)
{
Image buttonImage = button.GetComponent<Image>();
if (button == clickedButton)
{
// <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD>ɫΪ<C9AB><CEAA>ɫ
buttonImage.color = selectedColor;
}
else
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ťΪ<C5A5><CEAA>ɫ
buttonImage.color = defaultColor;
}
2024-12-05 20:21:15 +08:00
}
}
2024-12-11 15:53:49 +08:00
2024-12-06 11:52:15 +08:00
public async Task DestroyTaskAsync()
{
DeleteAllChildObjects();
await Task.Delay(10);
}
2024-12-11 15:53:49 +08:00
2024-12-06 11:52:15 +08:00
public void DeleteAllChildObjects()
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>岢ɾ<E5B2A2><C9BE>
foreach (Transform child in contentTrans)
{
Destroy(child.gameObject);
}
2024-12-11 14:24:06 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ť
buttons.Clear();
2024-12-06 11:52:15 +08:00
}
2024-12-05 20:21:15 +08:00
public void SetInfo(int id)
{
2024-12-06 11:52:15 +08:00
taskId.Add(id);
InitTask();
}
2024-12-06 16:24:45 +08:00
2024-12-05 20:21:15 +08:00
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.J))
{
SetInfo(11001);
}
}
}