Files
Main/Assets/GameAssets/Resources/GameUI/Common/UIComponentContainer/UITaskComponent.cs
2025-01-25 04:38:09 +08:00

153 lines
4.3 KiB
C#

using UnityEngine;
using System.Collections;
using Thousandto.GameUI.Form;
using Thousandto.Core.Base;
using System;
namespace Thousandto.Plugins.Common
{
/// <summary>
/// 任务UI组件
/// </summary>
public class UITaskAttr
{
#region//私有变量
private int _taskId = 0; //任务ID
private bool _isOver = false; //是否完成
private bool _isSelect = false; //是否被选中
private string _name = null; //任务名字
public EventDelegate.Callback Call; //回调
#endregion
#region//公共变量
public int TaskID
{
get { return _taskId; }
set { _taskId = value; }
}
public bool IsOver
{
get { return _isOver; }
set { _isOver = value; }
}
public bool IsSelect
{
get { return _isSelect; }
set { _isSelect = value; }
}
public string Name
{
get { return _name; }
set { _name = value; }
}
#endregion
}
public class UITaskComponent : IUIComponentPlus<UITaskComponent, UITaskAttr>
{
#region //私有变量
private int _index = 0;
private UIButton _btn = null;
private UILabel _name = null;
private UISprite _doing = null; //进行图片
private UISprite _over = null; //完成图片
private Transform _selcet = null; //选中
public EventDelegate.Callback Call = null;
public int Index
{
get
{
return _index;
}
}
#endregion
public UITaskComponent(Transform trans, EventDelegate.Callback call,int index = 0)
{
if (trans)
{
_btn = trans.RequireComponent<UIButton>();
_btn.onClick.Clear();
_selcet = trans.Find("Select");
_selcet.gameObject.SetActive(false);
_btn.onClick.Add(new EventDelegate(call));
_name = trans.Find("Name").RequireComponent<UILabel>();
_doing = trans.Find("Doing").RequireComponent<UISprite>();
_over = trans.Find("Success").RequireComponent<UISprite>();
_index = index;
}
}
#region//公共变量
public void SetActive(bool b)
{
if (_btn)
{
_btn.transform.gameObject.SetActive(b);
}
}
public void SetData(UITaskAttr attr)
{
if (_name)
{
_name.text = attr.Name;
}
UIIconBase icon = null;
if (attr.IsOver)
{
if (_doing)
{
_doing.gameObject.SetActive(false);
}
if (_over)
{
_over.gameObject.SetActive(true);
}
}
else
{
if (_doing)
{
_doing.gameObject.SetActive(true);
}
if (_over)
{
_over.gameObject.SetActive(false);
}
}
if (_selcet)
{
_selcet.gameObject.SetActive(attr.IsSelect);
}
if (_btn != null)
{
_btn.onClick.Clear();
_btn.onClick.Add(new EventDelegate(attr.Call));
}
}
public void SetSelect(bool b)
{
if (_selcet)
{
_selcet.gameObject.SetActive(b);
}
}
public UITaskComponent Clone(EventDelegate.Callback call, int index)
{
GameObject newGameObject = (GameObject)(GameObject.Instantiate(_btn.gameObject));
newGameObject.transform.parent = _btn.transform.parent;
UnityUtils.Reset(newGameObject.transform);
UITaskComponent component = new UITaskComponent(newGameObject.transform, call,index);
return component;
}
public void Remove()
{
if (_btn != null)
{
GameObject.Destroy(_btn.gameObject);
}
}
#endregion
}
}