StasisPodScript.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. 
  2. using GadgetCore.API;
  3. using System;
  4. using System.Collections;
  5. using System.Reflection;
  6. using UnityEngine;
  7. namespace StasisPod
  8. {
  9. public class StasisPodScript : MonoBehaviour
  10. {
  11. public static event Action<object[]> SetRPC;
  12. private void Start()
  13. {
  14. id = "x" + (Math.Floor(transform.position.x) / 4).ToString() + "y" + (Math.Floor(transform.position.y) / 4).ToString();
  15. SetRPC += this.Set;
  16. }
  17. private void OnDestroy()
  18. {
  19. SetRPC -= this.Set;
  20. }
  21. private void Set(object[] o)
  22. {
  23. if (o[0].ToString() == id)
  24. {
  25. this.inUse = (bool)o[1];
  26. UpdateTile();
  27. }
  28. }
  29. internal void StartCallSet(bool inUse)
  30. {
  31. StartCoroutine(CallSet(inUse));
  32. }
  33. private IEnumerator CallSet(bool inUse)
  34. {
  35. yield return new WaitForSeconds(0.01f);
  36. GadgetCoreAPI.CallCustomRPC("SetPodInUse", RPCMode.AllBuffered, new object[] { this.id, inUse });
  37. yield break;
  38. }
  39. private void UpdateTile()
  40. {
  41. gameObject.transform.GetChild(1).gameObject.SetActive(inUse);
  42. }
  43. internal bool CanUse()
  44. {
  45. return !inUse;
  46. }
  47. public bool inUse = false;
  48. public string id;
  49. internal static void CallEventSetRPC(object[] args)
  50. {
  51. var setFrameItemRPC = StasisPodScript.SetRPC;
  52. if (setFrameItemRPC == null)
  53. return;
  54. setFrameItemRPC(args);
  55. }
  56. }
  57. }