This repository has been archived by the owner on Apr 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlock.cs
150 lines (128 loc) · 3.53 KB
/
Block.cs
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class Block : MonoBehaviour
{
int value=1;
[SerializeField]
protected int index;
public BlockType type;
public Vector3 normalScale;
public float showTweenDuration;
public float showFallTweenDuration;
public float hideTweenDuration;
public float fallTweenDuration;
public float shakefallTweenDuration;
public float shakefallTweenForce;
public Sequence colorSwitchSequence;
public bool isPlayerOnTile = false;
public Color activatedColor;
public Color idleColor;
public float loseColor;
public float gainColor;
public virtual void Awake()
{
isPlayerOnTile = false;
}
public Tween Hide(bool skipAnim = true)
{
if (skipAnim)
{
transform.localScale = Vector3.zero;
}
else
{
return transform.DOScale(Vector3.zero, hideTweenDuration);
}
return null;
}
public void Fall()
{
Sequence mySequence = DOTween.Sequence();
mySequence.Append(transform.DOPunchRotation(shakefallTweenForce * Vector3.one,shakefallTweenDuration));
mySequence.Append(transform.DOMoveY(-10, fallTweenDuration));
mySequence.OnComplete(DestroyBlock);
}
public void DestroyBlock()
{
Destroy(this.gameObject);
}
public void SetIsPlayerOn(bool value)
{
isPlayerOnTile = value;
ToggleColor();
}
public void ToggleColor()
{
if(colorSwitchSequence != null && colorSwitchSequence.IsPlaying())
{
colorSwitchSequence.Kill();
}
Sequence mySequence = DOTween.Sequence();
// Debug.Log("gameobject : " + gameObject);
MeshRenderer mesh = GetComponent<MeshRenderer>();
if(mesh.materials.Length > 1)
{
Material mat = mesh.materials[1];
if (mat != null)
{
if (isPlayerOnTile)
{
mySequence.Append(mat.DOColor(activatedColor, gainColor));
}
else
{
mySequence.Append(mat.DOColor(activatedColor, 0));
mySequence.Append(mat.DOColor(idleColor, loseColor));
}
}
}
colorSwitchSequence = mySequence;
}
public Tween Show(bool pop = false)
{
if(pop)
{
return transform.DOScale(normalScale, showTweenDuration).SetEase(Ease.OutBack);
}
else
{
float y = transform.position.y;
transform.position = transform.position + new Vector3(0,8,0);
transform.localScale = normalScale;
return transform.DOMoveY(y, showFallTweenDuration);
}
}
public void AnimateHeight(float delay,float targetY,float duration,Ease ease= Ease.InOutSine){
StartCoroutine(AnimateHeightRoutine(delay,targetY,duration,ease));
}
IEnumerator AnimateHeightRoutine(float delay, float targetY,float duration,Ease ease){
yield return new WaitForSeconds(delay);
transform.DOMoveY(targetY,duration).SetEase(ease);
}
public int GetIndex()
{
return index;
}
public void SetIndex(int value)
{
if(value < 0)
{
return;
}
index = value;
}
}
public enum BlockType
{
Empty,
Normal,
Teleporter,
Bridge,
PressurePlate,
Unstable,
SoftButton,
HardButton,
Goal
}