123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using UnityEngine;
- using System.Collections;
- using System;
- public class BFX_ShaderProperies : MonoBehaviour {
- public BFX_BloodSettings BloodSettings;
- public AnimationCurve FloatCurve = AnimationCurve.EaseInOut(0, 0, 1, 1);
- public float GraphTimeMultiplier = 1, GraphIntensityMultiplier = 1;
- public float TimeDelay = 0;
- private bool canUpdate;
- bool isFrized;
- private float startTime;
- private int cutoutPropertyID;
- int forwardDirPropertyID;
- float timeLapsed;
- private MaterialPropertyBlock props;
- private Renderer rend;
- public event Action OnAnimationFinished;
- private void Awake()
- {
- props = new MaterialPropertyBlock();
- rend = GetComponent<Renderer>();
- cutoutPropertyID = Shader.PropertyToID("_Cutout");
- forwardDirPropertyID = Shader.PropertyToID("_DecalForwardDir");
- OnEnable();
- }
- private void OnEnable()
- {
- startTime = Time.time + TimeDelay;
- canUpdate = true;
- GetComponent<Renderer>().enabled = true;
- rend.GetPropertyBlock(props);
- var eval = FloatCurve.Evaluate(0) * GraphIntensityMultiplier;
- props.SetFloat(cutoutPropertyID, eval);
- props.SetVector(forwardDirPropertyID, transform.up);
- rend.SetPropertyBlock(props);
- }
- private void OnDisable()
- {
- rend.GetPropertyBlock(props);
- var eval = FloatCurve.Evaluate(0) * GraphIntensityMultiplier;
- props.SetFloat(cutoutPropertyID, eval);
- rend.SetPropertyBlock(props);
- timeLapsed = 0;
- }
- private void Update()
- {
- if (!canUpdate) return;
- rend.GetPropertyBlock(props);
- var deltaTime = BloodSettings == null ? Time.deltaTime : Time.deltaTime * BloodSettings.AnimationSpeed;
- if (BloodSettings != null && BloodSettings.FreezeDecalDisappearance && (timeLapsed / GraphTimeMultiplier) > 0.3f) { }
- else timeLapsed += deltaTime;
- var eval = FloatCurve.Evaluate(timeLapsed / GraphTimeMultiplier) * GraphIntensityMultiplier;
- props.SetFloat(cutoutPropertyID, eval);
- if (BloodSettings != null) props.SetFloat("_LightIntencity", Mathf.Clamp(BloodSettings.LightIntensityMultiplier, 0.01f, 1f));
- if (timeLapsed >= GraphTimeMultiplier)
- {
- canUpdate = false;
- OnAnimationFinished?.Invoke();
- }
- props.SetVector(forwardDirPropertyID, transform.up);
- rend.SetPropertyBlock(props);
- }
- }
|