summaryrefslogtreecommitdiff
path: root/Valheim_v0.141.2_r202102/Valheim/assembly_valheim/Switch.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Valheim_v0.141.2_r202102/Valheim/assembly_valheim/Switch.cs')
-rw-r--r--Valheim_v0.141.2_r202102/Valheim/assembly_valheim/Switch.cs56
1 files changed, 56 insertions, 0 deletions
diff --git a/Valheim_v0.141.2_r202102/Valheim/assembly_valheim/Switch.cs b/Valheim_v0.141.2_r202102/Valheim/assembly_valheim/Switch.cs
new file mode 100644
index 0000000..9b18b0d
--- /dev/null
+++ b/Valheim_v0.141.2_r202102/Valheim/assembly_valheim/Switch.cs
@@ -0,0 +1,56 @@
+using UnityEngine;
+
+public class Switch : MonoBehaviour, Interactable, Hoverable
+{
+ public delegate bool Callback(Switch caller, Humanoid user, ItemDrop.ItemData item);
+
+ public Callback m_onUse;
+
+ public string m_hoverText = "";
+
+ public string m_name = "";
+
+ public float m_holdRepeatInterval = -1f;
+
+ private float m_lastUseTime;
+
+ public bool Interact(Humanoid character, bool hold)
+ {
+ if (hold)
+ {
+ if (m_holdRepeatInterval <= 0f)
+ {
+ return false;
+ }
+ if (Time.time - m_lastUseTime < m_holdRepeatInterval)
+ {
+ return false;
+ }
+ }
+ m_lastUseTime = Time.time;
+ if (m_onUse != null)
+ {
+ return m_onUse(this, character, null);
+ }
+ return false;
+ }
+
+ public bool UseItem(Humanoid user, ItemDrop.ItemData item)
+ {
+ if (m_onUse != null)
+ {
+ return m_onUse(this, user, item);
+ }
+ return false;
+ }
+
+ public string GetHoverText()
+ {
+ return Localization.instance.Localize(m_hoverText);
+ }
+
+ public string GetHoverName()
+ {
+ return Localization.instance.Localize(m_name);
+ }
+}