2024-12-05 16:31:46 +08:00
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 ;
2024-12-05 16:31:46 +08:00
public class TaskPanel : Base
{
2024-12-06 11:29:20 +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-05 16:31:46 +08:00
// Start is called before the first frame update
void Start ( )
{
2024-12-06 11:29:20 +08:00
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
}
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-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 ;
2024-12-06 11:29:20 +08:00
TaskItem item = go . GetComponent < TaskItem > ( ) ;
item . SetInfo ( taskId [ i ] , JSONReader ) ;
2024-12-05 20:21:15 +08:00
}
2024-12-05 16:31:46 +08:00
}
2024-12-06 11:52:15 +08:00
public async Task DestroyTaskAsync ( )
{
DeleteAllChildObjects ( ) ;
await Task . Delay ( 10 ) ;
}
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-05 20:21:15 +08:00
2024-12-06 11:29:20 +08:00
public void SetInfo ( int id )
{
2024-12-06 11:52:15 +08:00
2024-12-06 11:29:20 +08:00
taskId . Add ( id ) ;
InitTask ( ) ;
}
2024-12-06 16:24:45 +08:00
2024-12-05 20:21:15 +08:00
2024-12-05 16:31:46 +08:00
// Update is called once per frame
void Update ( )
{
2024-12-06 11:29:20 +08:00
if ( Input . GetKeyDown ( KeyCode . J ) )
{
SetInfo ( 11001 ) ;
}
2024-12-05 16:31:46 +08:00
}
}