late goodbye
This commit is contained in:
+28
-9
@@ -1,4 +1,6 @@
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using DG.Tweening;
|
||||
@@ -10,16 +12,30 @@ public class Train : MonoBehaviour
|
||||
public bool useEffect;
|
||||
private LocomotionHandler locomotionHandler;
|
||||
private Coroutine c_effect;
|
||||
private Material[] materials;
|
||||
private List<Material> materials = new();
|
||||
private float effectDuration = .4f;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if(materials == null)
|
||||
materials = GetComponent<MeshRenderer>().materials;
|
||||
var uiMenu = FindObjectOfType<UIMainMenu>();
|
||||
uiMenu.currentTrain = this;
|
||||
|
||||
if(materials.Count == 0)
|
||||
{
|
||||
materials = GetComponent<MeshRenderer>().materials.ToList();
|
||||
var materialsInChildren = gameObject.transform
|
||||
.GetChild(0)
|
||||
.GetComponent<MeshRenderer>()
|
||||
.materials.ToList();
|
||||
|
||||
foreach(var mat in materialsInChildren)
|
||||
materials.Add(mat);
|
||||
}
|
||||
|
||||
if(!useEffect)
|
||||
{
|
||||
SetEffect(true);
|
||||
|
||||
if(locomotionHandler == null)
|
||||
locomotionHandler = FindObjectOfType<LocomotionHandler>();
|
||||
|
||||
@@ -36,7 +52,7 @@ public class Train : MonoBehaviour
|
||||
else SetEffect(true);
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
public async void Hide()
|
||||
{
|
||||
if(!useEffect)
|
||||
{
|
||||
@@ -46,6 +62,9 @@ public class Train : MonoBehaviour
|
||||
transform.DOLocalMoveZ(endPosition, speed)
|
||||
.SetEase(Ease.InSine)
|
||||
.OnComplete(() => gameObject.SetActive(false));
|
||||
|
||||
await Task.Delay(3000);
|
||||
SetEffect(false);
|
||||
}
|
||||
else SetEffect(false);
|
||||
}
|
||||
@@ -63,11 +82,11 @@ public class Train : MonoBehaviour
|
||||
|
||||
IEnumerator SetEffectRoutine(bool isShow)
|
||||
{
|
||||
float startPosition = isShow ? -5 : 2;
|
||||
float startPosition = isShow ? -5 : 3;
|
||||
float currentValue = startPosition;
|
||||
float endPosition = 0;
|
||||
|
||||
if(isShow) endPosition = 2;
|
||||
if(isShow) endPosition = 3;
|
||||
else endPosition = -5;
|
||||
|
||||
float progress = 0;
|
||||
@@ -77,7 +96,7 @@ public class Train : MonoBehaviour
|
||||
{
|
||||
currentValue = Mathf.Lerp(startPosition, endPosition, progress);
|
||||
|
||||
for(int i = 0; i < materials.Length; i++)
|
||||
for(int i = 0; i < materials.Count; i++)
|
||||
{
|
||||
materials[i]
|
||||
.SetFloat("_EffectPosition", currentValue);
|
||||
@@ -87,13 +106,13 @@ public class Train : MonoBehaviour
|
||||
yield return null;
|
||||
}
|
||||
|
||||
for(int i = 0; i < materials.Length; i++)
|
||||
for(int i = 0; i < materials.Count; i++)
|
||||
{
|
||||
materials[i]
|
||||
.SetFloat("_EffectPosition", endPosition);
|
||||
}
|
||||
|
||||
if(!isShow)
|
||||
if(!isShow && useEffect)
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user