狗屎Minimax坏我代码
This commit is contained in:
103
Assets/Scripts/MainGame/Effects/VFX/Assistance/LightGradient.cs
Normal file
103
Assets/Scripts/MainGame/Effects/VFX/Assistance/LightGradient.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Lean.Pool;
|
||||
using Sirenix.OdinInspector;
|
||||
|
||||
namespace Cielonos.MainGame
|
||||
{
|
||||
public class LightGradient : MonoBehaviour, IPoolable
|
||||
{
|
||||
[Required] public Light targetLight;
|
||||
|
||||
[Tooltip("在特效生成时是否立刻启用渐变,注意,必须通过对象池生成。\n为true时,渐变效果从targetLight的默认intensity开始,否则需要调用EnableFade方法启用渐变")]
|
||||
public bool playOnSpawn = true;
|
||||
|
||||
[Tooltip("光源渐变的生命周期")] public float life = 1f;
|
||||
|
||||
[Tooltip("是否应用强度变化")] public bool applyIntensityFade = true;
|
||||
[Tooltip("初始强度")] [ShowIf("applyIntensityFade")] public float initialIntensity = 1;
|
||||
[Tooltip("渐变曲线")] [ShowIf("applyIntensityFade")] public AnimationCurve intensityFadeCurve;
|
||||
|
||||
[Tooltip("是否应用范围变化")] public bool applyRangeFade = false;
|
||||
[Tooltip("初始范围")][ShowIf("applyRangeFade")] public float initialRange = 1;
|
||||
[Tooltip("范围曲线")][ShowIf("applyRangeFade")] public AnimationCurve rangeFadeCurve;
|
||||
|
||||
[Tooltip("是否使用光源颜色渐变")] public bool useLightColorGradient = false;
|
||||
[Tooltip("光源颜色渐变")][ShowIf("useLightColorGradient")] public Gradient lightColorGradient;
|
||||
|
||||
[HideInEditorMode]
|
||||
[SerializeField]
|
||||
private bool isFading;
|
||||
[HideInEditorMode]
|
||||
[SerializeField]
|
||||
private float time;
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
targetLight = GetComponent<Light>();
|
||||
intensityFadeCurve = AnimationCurve.EaseInOut(0, 1, 1, 0);
|
||||
rangeFadeCurve = AnimationCurve.EaseInOut(0, 1, 1, 0);
|
||||
}
|
||||
|
||||
public void OnSpawn()
|
||||
{
|
||||
if (playOnSpawn && !isFading)
|
||||
{
|
||||
EnableFade(initialIntensity, initialRange);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDespawn()
|
||||
{
|
||||
isFading = false;
|
||||
}
|
||||
|
||||
public void EnableFade(float intensity, float initialRange)
|
||||
{
|
||||
if (targetLight == null) throw new NullReferenceException("Target Light is null");
|
||||
|
||||
time = 0;
|
||||
isFading = true;
|
||||
if (applyIntensityFade)
|
||||
{
|
||||
this.initialIntensity = intensity;
|
||||
targetLight.intensity = intensity;
|
||||
}
|
||||
|
||||
if (applyRangeFade)
|
||||
{
|
||||
this.initialRange = initialRange;
|
||||
targetLight.range = initialRange;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!isFading) return;
|
||||
|
||||
time += Time.deltaTime;
|
||||
|
||||
if (applyIntensityFade)
|
||||
{
|
||||
targetLight.intensity = initialIntensity * intensityFadeCurve.Evaluate(time / life);
|
||||
}
|
||||
|
||||
if (applyRangeFade)
|
||||
{
|
||||
targetLight.range = initialRange * rangeFadeCurve.Evaluate(time / life);
|
||||
}
|
||||
|
||||
if (useLightColorGradient)
|
||||
{
|
||||
targetLight.color = lightColorGradient.Evaluate(time / life);
|
||||
}
|
||||
|
||||
if (time > life)
|
||||
{
|
||||
time = 0;
|
||||
isFading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 24ff3199a15f84e469258023a00cc54f
|
||||
timeCreated: 1493668034
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,139 @@
|
||||
using System;
|
||||
using Lean.Pool;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace Cielonos.MainGame
|
||||
{
|
||||
public class TransformAdjustment : MonoBehaviour, IPoolable
|
||||
{
|
||||
[Required] public VFXObject vfxObject;
|
||||
[Required] public Transform targetTransform;
|
||||
|
||||
[Tooltip("在特效生成时是否立刻启用渐变,注意,必须通过对象池生成。\n为true时,渐变效果从默认transform开始,否则需要调用EnableFade方法启用渐变")]
|
||||
public bool playOnSpawn = true;
|
||||
|
||||
[Tooltip("生命周期")] public float life = 1f;
|
||||
|
||||
[Tooltip("是否应用本地位置变化")] public bool applyLocalPosition = true;
|
||||
[Tooltip("初始位置")] [ShowIf("applyLocalPosition")] public Vector3 initialLocalPosition;
|
||||
[Tooltip("目标位置")] [ShowIf("applyLocalPosition")] public Vector3 targetLocalPosition = Vector3.zero;
|
||||
[Tooltip("X位置曲线")] [ShowIf("applyLocalPosition")] public AnimationCurve positionCurveX;
|
||||
[Tooltip("Y位置曲线")] [ShowIf("applyLocalPosition")] public AnimationCurve positionCurveY;
|
||||
[Tooltip("Z位置曲线")] [ShowIf("applyLocalPosition")] public AnimationCurve positionCurveZ;
|
||||
|
||||
[Tooltip("是否应用本地旋转变化")] public bool applyLocalRotation = false;
|
||||
[Tooltip("初始旋转")][ShowIf("applyLocalRotation")]public Vector3 initialEulerAngles;
|
||||
[Tooltip("初始旋转")][ShowIf("applyLocalRotation")] public Vector3 targetEulerAngles = Vector3.zero;
|
||||
[Tooltip("X旋转曲线")][ShowIf("applyLocalRotation")] public AnimationCurve rotationCurveX;
|
||||
[Tooltip("Y旋转曲线")][ShowIf("applyLocalRotation")] public AnimationCurve rotationCurveY;
|
||||
[Tooltip("Z旋转曲线")][ShowIf("applyLocalRotation")] public AnimationCurve rotationCurveZ;
|
||||
|
||||
[Tooltip("是否应用本地缩放变化")] public bool applyLocalScale = false;
|
||||
[Tooltip("初始缩放")][ShowIf("applyLocalScale")] public Vector3 initialLocalScale;
|
||||
[Tooltip("目标缩放")][ShowIf("applyLocalScale")] public Vector3 targetLocalScale = Vector3.one;
|
||||
[Tooltip("X缩放曲线")][ShowIf("applyLocalScale")] public AnimationCurve scaleCurveX;
|
||||
[Tooltip("Y缩放曲线")][ShowIf("applyLocalScale")] public AnimationCurve scaleCurveY;
|
||||
[Tooltip("Z缩放曲线")][ShowIf("applyLocalScale")] public AnimationCurve scaleCurveZ;
|
||||
|
||||
[HideInEditorMode]
|
||||
[SerializeField]
|
||||
private bool isFading;
|
||||
[HideInEditorMode]
|
||||
[SerializeField]
|
||||
private float time;
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
targetTransform = transform;
|
||||
positionCurveX = AnimationCurve.EaseInOut(0, 0, 1, 1);
|
||||
positionCurveY = AnimationCurve.EaseInOut(0, 0, 1, 1);
|
||||
positionCurveZ = AnimationCurve.EaseInOut(0, 0, 1, 1);
|
||||
rotationCurveX = AnimationCurve.EaseInOut(0, 0, 1, 1);
|
||||
rotationCurveY = AnimationCurve.EaseInOut(0, 0, 1, 1);
|
||||
rotationCurveZ = AnimationCurve.EaseInOut(0, 0, 1, 1);
|
||||
scaleCurveX = AnimationCurve.EaseInOut(0, 0, 1, 1);
|
||||
scaleCurveY = AnimationCurve.EaseInOut(0, 0, 1, 1);
|
||||
scaleCurveZ = AnimationCurve.EaseInOut(0, 0, 1, 1);
|
||||
}
|
||||
|
||||
public void OnSpawn()
|
||||
{
|
||||
if (playOnSpawn && !isFading)
|
||||
{
|
||||
Enable(targetLocalPosition, targetEulerAngles, targetLocalScale);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDespawn()
|
||||
{
|
||||
isFading = false;
|
||||
}
|
||||
|
||||
public void Enable(Vector3 position, Vector3 eulerAngles, Vector3 scale)
|
||||
{
|
||||
if (targetTransform == null) throw new NullReferenceException("Target Transform is null");
|
||||
|
||||
time = 0;
|
||||
isFading = true;
|
||||
if (applyLocalPosition)
|
||||
{
|
||||
this.targetLocalPosition = position;
|
||||
targetTransform.localPosition = initialLocalPosition;
|
||||
}
|
||||
|
||||
if (applyLocalRotation)
|
||||
{
|
||||
this.targetEulerAngles = eulerAngles;
|
||||
targetTransform.localEulerAngles = initialEulerAngles;
|
||||
}
|
||||
|
||||
if (applyLocalScale)
|
||||
{
|
||||
this.targetLocalScale = scale;
|
||||
targetTransform.localScale = initialLocalScale;
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!isFading) return;
|
||||
|
||||
time += vfxObject?.DeltaTime ?? Time.deltaTime;
|
||||
|
||||
if (applyLocalPosition)
|
||||
{
|
||||
targetTransform.localPosition = initialLocalPosition + new Vector3(
|
||||
(targetLocalPosition.x - initialLocalPosition.x) * positionCurveX.Evaluate(time / life),
|
||||
(targetLocalPosition.y - initialLocalPosition.y) * positionCurveY.Evaluate(time / life),
|
||||
(targetLocalPosition.z - initialLocalPosition.z) * positionCurveZ.Evaluate(time / life)
|
||||
);
|
||||
}
|
||||
|
||||
if (applyLocalRotation)
|
||||
{
|
||||
targetTransform.localEulerAngles = initialEulerAngles + new Vector3(
|
||||
(targetEulerAngles.x - initialEulerAngles.x) * rotationCurveX.Evaluate(time / life),
|
||||
(targetEulerAngles.y - initialEulerAngles.y) * rotationCurveY.Evaluate(time / life),
|
||||
(targetEulerAngles.z - initialEulerAngles.z) * rotationCurveZ.Evaluate(time / life)
|
||||
);
|
||||
}
|
||||
|
||||
if (applyLocalScale)
|
||||
{
|
||||
targetTransform.localScale = initialLocalScale + new Vector3(
|
||||
(targetLocalScale.x - initialLocalScale.x) * scaleCurveX.Evaluate(time / life),
|
||||
(targetLocalScale.y - initialLocalScale.y) * scaleCurveY.Evaluate(time / life),
|
||||
(targetLocalScale.z - initialLocalScale.z) * scaleCurveZ.Evaluate(time / life)
|
||||
);
|
||||
}
|
||||
|
||||
if (time > life)
|
||||
{
|
||||
time = 0;
|
||||
isFading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7723a076048a1c4e99bd7a77fdc664a
|
||||
@@ -0,0 +1,140 @@
|
||||
using System.Collections.Generic;
|
||||
using Lean.Pool;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cielonos.MainGame
|
||||
{
|
||||
public class VFXRaycastInteraction : MonoBehaviour, IPoolable
|
||||
{
|
||||
[Header("核心设置")]
|
||||
[Tooltip("在特效生成时是否立刻启用渐变,注意,必须通过对象池生成。\n为true时,渐变效果从targetLight的默认intensity开始,否则需要调用EnableFade方法启用渐变")]
|
||||
public bool playOnSpawn = true;
|
||||
public float life = 1f;
|
||||
public List<float> checkPoints;
|
||||
public int currentCheckPointIndex = 0;
|
||||
public bool isEnabling = true;
|
||||
public Transform startPoint; // 刀尖的位置(用于发射射线)
|
||||
public LayerMask collisionLayers; // 地面图层
|
||||
public float rayLength = 0.5f; // 射线长度(稍微比刀刃离地距离长一点)
|
||||
|
||||
[Header("特效资源")]
|
||||
public GameObject sparkPrefab; // 火星特效 Prefab
|
||||
public GameObject decalPrefab; // 划痕 Decal Prefab
|
||||
|
||||
[HideInEditorMode]
|
||||
[SerializeField]
|
||||
private bool isFading;
|
||||
[HideInEditorMode]
|
||||
[SerializeField]
|
||||
private float time;
|
||||
private Vector3 _lastTipPosition;
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
startPoint = transform;
|
||||
collisionLayers = LayerMask.GetMask("Wall", "Ground");
|
||||
}
|
||||
|
||||
public void OnSpawn()
|
||||
{
|
||||
if (playOnSpawn && !isEnabling)
|
||||
{
|
||||
isEnabling = true;
|
||||
time = 0f;
|
||||
currentCheckPointIndex = 0;
|
||||
}
|
||||
|
||||
_lastTipPosition = startPoint.position;
|
||||
}
|
||||
|
||||
public void OnDespawn()
|
||||
{
|
||||
isEnabling = false;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
if (time >= life)
|
||||
{
|
||||
isEnabling = false;
|
||||
}
|
||||
|
||||
if (!isEnabling || Time.timeScale == 0 || checkPoints.Count == 0) return;
|
||||
|
||||
// 1. 计算刀尖速度方向(用于决定划痕朝向)
|
||||
Vector3 velocity = (startPoint.position - _lastTipPosition) / Time.deltaTime;
|
||||
_lastTipPosition = startPoint.position;
|
||||
|
||||
//1. 检查是否到达下一个检查点
|
||||
if (currentCheckPointIndex < checkPoints.Count)
|
||||
{
|
||||
if (time >= checkPoints[currentCheckPointIndex])
|
||||
{
|
||||
currentCheckPointIndex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
return; // 未到达检查点,跳过本次更新
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return; // 所有检查点已处理完,跳过本次更新
|
||||
}
|
||||
|
||||
|
||||
// 2. 发射射线检测地面
|
||||
// 这里我们向下发射射线。如果你的游戏支持墙壁划痕,可以改为 velocity.normalized
|
||||
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(startPoint.position, startPoint.forward, out hit, rayLength, collisionLayers))
|
||||
{
|
||||
SpawnEffects(hit, velocity);
|
||||
}
|
||||
}
|
||||
|
||||
void SpawnEffects(RaycastHit hit, Vector3 slashVelocity)
|
||||
{
|
||||
Vector3 projectedSlashDir = Vector3.ProjectOnPlane(slashVelocity, hit.normal).normalized;
|
||||
|
||||
// --- 处理火星 (Spark) ---
|
||||
if (sparkPrefab != null)
|
||||
{
|
||||
// 关键点:使用 Quaternion.LookRotation(hit.normal)
|
||||
// 这会让火星特效的 Z轴(发射方向)严格对准地面法线(垂直向上),right方向和挥动方向对齐
|
||||
LeanPool.Spawn(sparkPrefab, hit.point, Quaternion.LookRotation(hit.normal, Vector3.Cross(projectedSlashDir, hit.normal)));
|
||||
}
|
||||
|
||||
// --- 处理划痕 (Decal) ---
|
||||
if (decalPrefab != null)
|
||||
{
|
||||
// 计算划痕的朝向:
|
||||
// 我们希望划痕贴在地面上(法线对齐 hit.normal)
|
||||
// 同时划痕的延伸方向要对齐刀的挥动方向(slashVelocity)
|
||||
if (projectedSlashDir != Vector3.zero)
|
||||
{
|
||||
// 计算 Decal 的旋转,Decal的forward和地面法线对齐,right方向和挥动方向对齐
|
||||
Quaternion decalRotation = Quaternion.LookRotation(hit.normal, Vector3.Cross(projectedSlashDir, hit.normal));
|
||||
|
||||
// 生成 Decal,稍微抬高一点点避免 Z-Fighting
|
||||
GameObject decal = LeanPool.Spawn(decalPrefab, hit.point + hit.normal * 0.01f, decalRotation);
|
||||
|
||||
// 记得在 Prefab 里设置自动销毁,或者在这里写 Destroy
|
||||
LeanPool.Despawn(decal, 5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 用于在 Scene 窗口调试射线,方便你调整 rayLength
|
||||
void OnDrawGizmos()
|
||||
{
|
||||
if (startPoint != null)
|
||||
{
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawLine(startPoint.position, startPoint.position + transform.forward * rayLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0217139a1a991f947ac6135f8ea20a0c
|
||||
Reference in New Issue
Block a user