summaryrefslogtreecommitdiff
path: root/Client/Assets/Behavior Designer/Runtime/Basic Tasks/SharedVariables/SharedGameObjectsToGameObjectList.cs
blob: 5849ac45b62a774e30ab6d7ee5bc8c8f7195da8f (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
38
39
40
41
using UnityEngine;
using System.Collections.Generic;

namespace BehaviorDesigner.Runtime.Tasks.Basic.SharedVariables
{
    [TaskCategory("Basic/SharedVariable")]
    [TaskDescription("Sets the SharedGameObjectList values from the GameObjects. Returns Success.")]
    public class SharedGameObjectsToGameObjectList : Action
    {
        [Tooltip("The GameObjects value")]
        public SharedGameObject[] gameObjects;
        [RequiredField]
        [Tooltip("The SharedTransformList to set")]
        public SharedGameObjectList storedGameObjectList;

        public override void OnAwake()
        {
            storedGameObjectList.Value = new List<GameObject>();
        }

        public override TaskStatus OnUpdate()
        {
            if (gameObjects == null || gameObjects.Length == 0) {
                return TaskStatus.Failure;
            }

            storedGameObjectList.Value.Clear();
            for (int i = 0; i < gameObjects.Length; ++i) {
                storedGameObjectList.Value.Add(gameObjects[i].Value);
            }

            return TaskStatus.Success;
        }

        public override void OnReset()
        {
            gameObjects = null;
            storedGameObjectList = null;
        }
    }
}