TaskCanvas.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class TaskCanvas : MonoBehaviour {
  6. public static TaskCanvas Instance;
  7. private void Awake()
  8. {
  9. Instance = this;
  10. gameObject.SetActive(false);
  11. }
  12. public Color NoColor;
  13. public Color OkColor;
  14. public GameObject BackGround = null;
  15. public GameObject Template;
  16. public List<TaskInfo> mTaskDate = new List<TaskInfo>();
  17. private Vector3 initBackGroundScale = Vector3.zero;
  18. private void Start()
  19. {
  20. initBackGroundScale = BackGround.transform.localScale;
  21. }
  22. public void CreateCanvas(List<TaskDate> pauseList)
  23. {
  24. for (int i = 0; i < pauseList.Count; i++)
  25. {
  26. // GameObject s = PrefabManager.Instance.GetPrefab("Col", Template);
  27. GameObject s = GameObject.Instantiate(Template, Template.transform.parent);
  28. s.transform.position -= new Vector3(0, i * 0.1f, 0);
  29. s.transform.parent = Template.transform.parent;
  30. s.SetActive(true);
  31. TaskInfo t = s.GetComponent<TaskInfo>();
  32. t.num.text = (i + 1).ToString();
  33. t.mText.text = pauseList[i].TaskName;
  34. t.Panel.color = pauseList[i].isOk ? OkColor : NoColor;
  35. mTaskDate.Add(t);
  36. }
  37. BackGround.transform.localScale = new Vector3(1,
  38. BackGround.transform.localScale.y + pauseList.Count * 0.35f, 1);
  39. }
  40. public void FinishTask(int index)
  41. {
  42. mTaskDate[index].Panel.color = OkColor;
  43. }
  44. public void ClearTask()
  45. {
  46. for (int i = 0; i < mTaskDate.Count; i++)
  47. {
  48. mTaskDate[i].Panel.color = NoColor;
  49. }
  50. }
  51. public void CloseTask()
  52. {
  53. for (int i = 0; i < mTaskDate.Count; i++)
  54. {
  55. Destroy(mTaskDate[i].gameObject);
  56. }
  57. BackGround.transform.localScale = initBackGroundScale;
  58. mTaskDate.Clear();
  59. }
  60. void Update () {
  61. }
  62. }