Tanoda
CountdownAction.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Runtime.Serialization;
4using UnityEngine;
5using UnityEngine.UI;
6
7public class CountdownAction : ActionObject, ISerializable
8{
9 public InputField time;
10 [HideInInspector] public float countdown;
11
12 private void Awake()
13 {
14 action = GetType().Name;
15 }
16
17 new void Start()
18 {
19 base.Start();
20 if (countdown != 0.0f) time.text = countdown.ToString();
21 }
22
23 public override void Triggered(string id)
24 {
25 base.Triggered(id);
26
27 StartCoroutine(Timer());
28 countdown = float.Parse(time.text);
29 }
30
31 IEnumerator Timer()
32 {
33 Debug.Log("Waiting for " + time.text + " seconds");
34 yield return new WaitForSeconds(float.Parse(time.text));
35 Debug.Log("next...");
36 TriggerOutput(outPuts[0].name);
37 }
38
39 public void InputEnded(string value)
40 {
41 try
42 {
43 countdown = float.Parse(time.text);
44 }
45 catch (Exception e)
46 {
47 time.text = "0";
48 }
49 }
50
51 public new void GetObjectData(SerializationInfo info, StreamingContext context)
52 {
53 base.GetObjectData(info, context);
54 info.AddValue("time", float.Parse(time.text));
55 }
56
57 public CountdownAction(SerializationInfo info, StreamingContext context) : base(info, context)
58 {
59 countdown = info.GetSingle("time");
60 try
61 {
62 if (time) time.text = countdown.ToString();
63 }
64 catch (Exception)
65 {
66 // ignored
67 }
68 }
69}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
void TriggerOutput(string id)
string action
Definition: ActionObject.cs:32
List< GameObject > outPuts
Definition: ActionObject.cs:19
override void Triggered(string id)
CountdownAction(SerializationInfo info, StreamingContext context)
new void GetObjectData(SerializationInfo info, StreamingContext context)
void InputEnded(string value)
InputField time