Assignment for RMIT Mixed Reality in 2020
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.

48 lines
1.3 KiB

  1. using UnityEngine;
  2. public class GazeTargetSpawner : MonoBehaviour
  3. {
  4. public GameObject GazeTargetPrefab;
  5. public int NumberOfDummyTargets = 100;
  6. public int RadiusMultiplier = 3;
  7. [SerializeField]
  8. private bool isVisible;
  9. public bool IsVisible
  10. {
  11. get
  12. {
  13. return isVisible;
  14. }
  15. set
  16. {
  17. isVisible = value;
  18. GazeTarget[] dummyGazeTargets = gameObject.GetComponentsInChildren<GazeTarget>();
  19. for (int i = 0; i < dummyGazeTargets.Length; ++i)
  20. {
  21. MeshRenderer dummyMesh = dummyGazeTargets[i].GetComponent<MeshRenderer>();
  22. if (dummyMesh != null)
  23. {
  24. dummyMesh.enabled = isVisible;
  25. }
  26. }
  27. }
  28. }
  29. void Start ()
  30. {
  31. for (int i = 0; i < NumberOfDummyTargets; ++i)
  32. {
  33. GameObject target = Instantiate(GazeTargetPrefab, transform);
  34. target.name += "_" + i;
  35. target.transform.localPosition = Random.insideUnitSphere * RadiusMultiplier;
  36. target.transform.rotation = Quaternion.identity;
  37. target.GetComponent<MeshRenderer>().enabled = IsVisible;
  38. }
  39. }
  40. void OnValidate()
  41. {
  42. // Run through OnValidate to pick up changes from inspector
  43. IsVisible = isVisible;
  44. }
  45. }