Added blood effect & hurt anim controller
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BFX_BloodDecalLayers : MonoBehaviour
|
||||
{
|
||||
public LayerMask DecalLayers = 1;
|
||||
public DecalLayersProperty DecalRenderingMode = DecalLayersProperty.DrawToSelectedLayers;
|
||||
public DepthMode LayerDepthResoulution = DepthMode.FullScreen;
|
||||
|
||||
DepthTextureMode defaultMode;
|
||||
RenderTexture rt;
|
||||
Camera depthCamera;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
var currentCam = GetComponent<Camera>();
|
||||
defaultMode = currentCam.depthTextureMode;
|
||||
if (currentCam.renderingPath == RenderingPath.Forward)
|
||||
{
|
||||
currentCam.depthTextureMode |= DepthTextureMode.Depth;
|
||||
}
|
||||
|
||||
var go = new GameObject("DecalLayersCamera");
|
||||
go.transform.parent = currentCam.transform;
|
||||
go.transform.localPosition = Vector3.zero;
|
||||
go.transform.localRotation = Quaternion.identity;
|
||||
depthCamera = go.AddComponent<Camera>();
|
||||
depthCamera.CopyFrom(currentCam);
|
||||
depthCamera.renderingPath = RenderingPath.Forward;
|
||||
depthCamera.depth = currentCam.depth - 1;
|
||||
depthCamera.cullingMask = DecalLayers;
|
||||
|
||||
CreateDepthTexture();
|
||||
depthCamera.targetTexture = rt;
|
||||
Shader.SetGlobalTexture("_LayerDecalDepthTexture", rt);
|
||||
Shader.EnableKeyword("USE_CUSTOM_DECAL_LAYERS");
|
||||
|
||||
if (DecalRenderingMode == DecalLayersProperty.IgnoreSelectedLayers) Shader.EnableKeyword("USE_CUSTOM_DECAL_LAYERS_IGNORE_MODE");
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
GetComponent<Camera>().depthTextureMode = defaultMode;
|
||||
RenderTexture.ReleaseTemporary(rt);
|
||||
Shader.DisableKeyword("USE_CUSTOM_DECAL_LAYERS");
|
||||
if (DecalRenderingMode == DecalLayersProperty.IgnoreSelectedLayers) Shader.DisableKeyword("USE_CUSTOM_DECAL_LAYERS_IGNORE_MODE");
|
||||
}
|
||||
|
||||
void CreateDepthTexture()
|
||||
{
|
||||
switch (LayerDepthResoulution)
|
||||
{
|
||||
case DepthMode.FullScreen:
|
||||
rt = RenderTexture.GetTemporary(Screen.width, Screen.height, 24, RenderTextureFormat.Depth);
|
||||
break;
|
||||
case DepthMode.HalfScreen:
|
||||
rt = RenderTexture.GetTemporary((int)(Screen.width * 0.5f), (int)(Screen.height * 0.5f), 24, RenderTextureFormat.Depth);
|
||||
break;
|
||||
case DepthMode.QuarterScreen:
|
||||
rt = RenderTexture.GetTemporary((int)(Screen.width * 0.25f), (int)(Screen.height * 0.25f), 24, RenderTextureFormat.Depth);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public enum DecalLayersProperty
|
||||
{
|
||||
DrawToSelectedLayers,
|
||||
IgnoreSelectedLayers
|
||||
}
|
||||
|
||||
public enum DepthMode
|
||||
{
|
||||
FullScreen,
|
||||
HalfScreen,
|
||||
QuarterScreen
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f77967a4e50cf74d9f1e5377f7fbd58
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BFX_BloodSettings : MonoBehaviour
|
||||
{
|
||||
public float AnimationSpeed = 1;
|
||||
public float GroundHeight = 0;
|
||||
[Range(0, 1)]
|
||||
public float LightIntensityMultiplier = 1;
|
||||
public bool FreezeDecalDisappearance = false;
|
||||
public _DecalRenderinMode DecalRenderinMode = _DecalRenderinMode.Floor_XZ;
|
||||
public bool ClampDecalSideSurface = false;
|
||||
|
||||
public enum _DecalRenderinMode
|
||||
{
|
||||
Floor_XZ,
|
||||
AverageRayBetwenForwardAndFloor
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 36b8a788ff17aab40b283e664f0304da
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,23 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BFX_DecaGizmo : MonoBehaviour
|
||||
{
|
||||
Transform t;
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
if (t == null) t = transform;
|
||||
|
||||
Gizmos.color = new Color(49 / 255.0f, 136 / 255.0f, 1, 0.15f);
|
||||
Gizmos.matrix = Matrix4x4.TRS(t.position, t.rotation, t.lossyScale);
|
||||
Gizmos.DrawCube(Vector3.zero, Vector3.one);
|
||||
|
||||
Gizmos.color = new Color(49 / 255.0f, 136 / 255.0f, 1, 0.95f);
|
||||
Gizmos.DrawWireCube(Vector3.zero, Vector3.one);
|
||||
|
||||
Gizmos.matrix = Matrix4x4.identity;
|
||||
Gizmos.color = new Color(0.95f, 0.2f, 0.2f, 0.85f);
|
||||
Gizmos.DrawRay(t.position, t.up);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b852c523428df3449daaa0f53f60fb6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,146 @@
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class BFX_DecalSettings : MonoBehaviour
|
||||
{
|
||||
public BFX_BloodSettings BloodSettings;
|
||||
public Transform parent;
|
||||
public float TimeHeightMax = 3.1f;
|
||||
public float TimeHeightMin = -0.1f;
|
||||
[Space]
|
||||
public Vector3 TimeScaleMax = Vector3.one;
|
||||
public Vector3 TimeScaleMin = Vector3.one;
|
||||
[Space]
|
||||
public Vector3 TimeOffsetMax = Vector3.zero;
|
||||
public Vector3 TimeOffsetMin = Vector3.zero;
|
||||
[Space]
|
||||
public AnimationCurve TimeByHeight = AnimationCurve.Linear(0, 0, 1, 1);
|
||||
|
||||
private Vector3 startOffset;
|
||||
private Vector3 startScale;
|
||||
private float timeDelay;
|
||||
|
||||
Transform t, tParent;
|
||||
BFX_ShaderProperies shaderProperies;
|
||||
|
||||
Vector3 averageRay;
|
||||
bool isPositionInitialized;
|
||||
private Vector3 initializedPosition;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
startOffset = transform.localPosition;
|
||||
startScale = transform.localScale;
|
||||
t = transform;
|
||||
tParent = parent.transform;
|
||||
shaderProperies = GetComponent<BFX_ShaderProperies>();
|
||||
shaderProperies.OnAnimationFinished += ShaderCurve_OnAnimationFinished;
|
||||
}
|
||||
|
||||
private void ShaderCurve_OnAnimationFinished()
|
||||
{
|
||||
GetComponent<Renderer>().enabled = false;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!isPositionInitialized) InitializePosition();
|
||||
if (shaderProperies.enabled && initializedPosition.x < float.PositiveInfinity) transform.position = initializedPosition;
|
||||
}
|
||||
|
||||
void InitializePosition()
|
||||
{
|
||||
GetComponent<Renderer>().enabled = false;
|
||||
|
||||
var currentHeight = parent.position.y;
|
||||
var ground = BloodSettings.GroundHeight;
|
||||
|
||||
var currentScale = parent.localScale.y;
|
||||
var scaledTimeHeightMax = TimeHeightMax * currentScale;
|
||||
var scaledTimeHeightMin = TimeHeightMin * currentScale;
|
||||
|
||||
if (currentHeight - ground >= scaledTimeHeightMax || currentHeight - ground <= scaledTimeHeightMin)
|
||||
{
|
||||
GetComponent<MeshRenderer>().enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
GetComponent<MeshRenderer>().enabled = true;
|
||||
}
|
||||
|
||||
float diff = (tParent.position.y - ground) / scaledTimeHeightMax;
|
||||
diff = Mathf.Abs(diff);
|
||||
|
||||
var scaleMul = Vector3.Lerp(TimeScaleMin, TimeScaleMax, diff);
|
||||
t.localScale = new Vector3(scaleMul.x * startScale.x, startScale.y, scaleMul.z * startScale.z);
|
||||
|
||||
var lastOffset = Vector3.Lerp(TimeOffsetMin, TimeOffsetMax, diff);
|
||||
t.localPosition = startOffset + lastOffset;
|
||||
t.position = new Vector3(t.position.x, ground + 0.05f, t.position.z);
|
||||
|
||||
|
||||
timeDelay = TimeByHeight.Evaluate(diff);
|
||||
|
||||
shaderProperies.enabled = false;
|
||||
Invoke("EnableDecalAnimation", Mathf.Max(0, timeDelay / BloodSettings.AnimationSpeed));
|
||||
|
||||
if (BloodSettings.DecalRenderinMode == BFX_BloodSettings._DecalRenderinMode.AverageRayBetwenForwardAndFloor)
|
||||
{
|
||||
averageRay = GetAverageRay(tParent.position + tParent.right * 0.05f, tParent.right);
|
||||
|
||||
float decalAngle = Vector3.Angle(Vector3.up, averageRay);
|
||||
var zRotation = Mathf.Clamp(decalAngle, -90, 90);
|
||||
var decalRotation = t.localRotation.eulerAngles;
|
||||
t.localRotation = Quaternion.Euler(decalRotation.x, decalRotation.y, -(zRotation) * 0.5f);
|
||||
|
||||
var scaleRelativeToAngle = Mathf.Abs(zRotation) / 90f;
|
||||
var decalScale = t.localScale;
|
||||
decalScale.y = Mathf.Lerp(decalScale.y, decalScale.x * 1.5f, scaleRelativeToAngle);
|
||||
|
||||
t.localScale = decalScale;
|
||||
}
|
||||
|
||||
if (BloodSettings.ClampDecalSideSurface) Shader.EnableKeyword("CLAMP_SIDE_SURFACE");
|
||||
|
||||
isPositionInitialized = true;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (BloodSettings.ClampDecalSideSurface) Shader.DisableKeyword("CLAMP_SIDE_SURFACE");
|
||||
isPositionInitialized = false;
|
||||
initializedPosition = Vector3.positiveInfinity;
|
||||
}
|
||||
|
||||
Vector3 GetAverageRay(Vector3 start, Vector3 forward)
|
||||
{
|
||||
if (Physics.Raycast(start, -forward, out RaycastHit bulletRay))
|
||||
{
|
||||
return (bulletRay.normal + Vector3.up).normalized;
|
||||
}
|
||||
|
||||
return Vector3.up;
|
||||
}
|
||||
|
||||
void EnableDecalAnimation()
|
||||
{
|
||||
shaderProperies.enabled = true;
|
||||
initializedPosition = transform.position;
|
||||
}
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
if (t == null) t = transform;
|
||||
Gizmos.color = new Color(49 / 255.0f, 136 / 255.0f, 1, 0.03f);
|
||||
Gizmos.matrix = Matrix4x4.TRS(t.position, t.rotation, t.lossyScale);
|
||||
Gizmos.DrawCube(Vector3.zero, Vector3.one);
|
||||
|
||||
Gizmos.color = new Color(49 / 255.0f, 136 / 255.0f, 1, 0.85f);
|
||||
Gizmos.DrawWireCube(Vector3.zero, Vector3.one);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ece88c1f58dc84b4da85e14370eb3148
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,57 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
public class BFX_ManualAnimationUpdate : MonoBehaviour
|
||||
{
|
||||
public BFX_BloodSettings BloodSettings;
|
||||
public AnimationCurve AnimationSpeed = AnimationCurve.Linear(0, 0, 1, 1);
|
||||
public float FramesCount = 99;
|
||||
public float TimeLimit = 3;
|
||||
public float OffsetFrames = 0;
|
||||
|
||||
private float currentTime;
|
||||
|
||||
Renderer rend;
|
||||
private MaterialPropertyBlock propertyBlock;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (propertyBlock == null)
|
||||
propertyBlock = new MaterialPropertyBlock();
|
||||
|
||||
rend = GetComponent<Renderer>();
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
rend.enabled = true;
|
||||
|
||||
rend.GetPropertyBlock(propertyBlock);
|
||||
propertyBlock.SetFloat("_UseCustomTime", 1.0f);
|
||||
propertyBlock.SetFloat("_TimeInFrames", 0.0f);
|
||||
rend.SetPropertyBlock(propertyBlock);
|
||||
|
||||
currentTime = 0;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
currentTime += Time.deltaTime * BloodSettings.AnimationSpeed;
|
||||
if (currentTime / TimeLimit > 1.0)
|
||||
{
|
||||
if (rend.enabled) rend.enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var currentFrameTime = AnimationSpeed.Evaluate(currentTime / TimeLimit);
|
||||
currentFrameTime = currentFrameTime * FramesCount + OffsetFrames + 1.1f;
|
||||
float timeInFrames = (Mathf.Ceil(-currentFrameTime) / (FramesCount + 1)) + (1.0f / (FramesCount + 1));
|
||||
|
||||
rend.GetPropertyBlock(propertyBlock);
|
||||
propertyBlock.SetFloat("_LightIntencity", Mathf.Clamp(BloodSettings.LightIntensityMultiplier, 0.01f, 1f));
|
||||
propertyBlock.SetFloat("_TimeInFrames", timeInFrames);
|
||||
rend.SetPropertyBlock(propertyBlock);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 49633916cd5f89f4b9ce3e918ec8509e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class BFX_MouseOrbit : MonoBehaviour
|
||||
{
|
||||
public GameObject target;
|
||||
public float distance = 10.0f;
|
||||
|
||||
public float xSpeed = 250.0f;
|
||||
public float ySpeed = 120.0f;
|
||||
|
||||
public float yMinLimit = -20;
|
||||
public float yMaxLimit = 80;
|
||||
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
|
||||
void Start()
|
||||
{
|
||||
var angles = transform.eulerAngles;
|
||||
x = angles.y;
|
||||
y = angles.x;
|
||||
}
|
||||
|
||||
float prevDistance;
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
if (distance < 2) distance = 2;
|
||||
distance -= Input.GetAxis("Mouse ScrollWheel")*2;
|
||||
if (target && (Input.GetMouseButton(1)))
|
||||
{
|
||||
var pos = Input.mousePosition;
|
||||
var dpiScale = 1f;
|
||||
if (Screen.dpi < 1) dpiScale = 1;
|
||||
if (Screen.dpi < 200) dpiScale = 1;
|
||||
else dpiScale = Screen.dpi/200f;
|
||||
|
||||
if (pos.x < 380*dpiScale && Screen.height - pos.y < 250*dpiScale) return;
|
||||
|
||||
Cursor.visible = false;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
|
||||
x += Input.GetAxis("Mouse X")*xSpeed*0.02f;
|
||||
y -= Input.GetAxis("Mouse Y")*ySpeed*0.02f;
|
||||
|
||||
y = ClampAngle(y, yMinLimit, yMaxLimit);
|
||||
var rotation = Quaternion.Euler(y, x, 0);
|
||||
var position = rotation* new Vector3(0.0f, 0.0f, -distance) + target.transform.position;
|
||||
transform.rotation = rotation;
|
||||
transform.position = position;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Cursor.visible = true;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
//Cursor.visible = true;
|
||||
//Screen.lockCursor = false;
|
||||
}
|
||||
if(Input.GetKey(KeyCode.RightArrow))
|
||||
{
|
||||
if (Time.timeScale < 0.5) x += 1f / 60f * 100;
|
||||
else x += Time.deltaTime * 3;
|
||||
var rotation = Quaternion.Euler(y, x, 0);
|
||||
var position = rotation * new Vector3(0.0f, 0.0f, -distance) + target.transform.position;
|
||||
transform.rotation = rotation;
|
||||
transform.position = position;
|
||||
}
|
||||
|
||||
if (Input.GetKey(KeyCode.LeftArrow))
|
||||
{
|
||||
if(Time.timeScale < 0.5) x -= 1f / 60f * 100;
|
||||
else x -= Time.deltaTime * 3;
|
||||
var rotation = Quaternion.Euler(y, x, 0);
|
||||
var position = rotation * new Vector3(0.0f, 0.0f, -distance) + target.transform.position;
|
||||
transform.rotation = rotation;
|
||||
transform.position = position;
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.UpArrow))
|
||||
{
|
||||
if (Time.timeScale > 0.5) Time.timeScale = 0;
|
||||
else Time.timeScale = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (Math.Abs(prevDistance - distance) > 0.001f)
|
||||
{
|
||||
prevDistance = distance;
|
||||
var rot = Quaternion.Euler(y, x, 0);
|
||||
var po = rot*new Vector3(0.0f, 0.0f, -distance) + target.transform.position;
|
||||
transform.rotation = rot;
|
||||
transform.position = po;
|
||||
}
|
||||
}
|
||||
|
||||
static float ClampAngle(float angle, float min, float max)
|
||||
{
|
||||
if (angle < -360)
|
||||
angle += 360;
|
||||
if (angle > 360)
|
||||
angle -= 360;
|
||||
return Mathf.Clamp(angle, min, max);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5cdfcd8a5761aad45b83bac6c6cf290e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,24 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BFX_RenderDepth : MonoBehaviour
|
||||
{
|
||||
DepthTextureMode defaultMode;
|
||||
void OnEnable()
|
||||
{
|
||||
var cam = GetComponent<Camera>();
|
||||
defaultMode = cam.depthTextureMode;
|
||||
if (cam.renderingPath == RenderingPath.Forward)
|
||||
{
|
||||
cam.depthTextureMode |= DepthTextureMode.Depth;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void OnDisable()
|
||||
{
|
||||
GetComponent<Camera>().depthTextureMode = defaultMode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bae1de9ef5b128449a39ee9c92da9b00
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,90 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e19be2280f3477b4ab19c882db70e553
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user