177 lines
3.5 KiB
C#
177 lines
3.5 KiB
C#
using Moonlit.Utils;
|
|
using UnityEngine;
|
|
|
|
namespace Moonlit.FootstepPro
|
|
{
|
|
[ExecuteInEditMode]
|
|
[AddComponentMenu("FootprintSystem/Footprint")]
|
|
public class Footprint : MonoBehaviour
|
|
{
|
|
public bool doFade = true;
|
|
|
|
[SerializeField]
|
|
private AnimationCurve Fade;
|
|
|
|
[SerializeField]
|
|
private Material _Material;
|
|
|
|
private float _Time;
|
|
|
|
private float _StartDiffuseStrength;
|
|
|
|
private float _StartNormalsStrength;
|
|
|
|
private bool _UniqueMaterial;
|
|
|
|
public Material Material
|
|
{
|
|
get
|
|
{
|
|
return _Material;
|
|
}
|
|
}
|
|
|
|
public float DiffuseStrength
|
|
{
|
|
get
|
|
{
|
|
return _Material.GetFloat("_DiffuseStrength");
|
|
}
|
|
private set
|
|
{
|
|
if (!_UniqueMaterial)
|
|
{
|
|
_UniqueMaterial = true;
|
|
_Material = new Material(_Material);
|
|
}
|
|
_Material.SetFloat("_DiffuseStrength", value);
|
|
}
|
|
}
|
|
|
|
public float NormalsStrength
|
|
{
|
|
get
|
|
{
|
|
return _Material.GetFloat("_NormalsStrength");
|
|
}
|
|
private set
|
|
{
|
|
if (!_UniqueMaterial)
|
|
{
|
|
_UniqueMaterial = true;
|
|
_Material = new Material(_Material);
|
|
}
|
|
_Material.SetFloat("_NormalsStrength", value);
|
|
}
|
|
}
|
|
|
|
public bool Flip
|
|
{
|
|
set
|
|
{
|
|
if (!_UniqueMaterial)
|
|
{
|
|
_UniqueMaterial = true;
|
|
_Material = new Material(_Material);
|
|
}
|
|
Material.SetFloat("_HorizontalFlip", (!value) ? 0f : 1f);
|
|
}
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
Singleton<FootprintSystem>.Instance.Register(this);
|
|
_StartDiffuseStrength = DiffuseStrength;
|
|
_StartNormalsStrength = NormalsStrength;
|
|
_Time = 0f;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
Singleton<FootprintSystem>.Instance.Register(this);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (Singleton<FootprintSystem>.IsInitialized)
|
|
{
|
|
Singleton<FootprintSystem>.Instance.Unregister(this);
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (Singleton<FootprintSystem>.IsInitialized)
|
|
{
|
|
Singleton<FootprintSystem>.Instance.Unregister(this);
|
|
}
|
|
}
|
|
|
|
private void OnDrawGizmos()
|
|
{
|
|
DrawGizmo(false);
|
|
}
|
|
|
|
private void OnDrawGizmosSelected()
|
|
{
|
|
DrawGizmo(true);
|
|
}
|
|
|
|
public void PlaceRight(Vector3 position)
|
|
{
|
|
Transform();
|
|
}
|
|
|
|
public void PlaceLeft(Vector3 position)
|
|
{
|
|
Flip = true;
|
|
Transform();
|
|
}
|
|
|
|
public void Advance()
|
|
{
|
|
_Time += Time.deltaTime;
|
|
FootprintSystem instance = Singleton<FootprintSystem>.Instance;
|
|
TimeFade(instance);
|
|
}
|
|
|
|
private void Transform()
|
|
{
|
|
float y = base.transform.rotation.eulerAngles.y;
|
|
base.transform.rotation = Quaternion.Euler(new Vector3(0f, y - 180f, 0f));
|
|
base.transform.localScale = new Vector3(Mathf.Abs(base.transform.localScale.x), Mathf.Abs(base.transform.localScale.y), Mathf.Abs(base.transform.localScale.z));
|
|
}
|
|
|
|
private void TimeFade(FootprintSystem system)
|
|
{
|
|
if (doFade && (system.Fade == FootprintSystem.FadeType.Time || system.Fade == FootprintSystem.FadeType.TimeOrCount))
|
|
{
|
|
float num = Fade.Evaluate(_Time / system.FadeLength);
|
|
DiffuseStrength = _StartDiffuseStrength * num;
|
|
NormalsStrength = _StartNormalsStrength * num;
|
|
if (_Time > system.FadeLength)
|
|
{
|
|
Object.Destroy(base.gameObject);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void DrawGizmo(bool selected)
|
|
{
|
|
if (Singleton<FootprintSystem>.Instance.DrawEditorGizmos)
|
|
{
|
|
Color color = new Color(0f, 0.7f, 1f, (!selected) ? 0.1f : 0.3f);
|
|
Gizmos.matrix = base.transform.localToWorldMatrix;
|
|
if (base.isActiveAndEnabled)
|
|
{
|
|
Gizmos.color = color;
|
|
Gizmos.DrawCube(Vector3.zero, Vector3.one);
|
|
}
|
|
color.a = ((!selected) ? 0.2f : 0.5f);
|
|
Gizmos.color = color;
|
|
Gizmos.DrawWireCube(Vector3.zero, Vector3.one);
|
|
}
|
|
}
|
|
}
|
|
}
|