using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; namespace Cyber.Entities.SyncBases { /// /// Door that slides open and closed. Can be interacted to toggle openness. /// 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); } public override InteractableSyncdata GetInteractableSyncdata() { return new InteractableSyncdata(true, true); } 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; } } } }