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