using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
namespace Cyber.Entities.SyncBases {
public class Door : Interactable {
///
/// The root of the door mesh. This will be scaled to animate the door.
///
public Transform DoorRoot;
///
/// The openness of the door.
///
public bool IsOpen = false;
///
/// Toggles the openness of the door.
///
public override void Interact() {
IsOpen = !IsOpen;
}
///
/// Reads the openness of the door from the server.
///
///
public override void Deserialize(NetworkReader reader) {
IsOpen = reader.ReadBoolean();
}
///
/// Writes the openness of the door.
///
///
public override void Serialize(NetworkWriter writer) {
writer.Write(IsOpen);
}
///
/// Return the Sync Handletype information for .
///
/// Sync Handletype containing sync information.
public override SyncHandletype GetSyncHandletype() {
return new SyncHandletype(false, 10);
}
private void Update() {
float DoorScale = IsOpen ? 0.01f : 1;
if (DoorRoot.localScale.x != DoorScale) {
Vector3 Scale = DoorRoot.localScale;
if (Mathf.Abs(Scale.x - DoorScale) < 0.01) {
Scale.x = DoorScale;
} else {
Scale.x = Mathf.Lerp(Scale.x, DoorScale, 5f * Time.deltaTime);
}
DoorRoot.localScale = Scale;
}
}
}
}