using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; using Cyber.Networking; using Cyber.Console; using System; namespace Cyber.Entities.SyncBases { /// /// Object that blinks when interacted with. /// public class Button : Interactable { /// /// The interactable which this button will trigger. /// public Interactable WillTrigger; /// /// The button mesh that will blink. /// public MeshRenderer Mesh; /// /// How long the blink lasts. /// public float BlinkLength = 1f; /// /// How bright the light is (upwards of 1 for the bloom to kick in) /// public float BlinkBrightness = 1.5f; /// /// The color of the blink. /// public Color BlinkColor = new Color(1f, 0.6f, 0f); private float BlinkTime = float.MinValue; private Material Material; /// /// When the button is interacted with, it blinks once, light lasting /// for seconds, and calls Interact /// on the . /// public override void Interact(SyncBase Trigger) { BlinkTime = Time.time; if (WillTrigger != null) { WillTrigger.Interact(this); } else { Term.Println("FIXME: The button '" + gameObject.name + "' was pressed, but it doesn't have a WillTrigger."); } } /// /// Does nothing, because it doesn't need to synced. /// /// public override void Deserialize(NetworkReader reader) {} /// /// Does nothing, because it doesn't need to synced. /// /// public override void Serialize(NetworkWriter writer) { } public override InteractableSyncdata GetInteractableSyncdata() { return new InteractableSyncdata(false, true); } /// /// Buttons only act as triggers, so only interact is sent to the server. /// /// Sync Handletype containing sync information. public override SyncHandletype GetSyncHandletype() { return new SyncHandletype(false, 1000); } private void Start() { Material = Mesh.material; } private void Update() { float CurrentTime = Time.time - BlinkTime; if (CurrentTime < BlinkLength) { float Brightness = (1f - CurrentTime / BlinkLength) * BlinkBrightness; Color NewColor = new Color(Brightness * BlinkColor.r, Brightness * BlinkColor.g, Brightness * BlinkColor.b); Material.SetColor("_EmissionColor", NewColor); } } } }