Cyber/Assets/Scripts/Entities/SyncBases/Computer.cs

108 lines
3.8 KiB
C#
Raw Permalink Normal View History

using UnityEngine;
using UnityEngine.Networking;
using Cyber.Console;
using Cyber.Util;
namespace Cyber.Entities.SyncBases {
2017-05-11 20:05:43 +02:00
/// <summary>
/// Runs functions.
/// </summary>
/// \todo Implement programs in an editor-friendly way
public class Computer : Interactable {
2017-05-11 20:05:43 +02:00
/// <summary>The "left key" key code.</summary>
public const string KeyCodeLeft = "KeyLeft";
2017-05-11 20:05:43 +02:00
/// <summary>The "right key" key code.</summary>
public const string KeyCodeRight = "KeyRight";
2017-05-11 20:05:43 +02:00
/// <summary>
/// The delegate which defines the function that will be run when the
/// computer is interacted with (directly or through keys).
/// </summary>
public delegate void RunProgram(Computer host, string key);
/// <summary>
/// The screen this computer will print its output on.
/// </summary>
public TextTextureApplier Screen;
/// <summary>
/// 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.
/// </summary>
public Hologram Hologram;
/// <summary>
/// The "left" key for this computer. Might cause actions depending
/// on the program.
/// </summary>
public Button KeyLeft;
/// <summary>
/// The "right" key for this computer. Might cause actions depending
/// on the program.
/// </summary>
public Button KeyRight;
/// <summary>
/// The function that is run when inputs are triggered. Can cause
/// state changes in the host computer.
/// </summary>
public RunProgram Program;
2017-05-11 20:05:43 +02:00
/// <summary>
/// Runs the <see cref="Program"/> with some input, determined by the
/// Trigger.
/// </summary>
2017-05-12 05:07:16 +02:00
/// <param name="trigger">Determines the keycode given to the
2017-05-11 20:05:43 +02:00
/// <see cref="Program"/>.</param>
2017-05-12 05:07:16 +02:00
/// <param name="type">The interaction type.</param>
2017-05-12 01:03:27 +02:00
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;
}
}
}
2017-05-11 20:05:43 +02:00
/// <summary>
/// No serialization needed (yet).
/// </summary>
/// <param name="reader"></param>
public override void Deserialize(NetworkReader reader) {
}
2017-05-11 20:05:43 +02:00
/// <summary>
/// No serialization needed (yet).
/// </summary>
/// <param name="writer"></param>
public override void Serialize(NetworkWriter writer) {
}
2017-05-11 20:05:43 +02:00
/// <summary>
/// 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.
/// </summary>
/// <returns>The sync handletype.</returns>
public override SyncHandletype GetSyncHandletype() {
return new SyncHandletype(true, 10);
}
2017-05-11 20:05:43 +02:00
/// <summary>
/// Computers should share state between different clients, so sync and
/// send interactions to the network.
/// </summary>
/// <returns>The Interaction information.</returns>
public override InteractableSyncdata GetInteractableSyncdata() {
return new InteractableSyncdata(true, true);
}
}
}