ZoneInfo.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class ZoneInfo : MonoBehaviour
  6. {
  7. public int id;
  8. public Zone zone;
  9. public ScrollRect scrollRect;
  10. public Text text;
  11. public Dictionary<uint, GameObject> users = new Dictionary<uint, GameObject>();
  12. // Start is called before the first frame update
  13. void Start()
  14. {
  15. }
  16. // Update is called once per frame
  17. void Update()
  18. {
  19. }
  20. public void AddWorker(User user)
  21. {
  22. if (!users.ContainsKey(user.id))
  23. {
  24. var user_name = Instantiate(text);
  25. user_name.fontSize = 12;
  26. user_name.transform.parent = scrollRect.content.transform;
  27. user_name.text = user.name_user;
  28. users[user.id] = user_name.gameObject;
  29. }
  30. }
  31. public void DeleteWorker(uint user_id)
  32. {
  33. if (users.ContainsKey(user_id))
  34. {
  35. var go = users[user_id];
  36. Destroy(go);
  37. users.Remove(user_id);
  38. }
  39. }
  40. public void UserDetectPosition(User user, Structure user_pos)
  41. {
  42. var coord = zone.Coordinates();
  43. if (coord[0] < user_pos.coord_x && coord[2] > user_pos.coord_x && coord[1] < user_pos.coord_y && coord[3] > user_pos.coord_y)
  44. {
  45. AddWorker(user);
  46. }
  47. else DeleteWorker(user.id);
  48. }
  49. }