revival/game/Assets/Scripts/Character/Glove.cs

87 lines
2.3 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using NaughtyAttributes.Test;
using TMPro;
using UnityEngine;
using UnityEngine.Animations.Rigging;
public class Glove : MonoBehaviour
{
[SerializeField] private GameObject[] _cylinders;
[SerializeField] private Transform _graphics;
private TrailRenderer[] _trails;
private Renderer[] _renderers;
// TODO: refactor to settings object
[SerializeField] private float _baseTrailTime;
[SerializeField] private float _blinkTrailTime;
[SerializeField] private float _pulseTime;
[SerializeField] private Material _trailMat;
[SerializeField] private float _emissionScale;
[SerializeField] private float _rotationSpeed;
[SerializeField] private float _scaleFactor;
[SerializeField] private Light _light;
[SerializeField] private float _lightIntensity;
private const string EMISSION_COLOR = "_EmissionColor";
private void Start()
{
_trails = GetComponentsInChildren<TrailRenderer>();
_renderers = GetComponentsInChildren<Renderer>();
foreach (var trail in _trails)
{
trail.time = _baseTrailTime;
}
_light.intensity = 0;
}
private void LateUpdate()
{
_graphics.Rotate(Vector3.up * (Time.deltaTime * _rotationSpeed));
}
public void Pulse()
{
EnableTrails();
_graphics.transform.localScale = Vector3.one * _scaleFactor;
_graphics.DOScale(Vector3.one, _pulseTime);
foreach (var trail in _trails)
{
trail.time = _blinkTrailTime;
trail.DOTime(_baseTrailTime, _pulseTime);
}
var t = 0f;
DOTween.To(
() => t,
_ => { },
1.0f,
_pulseTime)
.OnComplete(DisableTrails);
_light.intensity = _lightIntensity;
_light.DOIntensity(0, _pulseTime);
}
private void EnableTrails() => SetTrails(true);
private void DisableTrails() => SetTrails(false);
private void SetTrails(bool state)
{
for (int i = 0; i < _trails.Length; i++)
{
_trails[i].Clear();
_trails[i].enabled = state;
}
}
}