Files
beyond/Assets/Scripts/Effects/CharacterCreationEffect.cs
2024-11-20 15:21:28 +01:00

89 lines
1.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using Beyond;
using DG.Tweening;
using Sirenix.OdinInspector;
using UnityEngine;
public class CharacterCreationEffect : MonoBehaviour
{
private List<Material> m_materials;
private int m_thresholID;
public bool m_makeInvisibleOnStart = true;
public bool m_createOnStart = true;
public float m_time = 1f;
private float m_timer = 0f;
// Start is called before the first frame update
void InitMaterials()
{
var renderers = GetComponentsInChildren<Renderer>();
m_materials = new List<Material>();
foreach (var r in renderers)
{
m_materials.Add(r.material);
}
var rdr = GetComponent<Renderer>();
if (rdr)
{
m_materials.Add(rdr.material);
}
m_thresholID = Shader.PropertyToID("_Threshold");
}
private IEnumerator CreateRoutine()
{
m_timer = 0f;
while (m_timer < m_time)
{
float th = 1f - m_timer / m_time;
foreach (var m in m_materials)
{
m.SetFloat(m_thresholID, th);
}
m_timer += Time.deltaTime;
yield return null;
}
yield return null;
}
[Button]
public void Create()
{
StartCoroutine(CreateRoutine());
}
void SetThreshold(float value)
{
foreach (var m in m_materials)
{
m.SetFloat(m_thresholID, value);
}
}
void Start()
{
InitMaterials();
if (m_createOnStart)
{
Create();
}
else if (m_makeInvisibleOnStart)
{
SetThreshold(1f);
}
}
// Update is called once per frame
void Update()
{
}
}