GetSubstring.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. namespace BehaviorDesigner.Runtime.Tasks.Unity.UnityString
  2. {
  3. [TaskCategory("Unity/String")]
  4. [TaskDescription("Stores a substring of the target string")]
  5. public class GetSubstring : Action
  6. {
  7. [Tooltip("The target string")]
  8. public SharedString targetString;
  9. [Tooltip("The start substring index")]
  10. public SharedInt startIndex = 0;
  11. [Tooltip("The length of the substring. Don't use if -1")]
  12. public SharedInt length = -1;
  13. [Tooltip("The stored result")]
  14. [RequiredField]
  15. public SharedString storeResult;
  16. public override TaskStatus OnUpdate()
  17. {
  18. if (length.Value != -1) {
  19. storeResult.Value = targetString.Value.Substring(startIndex.Value, length.Value);
  20. } else {
  21. storeResult.Value = targetString.Value.Substring(startIndex.Value);
  22. }
  23. return TaskStatus.Success;
  24. }
  25. public override void OnReset()
  26. {
  27. targetString = "";
  28. startIndex = 0;
  29. length = -1;
  30. storeResult = "";
  31. }
  32. }
  33. }