-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBulkSetActive.cs
90 lines (81 loc) · 2.89 KB
/
BulkSetActive.cs
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// This code is part of the Fungus library (https://github.com/snozbot/fungus)
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
using UnityEngine;
using UnityEngine.Serialization;
using System.Collections;
using System;
using UnityEngine.UI;
namespace Fungus
{
/// <summary>
/// Sets a game object in the scene to be active / inactive.
/// </summary>
[CommandInfo("Scripting",
"Bulk Set Active",
"Set gameobjects in the scene to be active / inactive.")]
[AddComponentMenu("")]
[ExecuteInEditMode]
public class BulkSetActive : Command
{
[System.Serializable]
public class BulkDrop
{
public GameObjectData gamobjects;
public BooleanData activeState;
public float delay = 0;
}
[SerializeField] public BulkDrop[] _targetGameObject = new BulkDrop[1];
private IEnumerator coroutine;
#region Public members
protected void bulktrigger()
{
coroutine = bulkActive(0);
StartCoroutine(coroutine);
}
protected IEnumerator bulkActive(float waitframe)
{
for (int i = 0; i < _targetGameObject.Length; i++)
{
if (_targetGameObject[i].activeState == true && _targetGameObject[i].gamobjects.Value != null)
{
//Delay after each iteration.
if (i % 1 == 0)
{
_targetGameObject[i].gamobjects.Value.SetActive(true);
yield return new WaitForSeconds(_targetGameObject[i].delay);
}
}
if (_targetGameObject[i].activeState == false && _targetGameObject[i].gamobjects.Value != null)
{
//Delay after each iteration.
if (i % 1 == 0)
{
_targetGameObject[i].gamobjects.Value.SetActive(false);
yield return new WaitForSeconds(_targetGameObject[i].delay);
}
}
}
}
public override bool HasReference(Variable variable)
{
//this is funky :0
bool tmpBool = true;
for(int i = 0; i < _targetGameObject.Length; i++)
{
tmpBool = _targetGameObject[i].gamobjects.gameObjectRef == variable || _targetGameObject[i].activeState.booleanRef == variable ||
base.HasReference(variable);
}
return tmpBool;
}
public override void OnEnter()
{
bulktrigger();
Continue();
}
public override Color GetButtonColor()
{
return new Color32(235, 191, 217, 255);
}
#endregion
}
}