Tanoda
HotfixAction.cs
Go to the documentation of this file.
1using System;
2using System.Linq;
3using System.Runtime.Serialization;
4using JetBrains.Annotations;
5using NaughtyAttributes;
6using UnityEngine;
7
8public class HotfixAction : ActionObject, ISerializable
9{
10 internal bool autostart;
11 private bool deactivated;
12 private readonly bool once = true;
13
14 public override void Deactivate()
15 {
16 base.Deactivate();
17 deactivated = true;
18 }
19
20 public override void Triggered(string id)
21 {
22 if (deactivated)
23 return;
24
25 if (id != GetInput())
26 {
27 if (once) deactivated = true;
28
29 base.Triggered(id);
30
31 Fixup();
32
33 TriggerNow();
34 }
35 }
36
37 public void TriggerNow()
38 {
39#if !UNITY_WEBGL
40 statusImg.color = Color.green;
41#endif
42 }
43
44
45 [CanBeNull]
46 public string GetInput()
47 {
48 try
49 {
50 return inIDs.Keys.ToList()[0];
51 }
52 catch (Exception)
53 {
54 return null;
55 }
56 }
57
58 [Button]
59 internal void Fixup()
60 {
61 try
62 {
64
65 foreach (var connection in connections)
66 {
67 var action = Controller.Instance.GetActionByInOut(connection.fromId);
68 if (action is PositionAction posAction)
69 {
70 var go = posAction.GetInputGO();
71 if (go)
72 {
73 go.transform.localPosition = posAction.targetPosition;
74 go.transform.localEulerAngles = posAction.targetRotation;
75 }
76 }
77 }
78 }
79 catch (Exception)
80 {
81 // ignored
82 }
83 }
84
85
86 public new void GetObjectData(SerializationInfo info, StreamingContext context)
87 {
88 base.GetObjectData(info, context);
89 }
90
91 public HotfixAction(SerializationInfo info, StreamingContext context) : base(info, context)
92 {
93 }
94}
UnityEngine.UI.Button Button
Definition: Pointer.cs:7
UnityEngine.Color Color
Definition: TestScript.cs:32
Image statusImg
Definition: ActionObject.cs:21
string action
Definition: ActionObject.cs:32
Connection[] GetConnectionsByEndPointId(string id)
Definition: Controller.cs:862
ActionObject GetActionByInOut(string id)
Definition: Controller.cs:925
static Controller Instance
Definition: Controller.cs:16
override void Deactivate()
Definition: HotfixAction.cs:14
HotfixAction(SerializationInfo info, StreamingContext context)
Definition: HotfixAction.cs:91
string GetInput()
Definition: HotfixAction.cs:46
override void Triggered(string id)
Definition: HotfixAction.cs:20
new void GetObjectData(SerializationInfo info, StreamingContext context)
Definition: HotfixAction.cs:86
void TriggerNow()
Definition: HotfixAction.cs:37