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

87 lines
2.3 KiB
C#
Raw Normal View History

2021-04-16 20:30:49 +02:00
using System;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using NaughtyAttributes.Test;
2021-05-11 02:48:24 +02:00
using TMPro;
2021-04-16 20:30:49 +02:00
using UnityEngine;
2021-05-18 18:00:10 +02:00
using UnityEngine.Animations.Rigging;
2021-04-16 20:30:49 +02:00
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;
2021-05-18 16:28:41 +02:00
[SerializeField] private Light _light;
[SerializeField] private float _lightIntensity;
2021-04-16 20:30:49 +02:00
private const string EMISSION_COLOR = "_EmissionColor";
private void Start()
{
_trails = GetComponentsInChildren<TrailRenderer>();
_renderers = GetComponentsInChildren<Renderer>();
foreach (var trail in _trails)
{
trail.time = _baseTrailTime;
}
2021-05-18 16:28:41 +02:00
2021-05-18 18:00:10 +02:00
_light.intensity = 0;
2021-04-16 20:30:49 +02:00
}
private void LateUpdate()
{
_graphics.Rotate(Vector3.up * (Time.deltaTime * _rotationSpeed));
}
public void Pulse()
{
2021-05-18 18:00:10 +02:00
EnableTrails();
2021-04-16 20:30:49 +02:00
_graphics.transform.localScale = Vector3.one * _scaleFactor;
_graphics.DOScale(Vector3.one, _pulseTime);
foreach (var trail in _trails)
{
trail.time = _blinkTrailTime;
trail.DOTime(_baseTrailTime, _pulseTime);
}
2021-05-18 18:00:10 +02:00
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;
}
2021-04-16 20:30:49 +02:00
}
}