You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.7 KiB
60 lines
1.7 KiB
4 years ago
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
public class TaskItemView : MonoBehaviour
|
||
|
{
|
||
|
|
||
|
public Text TaskName;
|
||
|
public Image Background;
|
||
|
public Image Foreground;
|
||
|
public Toggle ToggleButton;
|
||
|
int mItemIndex = -1;
|
||
|
internal void SetData(TaskModel data, int index)
|
||
|
{
|
||
|
mItemIndex = index;
|
||
|
//gameObject.name = data.ID.ToString();
|
||
|
TaskName.text = data.Name;
|
||
|
TaskName.GetComponent<ContentSizeFitter>().SetLayoutHorizontal();
|
||
|
Vector2 size = Vector2.zero;
|
||
|
size.x = TaskName.GetComponent<RectTransform>().sizeDelta.x + 35;
|
||
|
size.y = TaskName.GetComponent<RectTransform>().sizeDelta.y;
|
||
|
Background.GetComponent<RectTransform>().sizeDelta = size;
|
||
|
Foreground.GetComponent<RectTransform>().sizeDelta = size;
|
||
|
RectTransform tf = gameObject.GetComponent<RectTransform>();
|
||
|
float x = Mathf.Max(63, size.x);
|
||
|
tf.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, x);
|
||
|
if (mItemIndex == ChatManager.Instance.SelectTaskIndex)
|
||
|
{
|
||
|
ToggleButton.isOn = true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ToggleButton.isOn = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
internal void Init()
|
||
|
{
|
||
|
ToggleButton.onValueChanged.AddListener(OnValueChanged);
|
||
|
}
|
||
|
|
||
|
private void OnValueChanged(bool check)
|
||
|
{
|
||
|
if (check == true)
|
||
|
{
|
||
|
ChatManager.Instance.SelectTaskIndex = mItemIndex;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (ChatManager.Instance.SelectTaskIndex == mItemIndex)
|
||
|
{
|
||
|
ChatManager.Instance.SelectTaskIndex = -1;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|