LogicScript.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using UdonSharp;
  2. using UnityEngine;
  3. using VRC.SDKBase;
  4. using VRC.Udon;
  5. using System;
  6. [Obsolete("Replaced with Linked Object System")]
  7. [UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
  8. [DisallowMultipleComponent]
  9. [AddComponentMenu("Artyom Scripting System/_DEPRECATED_/Logic Script")]
  10. public class LogicScript : UdonSharpBehaviour
  11. {
  12. public Animator[] animators; // Array to hold Animators
  13. public string[] parameterNames; // Array to hold corresponding parameter names
  14. public bool playerTriggerEnabled = true;
  15. public bool pickupTriggerEnabled = true;
  16. [UdonSynced]
  17. public int isOccupied;
  18. public GameObject audioObjectTrue; // GameObject to enable when the state changes to true
  19. public GameObject audioObjectFalse; // GameObject to enable when the state changes to false
  20. void Start()
  21. {
  22. isOccupied = 0;
  23. }
  24. private void UpdateAnims(bool state)
  25. {
  26. for (int i = 0; i < animators.Length; i++)
  27. {
  28. animators[i].SetBool(parameterNames[i], state);
  29. }
  30. // Enable or disable GameObjects based on the state
  31. if (state)
  32. {
  33. if (audioObjectFalse != null) audioObjectFalse.SetActive(false);
  34. if (audioObjectTrue != null) audioObjectTrue.SetActive(true);
  35. }
  36. else
  37. {
  38. if (audioObjectTrue != null) audioObjectTrue.SetActive(false);
  39. if (audioObjectFalse != null) audioObjectFalse.SetActive(true);
  40. }
  41. }
  42. private void OnTriggerEnter(Collider other)
  43. {
  44. if (pickupTriggerEnabled)
  45. {
  46. VRC_Pickup pickup = other.GetComponent<VRC_Pickup>();
  47. if (pickup != null)
  48. {
  49. isOccupied = isOccupied + 1;
  50. UpdateAnims(true);
  51. }
  52. }
  53. }
  54. public override void OnPlayerTriggerEnter(VRCPlayerApi player)
  55. {
  56. if (playerTriggerEnabled)
  57. {
  58. isOccupied = isOccupied + 1;
  59. if (isOccupied > 0)
  60. {
  61. UpdateAnims(true);
  62. }
  63. }
  64. }
  65. private void OnTriggerExit(Collider other)
  66. {
  67. if (pickupTriggerEnabled)
  68. {
  69. VRC_Pickup pickup = other.GetComponent<VRC_Pickup>();
  70. if (pickup != null)
  71. {
  72. isOccupied = isOccupied - 1;
  73. if (isOccupied < 1)
  74. {
  75. UpdateAnims(false);
  76. }
  77. }
  78. }
  79. }
  80. public override void OnPlayerTriggerExit(VRCPlayerApi player)
  81. {
  82. if (playerTriggerEnabled)
  83. {
  84. isOccupied = isOccupied - 1;
  85. if (isOccupied < 1)
  86. {
  87. UpdateAnims(false);
  88. }
  89. }
  90. }
  91. }