Replace.cs 920 B

1234567891011121314151617181920212223242526272829303132
  1. namespace BehaviorDesigner.Runtime.Tasks.Unity.UnityString
  2. {
  3. [TaskCategory("Unity/String")]
  4. [TaskDescription("Replaces a string with the new string")]
  5. public class Replace : Action
  6. {
  7. [Tooltip("The target string")]
  8. public SharedString targetString;
  9. [Tooltip("The old replace")]
  10. public SharedString oldString;
  11. [Tooltip("The new string")]
  12. public SharedString newString;
  13. [Tooltip("The stored result")]
  14. [RequiredField]
  15. public SharedString storeResult;
  16. public override TaskStatus OnUpdate()
  17. {
  18. storeResult.Value = targetString.Value.Replace(oldString.Value, newString.Value);
  19. return TaskStatus.Success;
  20. }
  21. public override void OnReset()
  22. {
  23. targetString = "";
  24. oldString = "";
  25. newString = "";
  26. storeResult = "";
  27. }
  28. }
  29. }