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 System;
using UnityEngine;
public class LevelMapper : MonoBehaviour
{
private CharacterData data;
private PlayerJump jump;
private PlayerMovement movement;
private bool isJumping;
private bool isRunning;
public GameObject node;
public GameObject line;
public GameObject line2;
private Vector3 jumpPos;
private Vector3 landPos;
private Vector3 startRunPos;
private Vector3 leaveGroundPos;
private void Start()
{
data = GetComponentInParent<CharacterData>();
jump = data.jump;
movement = data.movement;
PlayerJump playerJump = jump;
playerJump.JumpAction = (Action)Delegate.Combine(playerJump.JumpAction, new Action(Jump));
CharacterData characterData = data;
characterData.TouchGroundAction = (Action<float, Vector3, Vector3, Transform>)Delegate.Combine(characterData.TouchGroundAction, new Action<float, Vector3, Vector3, Transform>(Ground));
CharacterData characterData2 = data;
characterData2.TouchWallAction = (Action<float, Vector3, Vector3>)Delegate.Combine(characterData2.TouchWallAction, new Action<float, Vector3, Vector3>(Wall));
}
private void Update()
{
if (!data.isGrounded)
{
LeaveGround();
}
}
private void Jump()
{
isJumping = true;
jumpPos = base.transform.position;
}
private void Wall(float sinceWall, Vector3 pos, Vector3 normal)
{
if (!data.isWallGrab)
{
if (data.sinceJump < 0.1f)
{
isJumping = false;
}
else
{
Land();
}
}
}
private void Ground(float sinceGround, Vector3 pos, Vector3 groundNormal, Transform groundTransform = null)
{
if (!isRunning)
{
startRunPos = pos;
isRunning = true;
}
if (!data.isGrounded)
{
if (data.sinceJump < 0.1f)
{
isJumping = false;
}
else
{
Land();
}
}
}
private void Land()
{
landPos = base.transform.position;
if (Vector3.Distance(landPos, jumpPos) > 3f && isJumping)
{
SaveJump();
}
isJumping = false;
}
private void LeaveGround()
{
if (isRunning)
{
leaveGroundPos = data.groundPos;
SaveRun();
isRunning = false;
}
}
private void SaveJump()
{
UnityEngine.Object.Instantiate(node, jumpPos, Quaternion.identity).GetComponent<SpriteRenderer>().color = Color.green;
UnityEngine.Object.Instantiate(node, landPos, Quaternion.identity).GetComponent<SpriteRenderer>().color = Color.red;
LineRenderer component = UnityEngine.Object.Instantiate(line, Vector3.zero, Quaternion.identity).GetComponent<LineRenderer>();
component.SetPosition(0, jumpPos);
component.SetPosition(1, landPos);
}
private void SaveRun()
{
if (!(Vector3.Distance(startRunPos, jumpPos) < 2f))
{
UnityEngine.Object.Instantiate(node, startRunPos, Quaternion.identity).GetComponent<SpriteRenderer>().color = Color.blue;
UnityEngine.Object.Instantiate(node, leaveGroundPos, Quaternion.identity).GetComponent<SpriteRenderer>().color = Color.blue;
LineRenderer component = UnityEngine.Object.Instantiate(line2, Vector3.zero, Quaternion.identity).GetComponent<LineRenderer>();
component.SetPosition(0, startRunPos);
component.SetPosition(1, leaveGroundPos);
}
}
}
|