86 lines
2.4 KiB
C#
86 lines
2.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 TaskBoxTemplate;
|
|
[SerializeField] private GameObject TaskBoxTemplate;
|
|
[SerializeField] private List<GameObject> TaskBoxList;
|
|
|
|
/// <summary>
|
|
/// Fetch reference to static instance of UiManager script
|
|
/// </summary>
|
|
private static UIBaseManager<Task> _uiManager;
|
|
|
|
private UIBaseManager<Task> UiManager
|
|
{
|
|
get
|
|
{
|
|
if (_uiManager == null) { _uiManager = FetchUiManager(); }
|
|
|
|
return _uiManager;
|
|
}
|
|
}
|
|
|
|
// TODO decide whick method use and where bind object with itself
|
|
// public abstract void Bind(ManagerInterfac<T>e manager);
|
|
private UIBaseManager<Task> FetchUiManager() // check if need return by ref
|
|
{
|
|
var uiManager = GameObject.FindObjectOfType<TaskUIManager>();
|
|
|
|
// uiManager.SetPanelController(gameObject); - unnecessary
|
|
|
|
return uiManager;
|
|
}
|
|
|
|
public void InitPanelBoxes(List<Task> _tasks)
|
|
{
|
|
if (_panelContent == null)
|
|
throw new Exception("Panel content is not attaches");
|
|
|
|
for(int i = 0; i < _tasks.Count; i++)
|
|
{
|
|
this.AddTask(_tasks[i]);
|
|
}
|
|
}
|
|
|
|
protected GameObject SetupTaskBox(Task _task)
|
|
{
|
|
if (TaskBoxTemplate == null)
|
|
throw new Exception("taskbox_template is empty");
|
|
|
|
GameObject _newTaskBox = Instantiate(TaskBoxTemplate, _panelContent.transform.position, Quaternion.identity); //.GetComponent<TaskBox>();
|
|
|
|
_newTaskBox.transform.SetParent(_panelContent.transform);
|
|
|
|
_newTaskBox.transform.localScale = new Vector3(2.5f, 2.5f, 1.0f);
|
|
|
|
_newTaskBox.GetComponent<TaskBox>().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
|
|
GameObject newTaskBox = SetupTaskBox(_task);
|
|
|
|
// Set new Slot instance
|
|
TaskBoxList.Add(newTaskBox);
|
|
}
|
|
}
|