-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlaguePhases.cs
120 lines (100 loc) · 3.61 KB
/
PlaguePhases.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
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using Landfall.TABS;
namespace AnimalKingdom
{
public class PlaguePhases : MonoBehaviour
{
private void Start()
{
unit = transform.root.GetComponent<Unit>();
unit.data.healthHandler.willBeRewived = false;
}
public void BeginTransition()
{
StartCoroutine(DoSickening());
}
private IEnumerator DoSickening()
{
StartCoroutine(PlayPartWithDelay(sickenTime - 0.5f));
var storedAliveMaterials = new List<Material>();
foreach (var index in aliveMaterialIndexes)
{
storedAliveMaterials.Add(Instantiate(renderer.materials[index]));
}
var t = 0f;
while (t < sickenTime && !unit.data.Dead)
{
for (int i = 0; i < aliveMaterialIndexes.Count; i++)
{
renderer.materials[aliveMaterialIndexes[i]].Lerp(storedAliveMaterials[i], sicklyMaterials[i], t / sickenTime);
}
t += Time.deltaTime;
yield return null;
}
if (unit.data.Dead)
{
part.Stop();
Destroy(gameObject);
yield break;
}
currentState = PlagueState.Sickly;
SetRenderer();
if (unit.GetComponentInChildren<EyeSpawner>())
{
foreach (var eyeSet in unit.GetComponentsInChildren<EyeSpawner>())
{
foreach (var eye in eyeSet.spawnedEyes) Destroy(eye.gameObject);
eyeSet.spawnedEyes.Clear();
eyeSet.eyeObject = reviveEye;
eyeSet.GetType().GetMethod("Awake", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(eyeSet, new object[] { });
}
}
StartCoroutine(PlayPartWithDelay(0.5f));
}
public IEnumerator PlayPartWithDelay(float delay = 0f)
{
yield return new WaitForSeconds(delay);
part.Play();
}
public void SetRenderer()
{
if (currentState == PlagueState.Alive)
{
renderer.gameObject.SetActive(true);
sickRenderer.gameObject.SetActive(false);
zombieRenderer.gameObject.SetActive(false);
}
else if (currentState == PlagueState.Sickly)
{
renderer.gameObject.SetActive(false);
sickRenderer.gameObject.SetActive(true);
zombieRenderer.gameObject.SetActive(false);
}
else if (currentState == PlagueState.Zombie)
{
renderer.gameObject.SetActive(false);
sickRenderer.gameObject.SetActive(false);
zombieRenderer.gameObject.SetActive(true);
}
}
private Unit unit;
public enum PlagueState
{
Alive,
Sickly,
Zombie
}
public PlagueState currentState;
public Renderer renderer;
public Renderer sickRenderer;
public Renderer zombieRenderer;
public ParticleSystem part;
public List<Material> sicklyMaterials = new List<Material>();
public List<int> aliveMaterialIndexes = new List<int>();
public GameObject reviveEye;
public float sickenTime = 6f;
}
}