-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Evolution shader effect added. Fully functional but will soft-rework
not perfectly structured. also part of PlayerBoardMan.cs at the moment, would like a separate PlayerEvolutionMan.cs
- Loading branch information
1 parent
2a75e62
commit cbdc9f9
Showing
41 changed files
with
422 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 83 additions & 4 deletions
87
...s/Scripts/Other/UnitComponents/BoardUnits/ShaderEffects/BoardUnitEvolutionShaderEffect.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,95 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
using static GameInfo; | ||
|
||
public class BoardUnitEvolutionShaderEffect : UnitShaderEffects { | ||
|
||
public float ShaderEvoFade { | ||
get { return This<BoardUnit>().state.ShaderEvoFade; } | ||
set { This<BoardUnit>().state.ShaderEvoFade = Mathf.Clamp(value, 0f, 1f); } | ||
} | ||
public float ShaderEvoAlphaFade { | ||
get {return This<BoardUnit>().state.ShaderEvoAlphaFade; } | ||
set { This<BoardUnit>().state.ShaderEvoAlphaFade = Mathf.Clamp(value, 0f, 1f); } | ||
} | ||
|
||
private readonly string | ||
EvoFade = "_EvoFade" | ||
EvoFade = "_EvoFade", | ||
EvoAlphaFade = "_EvoAlphaFade" | ||
; | ||
|
||
bool IsEvolvedUnit = false; | ||
private bool isEvolving = false; | ||
|
||
private float speed = 0.5f; | ||
|
||
private new void Awake() { | ||
base.Awake(); | ||
This<BoardUnit>().state.AddCallback("ShaderEvoFade", UpdateEvoParameters); | ||
This<BoardUnit>().state.AddCallback("ShaderEvoAlphaFade", UpdateEvoParameters); | ||
} | ||
|
||
private void Start() { if (BoltNetwork.IsServer) { SubscribeLocalEventHandlers(); } } | ||
|
||
private IEnumerator EvolveUnit() { | ||
yield return new WaitForSeconds(2 * speed * ShaderEvoFade); | ||
ShaderEvoAlphaFade = 1f; | ||
isEvolving = true; | ||
while (isEvolving) { | ||
ShaderEvoFade += speed * Time.deltaTime; | ||
if (ShaderEvoFade == 1f) isEvolving = false; | ||
yield return new WaitForEndOfFrame(); | ||
} | ||
yield return new WaitForSeconds(0.1f); | ||
isEvolving = true; | ||
while (isEvolving) { | ||
ShaderEvoAlphaFade -= speed * Time.deltaTime; | ||
if (ShaderEvoAlphaFade == 0f) isEvolving = false; | ||
yield return new WaitForEndOfFrame(); | ||
} | ||
} | ||
|
||
private IEnumerator SpawnEvolvedUnit() { | ||
ShaderEvoFade = 1f; | ||
ShaderEvoAlphaFade = 1f; | ||
ShaderEvoAlphaFade = 0f; | ||
isEvolving = true; | ||
while (isEvolving) { | ||
ShaderEvoAlphaFade += speed * Time.deltaTime; | ||
if (ShaderEvoAlphaFade == 1f) isEvolving = false; | ||
yield return new WaitForEndOfFrame(); | ||
} | ||
yield return new WaitForSeconds(0.1f); | ||
isEvolving = true; | ||
while (isEvolving) { | ||
ShaderEvoFade -= speed * Time.deltaTime; | ||
if (ShaderEvoFade == 0f) isEvolving = false; | ||
yield return new WaitForEndOfFrame(); | ||
} | ||
} | ||
|
||
private void UpdateEvoParameters() { | ||
foreach (var m in Materials) { | ||
m.SetFloat(EvoFade, ShaderEvoFade); | ||
m.SetFloat(EvoAlphaFade, ShaderEvoAlphaFade); | ||
} | ||
} | ||
|
||
private void SubscribeLocalEventHandlers() { | ||
Player player = This<BoardUnit>().Owner; | ||
var board = player.GetPlayerMan<PlayerBoardMan>(); | ||
board.EvolvingUnitEvent += HandleEvolvingUnitEvent; | ||
board.SpawnedEvolvedUnitEvent += HandleSpawnedEvolvedUnitEvent; | ||
} | ||
|
||
private void HandleEvolvingUnitEvent(BoardUnit unit) { | ||
if (!IsThis<BoardUnit>(unit)) return; | ||
StopAllCoroutines(); | ||
StartCoroutine(EvolveUnit()); | ||
} | ||
|
||
private void Update() { | ||
|
||
private void HandleSpawnedEvolvedUnitEvent(BoardUnit unit) { | ||
if (!IsThis<BoardUnit>(unit)) return; | ||
StartCoroutine(SpawnEvolvedUnit()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.