using System; using System.Collections; using Hazel; using PowerTools; using UnityEngine; public class ManualDoor : MonoBehaviour { private const float ClosedDuration = 10f; public const float CooldownDuration = 30f; public bool Open; public BoxCollider2D myCollider; public SpriteAnim animator; public AnimationClip OpenDoorAnim; public AnimationClip CloseDoorAnim; private float size; private void Awake() { Vector2 vector = this.myCollider.size; this.size = ((vector.x > vector.y) ? vector.y : vector.x); } public virtual void SetDoorway(bool open) { if (this.Open == open) { return; } if (this.animator) { this.animator.Play(open ? this.OpenDoorAnim : this.CloseDoorAnim, 1f); } this.Open = open; this.myCollider.isTrigger = open; base.StopAllCoroutines(); if (!open) { Vector2 vector = this.myCollider.size; base.StartCoroutine(this.CoCloseDoorway(vector.x > vector.y)); } } // 自动关门 private IEnumerator CoCloseDoorway(bool isHort) { Vector2 s = this.myCollider.size; float i = 0f; if (isHort) { while (i < 0.1f) { i += Time.deltaTime; s.y = Mathf.Lerp(0.0001f, this.size, i / 0.1f); this.myCollider.size = s; yield return null; } } else { while (i < 0.1f) { i += Time.deltaTime; s.x = Mathf.Lerp(0.0001f, this.size, i / 0.1f); this.myCollider.size = s; yield return null; } } yield break; } //c 同步门的状态 public virtual void Serialize(MessageWriter writer) { writer.Write(this.Open); } public virtual void Deserialize(MessageReader reader) { this.SetDoorway(reader.ReadBoolean()); } }