104 lines
2.5 KiB
C#
104 lines
2.5 KiB
C#
using System.Collections;
|
|
using Es.InkPainter.Effective;
|
|
using UnityEngine;
|
|
|
|
namespace Es.InkPainter.Sample
|
|
{
|
|
[RequireComponent(typeof(InkCanvas))]
|
|
public class TextureRecovery : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private float lerpCoefficient = 0.1f;
|
|
|
|
[SerializeField]
|
|
private float callTimer = 0.1f;
|
|
|
|
[SerializeField]
|
|
private bool @fixed;
|
|
|
|
private Material material;
|
|
|
|
private InkCanvas canvas;
|
|
|
|
private Texture defaultMainTexture;
|
|
|
|
private RenderTexture paintMainTexture;
|
|
|
|
private Texture defaultNormalMap;
|
|
|
|
private RenderTexture paintNormalMap;
|
|
|
|
private Texture defaultHeightMap;
|
|
|
|
private RenderTexture paintHeightMap;
|
|
|
|
private void Awake()
|
|
{
|
|
canvas = GetComponent<InkCanvas>();
|
|
canvas.OnInitializedAfter += Init;
|
|
}
|
|
|
|
private void Init(InkCanvas canvas)
|
|
{
|
|
material = GetComponent<MeshRenderer>().sharedMaterial;
|
|
defaultMainTexture = canvas.GetMainTexture(material.name);
|
|
paintMainTexture = canvas.GetPaintMainTexture(material.name);
|
|
defaultNormalMap = canvas.GetNormalTexture(material.name);
|
|
paintNormalMap = canvas.GetPaintNormalTexture(material.name);
|
|
defaultHeightMap = canvas.GetHeightTexture(material.name);
|
|
paintHeightMap = canvas.GetPaintHeightTexture(material.name);
|
|
StartCoroutine(TextureLerp());
|
|
}
|
|
|
|
public void FixedUpdate()
|
|
{
|
|
if (@fixed)
|
|
{
|
|
if (defaultMainTexture != null && paintMainTexture != null)
|
|
{
|
|
TextureMorphing.Lerp(defaultMainTexture, paintMainTexture, lerpCoefficient);
|
|
}
|
|
if (defaultNormalMap != null && paintNormalMap != null)
|
|
{
|
|
TextureMorphing.Lerp(defaultNormalMap, paintNormalMap, lerpCoefficient);
|
|
}
|
|
if (defaultHeightMap != null && paintHeightMap != null)
|
|
{
|
|
TextureMorphing.Lerp(defaultHeightMap, paintHeightMap, lerpCoefficient);
|
|
}
|
|
}
|
|
}
|
|
|
|
private IEnumerator TextureLerp()
|
|
{
|
|
while (true)
|
|
{
|
|
if (@fixed)
|
|
{
|
|
yield return new WaitForSeconds(1f);
|
|
continue;
|
|
}
|
|
int i = 0;
|
|
while (i < 10)
|
|
{
|
|
yield return new WaitForSeconds(callTimer / 10f);
|
|
if (defaultMainTexture != null && paintMainTexture != null)
|
|
{
|
|
TextureMorphing.Lerp(defaultMainTexture, paintMainTexture, lerpCoefficient / 10f);
|
|
}
|
|
if (defaultNormalMap != null && paintNormalMap != null)
|
|
{
|
|
TextureMorphing.Lerp(defaultNormalMap, paintNormalMap, lerpCoefficient / 10f);
|
|
}
|
|
if (defaultHeightMap != null && paintHeightMap != null)
|
|
{
|
|
TextureMorphing.Lerp(defaultHeightMap, paintHeightMap, lerpCoefficient / 10f);
|
|
}
|
|
int num = i + 1;
|
|
i = num;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|