blob: fb2ac04dc638c9c541048794e969b019397498bc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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());
}
}
|