GetShadowStrength.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using UnityEngine;
  2. namespace BehaviorDesigner.Runtime.Tasks.Unity.UnityLight
  3. {
  4. [TaskCategory("Unity/Light")]
  5. [TaskDescription("Stores the color of the light.")]
  6. public class GetShadowStrength : Action
  7. {
  8. [Tooltip("The GameObject that the task operates on. If null the task GameObject is used.")]
  9. public SharedGameObject targetGameObject;
  10. [RequiredField]
  11. [Tooltip("The color to store")]
  12. public SharedFloat storeValue;
  13. // cache the light component
  14. private Light light;
  15. private GameObject prevGameObject;
  16. public override void OnStart()
  17. {
  18. var currentGameObject = GetDefaultGameObject(targetGameObject.Value);
  19. if (currentGameObject != prevGameObject) {
  20. light = currentGameObject.GetComponent<Light>();
  21. prevGameObject = currentGameObject;
  22. }
  23. }
  24. public override TaskStatus OnUpdate()
  25. {
  26. if (light == null) {
  27. Debug.LogWarning("Light is null");
  28. return TaskStatus.Failure;
  29. }
  30. storeValue = light.shadowStrength;
  31. return TaskStatus.Success;
  32. }
  33. public override void OnReset()
  34. {
  35. targetGameObject = null;
  36. storeValue = 0;
  37. }
  38. }
  39. }