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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
using Photon.Pun;
using UnityEngine;
public class ScreenEdgeBounce : MonoBehaviour
{
private float sinceBounce = 1f;
private Camera mainCam;
private RayHitReflect reflect;
private Vector2 lastNormal;
private ProjectileHit projHit;
private bool done;
private RayHitBulletSound bulletSound;
private PhotonView view;
private void Start()
{
GetComponentInParent<ChildRPC>().childRPCsVector2Vector2IntInt.Add("ScreenBounce", DoHit);
view = GetComponentInParent<PhotonView>();
bulletSound = GetComponentInParent<RayHitBulletSound>();
projHit = GetComponentInParent<ProjectileHit>();
ScreenEdgeBounce[] componentsInChildren = base.transform.root.GetComponentsInChildren<ScreenEdgeBounce>();
for (int i = 0; i < componentsInChildren.Length; i++)
{
if (i > 0)
{
Object.Destroy(componentsInChildren[i]);
}
}
mainCam = MainCam.instance.transform.GetComponent<Camera>();
reflect = GetComponentInParent<RayHitReflect>();
}
private void Update()
{
if (!view.IsMine || done)
{
return;
}
Vector3 vector = mainCam.WorldToScreenPoint(base.transform.position);
vector.x /= Screen.width;
vector.y /= Screen.height;
vector = new Vector3(Mathf.Clamp(vector.x, 0f, 1f), Mathf.Clamp(vector.y, 0f, 1f), vector.z);
if (vector.x != 0f && vector.x != 1f && vector.y != 1f && vector.y != 0f)
{
return;
}
Vector2 vector2 = Vector2.zero;
if (vector.x == 0f)
{
vector2 = Vector2.right;
}
else if (vector.x == 1f)
{
vector2 = -Vector2.right;
}
if (vector.y == 0f)
{
vector2 = Vector2.up;
}
else if (vector.y == 1f)
{
vector2 = -Vector2.up;
}
if (lastNormal == vector2 && Vector2.Angle(vector2, base.transform.forward) < 90f)
{
lastNormal = vector2;
return;
}
lastNormal = vector2;
vector.x *= Screen.width;
vector.y *= Screen.height;
RaycastHit2D raycastHit2D = default(RaycastHit2D);
raycastHit2D.normal = vector2;
raycastHit2D.point = mainCam.ScreenToWorldPoint(vector);
int num = -1;
if ((bool)raycastHit2D.transform)
{
PhotonView component = raycastHit2D.transform.root.GetComponent<PhotonView>();
if ((bool)component)
{
num = component.ViewID;
}
}
int intData = -1;
if (num == -1)
{
Collider2D[] componentsInChildren = MapManager.instance.currentMap.Map.GetComponentsInChildren<Collider2D>();
for (int i = 0; i < componentsInChildren.Length; i++)
{
if (componentsInChildren[i] == raycastHit2D.collider)
{
intData = i;
}
}
}
GetComponentInParent<ChildRPC>().CallFunction("ScreenBounce", raycastHit2D.point, raycastHit2D.normal, num, intData);
if (reflect.reflects <= 0)
{
done = true;
}
sinceBounce = 0f;
}
private void DoHit(Vector2 hitPos, Vector2 hitNormal, int viewID = -1, int colliderID = -1)
{
HitInfo hitInfo = new HitInfo();
hitInfo.point = hitPos;
hitInfo.normal = hitNormal;
hitInfo.collider = null;
if (viewID != -1)
{
PhotonView photonView = PhotonNetwork.GetPhotonView(viewID);
hitInfo.collider = photonView.GetComponentInChildren<Collider2D>();
hitInfo.transform = photonView.transform;
}
else if (colliderID != -1)
{
hitInfo.collider = MapManager.instance.currentMap.Map.GetComponentsInChildren<Collider2D>()[colliderID];
hitInfo.transform = hitInfo.collider.transform;
}
DynamicParticles.instance.PlayBulletHit(projHit.damage, base.transform, hitInfo, projHit.projectileColor);
bulletSound.DoHitEffect(hitInfo);
reflect.DoHitEffect(hitInfo);
}
}
|