using UnityEngine; using UnityEngine.Networking; using Cyber.Console; using Cyber.Util; namespace Cyber.Entities.SyncBases { /// /// Runs functions. /// /// \todo Implement programs in an editor-friendly way public class Computer : Interactable { /// The "left key" key code. public const string KeyCodeLeft = "KeyLeft"; /// The "right key" key code. public const string KeyCodeRight = "KeyRight"; /// /// The delegate which defines the function that will be run when the /// computer is interacted with (directly or through keys). /// public delegate void RunProgram(Computer host, string key); /// /// The screen this computer will print its output on. /// public TextTextureApplier Screen; /// /// If the computer has a hologram as a screen, and is set here, the /// hologram will be animated properly when the computer is shut down. /// public Hologram Hologram; /// /// The "left" key for this computer. Might cause actions depending /// on the program. /// public Button KeyLeft; /// /// The "right" key for this computer. Might cause actions depending /// on the program. /// public Button KeyRight; /// /// The function that is run when inputs are triggered. Can cause /// state changes in the host computer. /// public RunProgram Program; /// /// Runs the with some input, determined by the /// Trigger. /// /// Determines the keycode given to the /// . public override void Interact(SyncBase trigger, InteractionType type) { if (type == InteractionType.Activate) { Hologram.Visible = true; if (trigger == KeyLeft) { Screen.SetTextProperties(new TextTextureProperties("\n Pressed left!")); } else if (trigger == KeyRight) { Screen.SetTextProperties(new TextTextureProperties("\n Pressed right!")); } else { Screen.SetTextProperties(new TextTextureProperties("")); Hologram.Visible = false; } } } /// /// No serialization needed (yet). /// /// public override void Deserialize(NetworkReader reader) { } /// /// No serialization needed (yet). /// /// public override void Serialize(NetworkWriter writer) { } /// /// Computers could have lots of data, and therefore should be hashed /// to optimize bandwidth usage. No hurry in updating them though, so /// an update per 10 ticks is enough. /// /// The sync handletype. public override SyncHandletype GetSyncHandletype() { return new SyncHandletype(true, 10); } /// /// Computers should share state between different clients, so sync and /// send interactions to the network. /// /// The Interaction information. public override InteractableSyncdata GetInteractableSyncdata() { return new InteractableSyncdata(true, true); } } }