SetProjectorMaterialTime.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1.  using UnityEngine;
  2. // Use this Script in parent folder of all Humans
  3. [DefaultExecutionOrder(70)]
  4. public class SetProjectorMaterialTime : MonoBehaviour
  5. {
  6. [Header("Projector Materials:")]
  7. public Material year2019;
  8. public Material year2020;
  9. public Material year2021;
  10. public Material default_mat;
  11. [Header("Thief Settings")]
  12. public Material thief_mat;
  13. public bool showThief2019 = false;
  14. public bool showThief2020 = false;
  15. public bool showThief2021 = false;
  16. // Start is called before the first frame update
  17. void Start()
  18. {
  19. Component[] years = gameObject.GetComponentsInChildren<InstantiatePrefab>();
  20. Component[] thiefs = gameObject.GetComponentsInChildren<ReadFromCSV>();
  21. foreach (var year in years)
  22. {
  23. GameObject[][] humansGO = year.GetComponent<InstantiatePrefab>().humanGameObject;
  24. for (int i = 0; i < humansGO.Length; ++i)
  25. for (int j = 0; j < humansGO[i].Length; ++j)
  26. {
  27. // Decal Game Object is visible
  28. humansGO[i][j].transform.Find("Decal").gameObject.SetActive(true);
  29. if (humansGO[i][j].CompareTag("2021"))
  30. humansGO[i][j].transform.Find("Decal").GetComponent<Projector>().material = year2021;
  31. else if (humansGO[i][j].CompareTag("2020"))
  32. humansGO[i][j].transform.Find("Decal").GetComponent<Projector>().material = year2020;
  33. else if (humansGO[i][j].CompareTag("2019"))
  34. humansGO[i][j].transform.Find("Decal").GetComponent<Projector>().material = year2019;
  35. else
  36. humansGO[i][j].transform.Find("Decal").GetComponent<Projector>().material = default_mat;
  37. }
  38. foreach (var thief in thiefs)
  39. {
  40. int thief_i = thief.GetComponent<ReadFromCSV>().thief_i;
  41. int thief_j = thief.GetComponent<ReadFromCSV>().thief_j;
  42. if (humansGO[0][0].CompareTag("2021") && thief.CompareTag("2021") && showThief2021)
  43. {
  44. humansGO[thief_i][thief_j].transform.Find("Decal").GetComponent<Projector>().material = thief_mat;
  45. break;
  46. }
  47. if (humansGO[0][0].CompareTag("2020") && thief.CompareTag("2020") && showThief2020)
  48. {
  49. humansGO[thief_i][thief_j].transform.Find("Decal").GetComponent<Projector>().material = thief_mat;
  50. break;
  51. }
  52. if (humansGO[0][0].CompareTag("2019") && thief.CompareTag("2019") && showThief2019)
  53. {
  54. humansGO[thief_i][thief_j].transform.Find("Decal").GetComponent<Projector>().material = thief_mat;
  55. break;
  56. }
  57. }
  58. }
  59. }
  60. }