summaryrefslogtreecommitdiff
path: root/Client/Assets/Behavior Designer/Runtime/Basic Tasks/String/GetSubstring.cs
blob: be5de33ed74b0fc47a8d8fa5725c35fc63f519d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using UnityEngine;

namespace BehaviorDesigner.Runtime.Tasks.Basic.UnityString
{
    [TaskCategory("Basic/String")]
    [TaskDescription("Stores a substring of the target string")]
    public class GetSubstring : Action
    {
        [Tooltip("The target string")]
        public SharedString targetString;
        [Tooltip("The start substring index")]
        public SharedInt startIndex = 0;
        [Tooltip("The length of the substring. Don't use if -1")]
        public SharedInt length = -1;
        [Tooltip("The stored result")]
        [RequiredField]
        public SharedString storeResult;

        public override TaskStatus OnUpdate()
        {
            if (length.Value != -1) {
                storeResult.Value = targetString.Value.Substring(startIndex.Value, length.Value);
            } else {
                storeResult.Value = targetString.Value.Substring(startIndex.Value);
            }
            return TaskStatus.Success;
        }

        public override void OnReset()
        {
            targetString = "";
            startIndex = 0;
            length = -1;
            storeResult = "";
        }
    }
}