diff options
Diffstat (limited to 'Client/Assembly-CSharp/ManualDoor.cs')
-rw-r--r-- | Client/Assembly-CSharp/ManualDoor.cs | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/ManualDoor.cs b/Client/Assembly-CSharp/ManualDoor.cs new file mode 100644 index 0000000..fb2ac04 --- /dev/null +++ b/Client/Assembly-CSharp/ManualDoor.cs @@ -0,0 +1,90 @@ +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()); + } +} |