Scriptum/Assets/Scripts/Task/TaskPanelController.cs
2022-06-11 23:12:52 +02:00

56 lines
1.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System;
public class TaskPanelController : MonoBehaviour
{
[Header("Panel Information")]
[SerializeField] protected GameObject _panelContent;
[SerializeField] private TaskBox taskbox_template;
[SerializeField] private List<TaskBox> taskBox_list;
protected void InitPanelBoxes(List<Task> _tasks)
{
if(_panelContent)
{
for(int i = 0; i < _tasks.Count; i++)
{
this.AddTask(_tasks[i]);
}
}
}
protected TaskBox SetupTaskBox(Task _task)
{
TaskBox _newTaskBox = Instantiate(taskbox_template, _panelContent.transform.position, Quaternion.identity).GetComponent<TaskBox>();
_newTaskBox.transform.SetParent(_panelContent.transform);
_newTaskBox.transform.localScale = new Vector3(2.5f, 2.5f, 1.0f);
_newTaskBox.SetTask(_task);
return _newTaskBox;
}
public void Setup(List<Task> _tasks)
{
this.InitPanelBoxes(_tasks);
}
public void AddTask(Task _task)
{
// update TaskManager main list of task
TaskManager.Instance.AddTask(_task);
// add task to local panel contant
TaskBox newTaskBox = SetupTaskBox(_task);
// Set new Slot instance
taskBox_list.Add(newTaskBox);
}
}