крутой шейдер
This commit is contained in:
1 parent
da648df1d9
commit
9245409fc9
9 files changed
+446
-59
No files matched your search
+110
-20
@@ -12,6 +12,9 @@ public class BlindMutantAI : MonoBehaviour
|
||||
|
||||
[Header("Патрулирование")]
|
||||
public Transform[] patrolPoints;
|
||||
[Tooltip("Время паузы на точке патрулирования для прислушивания")]
|
||||
public float waitTimeAtPoint = 1.5f;
|
||||
private float waitTimer = 0f;
|
||||
private int currentPatrolIndex;
|
||||
private bool isInvestigating = false;
|
||||
|
||||
@@ -30,7 +33,20 @@ public class BlindMutantAI : MonoBehaviour
|
||||
void Start()
|
||||
{
|
||||
agent = GetComponent<NavMeshAgent>();
|
||||
agent.speed = walkSpeed;
|
||||
if (agent != null)
|
||||
{
|
||||
agent.speed = walkSpeed;
|
||||
|
||||
// Если агент чуть выше пола или не на сетке, привязываем его к ближайшей точке NavMesh
|
||||
if (!agent.isOnNavMesh)
|
||||
{
|
||||
if (NavMesh.SamplePosition(transform.position, out NavMeshHit hit, 5.0f, NavMesh.AllAreas))
|
||||
{
|
||||
agent.Warp(hit.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
animator = GetComponentInChildren<Animator>();
|
||||
|
||||
// Автоматически находим игрока на сцене
|
||||
@@ -40,9 +56,36 @@ public class BlindMutantAI : MonoBehaviour
|
||||
targetPlayerHealth = playerObj;
|
||||
}
|
||||
|
||||
if (patrolPoints != null && patrolPoints.Length > 0)
|
||||
// Если точки патрулирования не заданы или массив состоит из null, ищем PatrolWaypoints на сцене
|
||||
if (IsPatrolArrayEmptyOrNull())
|
||||
{
|
||||
GoToNextPatrolPoint();
|
||||
AutoAssignPatrolWaypoints();
|
||||
}
|
||||
|
||||
GoToNextPatrolPoint();
|
||||
}
|
||||
|
||||
private bool IsPatrolArrayEmptyOrNull()
|
||||
{
|
||||
if (patrolPoints == null || patrolPoints.Length == 0) return true;
|
||||
for (int i = 0; i < patrolPoints.Length; i++)
|
||||
{
|
||||
if (patrolPoints[i] != null) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void AutoAssignPatrolWaypoints()
|
||||
{
|
||||
var patrolRoot = GameObject.Find("PatrolWaypoints");
|
||||
if (patrolRoot != null && patrolRoot.transform.childCount > 0)
|
||||
{
|
||||
patrolPoints = new Transform[patrolRoot.transform.childCount];
|
||||
for (int i = 0; i < patrolRoot.transform.childCount; i++)
|
||||
{
|
||||
patrolPoints[i] = patrolRoot.transform.GetChild(i);
|
||||
}
|
||||
Debug.Log($"<color=cyan>[BlindMutantAI] Автоматически обнаружено {patrolPoints.Length} точек патрулирования в объекте 'PatrolWaypoints'.</color>");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,12 +110,14 @@ public class BlindMutantAI : MonoBehaviour
|
||||
private void UpdateAnimator()
|
||||
{
|
||||
if (animator == null) return;
|
||||
float currentSpeed = agent != null && agent.enabled ? agent.velocity.magnitude : 0f;
|
||||
float currentSpeed = agent != null && agent.enabled && agent.isOnNavMesh ? agent.velocity.magnitude : 0f;
|
||||
animator.SetFloat("Speed", currentSpeed);
|
||||
}
|
||||
|
||||
private void HandlePlayerChaseAndAttack()
|
||||
{
|
||||
if (agent == null || !agent.isOnNavMesh) return;
|
||||
|
||||
if (targetPlayerHealth != null && targetPlayerHealth.IsDead)
|
||||
{
|
||||
LosePlayerTarget();
|
||||
@@ -138,26 +183,34 @@ public class BlindMutantAI : MonoBehaviour
|
||||
|
||||
private void HandlePatrolAndInvestigation()
|
||||
{
|
||||
if (!agent.pathPending && agent.remainingDistance < 0.5f)
|
||||
if (agent == null || !agent.isOnNavMesh) return;
|
||||
|
||||
if (!agent.pathPending && agent.remainingDistance < 0.6f)
|
||||
{
|
||||
if (isInvestigating)
|
||||
{
|
||||
isInvestigating = false;
|
||||
agent.speed = walkSpeed;
|
||||
if (patrolPoints != null && patrolPoints.Length > 0)
|
||||
{
|
||||
GoToNextPatrolPoint();
|
||||
}
|
||||
waitTimer = waitTimeAtPoint;
|
||||
}
|
||||
else if (patrolPoints != null && patrolPoints.Length > 0)
|
||||
|
||||
if (waitTimer > 0f)
|
||||
{
|
||||
GoToNextPatrolPoint();
|
||||
waitTimer -= Time.deltaTime;
|
||||
agent.isStopped = true;
|
||||
return;
|
||||
}
|
||||
|
||||
agent.isStopped = false;
|
||||
waitTimer = waitTimeAtPoint;
|
||||
GoToNextPatrolPoint();
|
||||
}
|
||||
}
|
||||
|
||||
private void EngagePlayer(Transform playerTransform)
|
||||
{
|
||||
if (agent == null || !agent.isOnNavMesh) return;
|
||||
|
||||
targetPlayer = playerTransform;
|
||||
if (targetPlayerHealth == null)
|
||||
{
|
||||
@@ -165,6 +218,7 @@ public class BlindMutantAI : MonoBehaviour
|
||||
}
|
||||
|
||||
isInvestigating = false;
|
||||
waitTimer = 0f;
|
||||
agent.isStopped = false;
|
||||
agent.speed = runSpeed;
|
||||
agent.SetDestination(targetPlayer.position);
|
||||
@@ -174,22 +228,55 @@ public class BlindMutantAI : MonoBehaviour
|
||||
private void LosePlayerTarget()
|
||||
{
|
||||
targetPlayer = null;
|
||||
agent.isStopped = false;
|
||||
agent.speed = walkSpeed;
|
||||
isInvestigating = false;
|
||||
|
||||
if (patrolPoints != null && patrolPoints.Length > 0)
|
||||
if (agent != null && agent.isOnNavMesh)
|
||||
{
|
||||
GoToNextPatrolPoint();
|
||||
agent.isStopped = false;
|
||||
agent.speed = walkSpeed;
|
||||
}
|
||||
isInvestigating = false;
|
||||
waitTimer = 0f;
|
||||
|
||||
GoToNextPatrolPoint();
|
||||
Debug.Log("Мутант потерял игрока и возвращается к патрулированию.");
|
||||
}
|
||||
|
||||
private void GoToNextPatrolPoint()
|
||||
{
|
||||
if (patrolPoints == null || patrolPoints.Length == 0) return;
|
||||
agent.destination = patrolPoints[currentPatrolIndex].position;
|
||||
currentPatrolIndex = (currentPatrolIndex + 1) % patrolPoints.Length;
|
||||
if (agent == null || !agent.isOnNavMesh) return;
|
||||
|
||||
if (patrolPoints != null && patrolPoints.Length > 0)
|
||||
{
|
||||
for (int attempts = 0; attempts < patrolPoints.Length; attempts++)
|
||||
{
|
||||
var wp = patrolPoints[currentPatrolIndex];
|
||||
currentPatrolIndex = (currentPatrolIndex + 1) % patrolPoints.Length;
|
||||
|
||||
if (wp != null)
|
||||
{
|
||||
agent.isStopped = false;
|
||||
agent.speed = walkSpeed;
|
||||
agent.SetDestination(wp.position);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Если точек нет вообще — свободное блуждание по комплексу
|
||||
WanderRandomly();
|
||||
}
|
||||
|
||||
private void WanderRandomly()
|
||||
{
|
||||
if (agent == null || !agent.isOnNavMesh) return;
|
||||
|
||||
Vector3 randomDir = Random.insideUnitSphere * 15f;
|
||||
randomDir += transform.position;
|
||||
if (NavMesh.SamplePosition(randomDir, out NavMeshHit hit, 15f, NavMesh.AllAreas))
|
||||
{
|
||||
agent.isStopped = false;
|
||||
agent.speed = walkSpeed;
|
||||
agent.SetDestination(hit.position);
|
||||
}
|
||||
}
|
||||
|
||||
public void HearSound(Vector3 soundPosition)
|
||||
@@ -200,7 +287,10 @@ public class BlindMutantAI : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
if (agent == null || !agent.isOnNavMesh) return;
|
||||
|
||||
isInvestigating = true;
|
||||
waitTimer = 0f;
|
||||
agent.isStopped = false;
|
||||
agent.speed = runSpeed;
|
||||
agent.SetDestination(soundPosition);
|
||||
|
||||
@@ -71,21 +71,31 @@ public class EchoTrigger : MonoBehaviour
|
||||
if (waveActive[i])
|
||||
{
|
||||
waveRadii[i] += waveSpeed * Time.deltaTime;
|
||||
echoMaterial.SetFloat("_EchoRadius" + (i + 1), waveRadii[i]);
|
||||
|
||||
// ВЫЧИСЛЯЕМ ПРОЗРАЧНОСТЬ с учетом стартовой яркости
|
||||
// Умножаем на waveIntensities[i], чтобы бег был ярче, а стелс тусклее
|
||||
float opacity = (1f - (waveRadii[i] / waveMaxRadii[i])) * waveIntensities[i];
|
||||
|
||||
// Mathf.Max не дает уйти в минус, но РАЗРЕШАЕТ быть больше 1 (для HDR свечения)
|
||||
opacity = Mathf.Max(0f, opacity);
|
||||
float currentRadius = waveRadii[i];
|
||||
float maxRadius = waveMaxRadii[i];
|
||||
float progress = Mathf.Clamp01(currentRadius / maxRadius);
|
||||
|
||||
// Плавное появление (Fade-in): в первые 18% пути волна мягко разгорается (без резкой вспышки)
|
||||
float fadeIn = Mathf.SmoothStep(0f, 1f, progress / 0.18f);
|
||||
// Плавное рассеивание (Fade-out): к концу облако плавно растворяется в темноте
|
||||
float fadeOut = Mathf.Pow(1f - progress, 1.4f);
|
||||
|
||||
float opacity = (fadeIn * fadeOut) * waveIntensities[i];
|
||||
opacity = Mathf.Max(0f, opacity);
|
||||
|
||||
echoMaterial.SetFloat("_EchoRadius" + (i + 1), currentRadius);
|
||||
echoMaterial.SetFloat("_EchoOpacity" + (i + 1), opacity);
|
||||
|
||||
if (waveRadii[i] > waveMaxRadii[i])
|
||||
|
||||
Shader.SetGlobalFloat("_EchoRadius" + (i + 1), currentRadius);
|
||||
Shader.SetGlobalFloat("_EchoOpacity" + (i + 1), opacity);
|
||||
|
||||
if (currentRadius >= maxRadius)
|
||||
{
|
||||
waveActive[i] = false;
|
||||
echoMaterial.SetFloat("_EchoRadius" + (i + 1), 0f);
|
||||
echoMaterial.SetFloat("_EchoOpacity" + (i + 1), 0f);
|
||||
Shader.SetGlobalFloat("_EchoRadius" + (i + 1), 0f);
|
||||
Shader.SetGlobalFloat("_EchoOpacity" + (i + 1), 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,7 +156,10 @@ public class EchoTrigger : MonoBehaviour
|
||||
waveRadii[waveIndex] = 0f;
|
||||
waveActive[waveIndex] = true;
|
||||
|
||||
echoMaterial.SetFloat("_EchoOpacity" + (waveIndex + 1), targetIntensity);
|
||||
// Начинаем плавно с 0, чтобы разгореться через fadeIn
|
||||
echoMaterial.SetFloat("_EchoOpacity" + (waveIndex + 1), 0f);
|
||||
echoMaterial.SetVector("_EchoPosition" + (waveIndex + 1), position);
|
||||
Shader.SetGlobalFloat("_EchoOpacity" + (waveIndex + 1), 0f);
|
||||
Shader.SetGlobalVector("_EchoPosition" + (waveIndex + 1), position);
|
||||
}
|
||||
}
|
||||
@@ -908,7 +908,10 @@ public static class LaboratoryLevelGenerator
|
||||
var ai = enemy.GetComponent<BlindMutantAI>();
|
||||
if (ai != null)
|
||||
{
|
||||
Undo.RecordObject(ai, "Setup Patrol Points");
|
||||
ai.patrolPoints = transforms;
|
||||
EditorUtility.SetDirty(ai);
|
||||
EditorUtility.SetDirty(enemy);
|
||||
Debug.Log($"<color=green>Configured {transforms.Length} patrol points for SkinnyOrc BlindMutantAI in South Concourse (0, 0.08, -28)!</color>");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user