一楼大厅优化未完成

This commit is contained in:
ZYT
2025-07-22 11:42:28 +08:00
parent fbbe238b5b
commit 4a65dc27fd
20 changed files with 390 additions and 104 deletions

View File

@@ -108,7 +108,7 @@ using UnityEngine.AI;
break; // 太近了,提前跳出
}
// 5. 如果通过了 avoidRadius就直接返回
//5.如果通过了 avoidRadius就直接返回
if (minDistToOthers >= avoidRadius.Value)
return cand;
@@ -142,10 +142,190 @@ using UnityEngine.AI;
}
}
/// <summary>
/// 检测boss是否到阶段血量
/// </summary>
public class CheckEnemyHp : Conditional
public class MoveToPlayerFront : Action
{
public SharedFloat minDistance = new SharedFloat { Value = 3f };
public SharedFloat maxDistance = new SharedFloat { Value = 5f };
public SharedFloat minAngle = new SharedFloat { Value = 30f };
public SharedFloat maxAngle = new SharedFloat { Value = 40f };
// 添加静态字典记录每个怪物的移动状态
private static Dictionary<GameObject, bool> hasMoved = new Dictionary<GameObject, bool>();
private NavMeshAgent agent;
private bool hasReachedPosition;
private Vector3 finalPosition; // 存储最终位置
// 添加静态字典记录每个敌人的移动状态
private static Dictionary<int, bool> hasMovedDict = new Dictionary<int, bool>();
private int instanceID;
public override void OnAwake()
{
instanceID = gameObject.GetInstanceID();
}
public override void OnStart()
{
// 检查是否已经移动过
if (hasMovedDict.ContainsKey(instanceID) && hasMovedDict[instanceID])
{
hasReachedPosition = true;
return;
}
agent = GetComponent<NavMeshAgent>();
agent.autoBraking = true;
agent.stoppingDistance = 0.1f;
// 计算玩家正前方扇形区域内的随机位置
finalPosition = CalculateFrontPosition();
if (agent.isActiveAndEnabled)
{
agent.SetDestination(finalPosition);
hasReachedPosition = false;
}
}
public override TaskStatus OnUpdate()
{
// 如果已经移动过,直接返回成功
if (hasMovedDict.ContainsKey(instanceID) && hasMovedDict[instanceID])
{
return TaskStatus.Success;
}
if (hasReachedPosition)
{
//标记为已移动
hasMovedDict[instanceID] = true;
return TaskStatus.Success;
}
// 检查是否到达目标位置
if (!agent.pathPending && agent.remainingDistance <= agent.stoppingDistance)
{
// 完全停止导航系统
agent.isStopped = true;
agent.ResetPath();
agent.enabled = false; // 禁用导航组件
// 固定位置
transform.position = finalPosition;
// 添加物理约束(如果有刚体)
Rigidbody rb = GetComponent<Rigidbody>();
if (rb != null)
{
rb.isKinematic = true;
rb.velocity = Vector3.zero;
rb.angularVelocity = Vector3.zero;
}
// 标记为已移动
hasMoved[gameObject] = true;
hasReachedPosition = true;
return TaskStatus.Success;
}
return TaskStatus.Running;
}
private Vector3 CalculateFrontPosition()
{
Transform player = GameManager.Ins.player.transform;
Vector3 playerPos = player.position;
Vector3 playerForward = player.forward;
// 随机角度 (30-40度之间随机左右侧)
float randomAngle = Random.Range(minAngle.Value, maxAngle.Value) *
(Random.value > 0.5f ? 1f : -1f);
// 随机距离
float randomDistance = Random.Range(minDistance.Value, maxDistance.Value);
// 计算方向向量 (玩家前方旋转随机角度)
Quaternion rotation = Quaternion.Euler(0f, randomAngle, 0f);
Vector3 direction = rotation * playerForward;
// 计算目标位置
Vector3 targetPos = playerPos + direction * randomDistance;
// 确保位置在NavMesh上
if (NavMesh.SamplePosition(targetPos, out NavMeshHit hit, 5f, NavMesh.AllAreas)) // 增加采样范围
{
// 确保不会出现在半空中
if (Mathf.Abs(hit.position.y - playerPos.y) > 2f)
{
// 如果高度差太大,调整到玩家高度
return new Vector3(hit.position.x, playerPos.y, hit.position.z);
}
return hit.position;
}
// 如果采样失败,使用玩家位置(确保不会出现在半空中)
return playerPos + Vector3.up * 0.1f; // 稍微高于地面
}
// 当敌人被销毁时清理记录
public override void OnEnd()
{
if (hasMovedDict.ContainsKey(instanceID))
{
hasMovedDict.Remove(instanceID);
}
}
}
public class SetAttackState : Action
{
public SharedBool attackState;
// 添加静态字典记录每个敌人的攻击状态
private static Dictionary<int, bool> attackStateSet = new Dictionary<int, bool>();
private int instanceID;
public override void OnAwake()
{
instanceID = gameObject.GetInstanceID();
}
public override TaskStatus OnUpdate()
{
// 如果已经设置过攻击状态,直接返回成功
if (attackStateSet.ContainsKey(instanceID) && attackStateSet[instanceID])
{
return TaskStatus.Success;
}
Enemy1 enemy = GetComponent<Enemy1>();
if (enemy != null)
{
enemy.SetAttackState(attackState.Value);
// 标记为已设置
attackStateSet[instanceID] = true;
return TaskStatus.Success;
}
return TaskStatus.Failure;
}
// 当敌人被销毁时清理记录
public override void OnEnd()
{
if (attackStateSet.ContainsKey(instanceID))
{
attackStateSet.Remove(instanceID);
}
}
}
/// <summary>
/// 检测boss是否到阶段血量
/// </summary>
public class CheckEnemyHp : Conditional
{
public SharedFloat hpIndex;
@@ -351,16 +531,27 @@ using UnityEngine.AI;
}
}
public class NormalAttack : Action
public class NormalAttack : Action
{
private Enemy1 enemy;
public override void OnAwake()
{
public override void OnStart()
enemy = GetComponent<Enemy1>();
}
public override void OnStart()
{
//// 你的普攻逻辑
//Debug.Log("执行普攻");
//Enemy curEnemy = GetComponent<Enemy>();
//curEnemy.Attack();
if(enemy != null && !enemy.isAttack)
{
// 你的普攻逻辑
Debug.Log("执行普攻");
Enemy curEnemy = GetComponent<Enemy>();
curEnemy.Attack();
enemy.Attack();
}
}
}
public class IsSkillReady : Conditional
{

View File

@@ -281,7 +281,7 @@ public class Boss : Enemy
}
}
private float enemyTime=45f;
private float enemyTime=90f;
private float curEnemyTime;
public void ShowEnemy()
{

View File

@@ -5,6 +5,7 @@ using DG.Tweening;
using DragonLi.Core;
using DragonLi.Frame;
using UnityEngine;
using UnityEngine.AI;
public class DropShip : Enemy
{
@@ -12,7 +13,7 @@ public class DropShip : Enemy
public GameObject player;
public Transform[] enemyPos;
public Vector3 startPos;
public GameObject bigXl;//大招蓄力特效
public GameObject mzObj;//瞄准特效
public GameObject damagableObj;//受伤特效
@@ -39,8 +40,8 @@ public class DropShip : Enemy
}
bloodSlider.gameObject.SetActive(false);
enemyState = EnemyState.Show;
GameInit.Ins.PlayAudio("1.8",GameInit.Ins.self.transform,true);
GameInit.Ins.PlayAudio("1.8", GameInit.Ins.self.transform, true);
}
public override void Attack()
@@ -66,13 +67,13 @@ public class DropShip : Enemy
components[1].Stop();
if (components[2].isDead && components[3].isDead)
{
Fly();
Fly();
}
else if(!components[2].isDead && components[3].isDead)
else if (!components[2].isDead && components[3].isDead)
{
StartCoroutine(ShootOneAttackMode(2, Fly));
}
else if(components[2].isDead && !components[3].isDead)
else if (components[2].isDead && !components[3].isDead)
{
StartCoroutine(ShootOneAttackMode(3, Fly));
}
@@ -81,7 +82,7 @@ public class DropShip : Enemy
StartCoroutine(ShootOneAttackMode(2));
StartCoroutine(ShootOneAttackMode(3, Fly));
}
}
public override void TwoAttackMode()
@@ -92,19 +93,20 @@ public class DropShip : Enemy
public void ShowEnemy()
{
for (int i = 0; i < enemyPos.Length; i++)
{
Vector3 curEnemyPos=new Vector3(enemyPos[i].position.x,0,enemyPos[i].position.z);
Vector3 curEnemyPos = new Vector3(enemyPos[i].position.x, 0, enemyPos[i].position.z);
GameManager.Ins.CreateCallEnemyEffect(curEnemyPos);
}
MonoSingleton<CoroutineTaskManager>.Instance.WaitSecondTodo(() =>
{
for (int i = 0; i < enemyPos.Length; i++)
{
Vector3 curEnemyPos=new Vector3(enemyPos[i].position.x,0,enemyPos[i].position.z);
GameManager.Ins.CreateEnemy(1,curEnemyPos,Vector3.zero,false);
Vector3 curEnemyPos = new Vector3(enemyPos[i].position.x, 0, enemyPos[i].position.z);
GameManager.Ins.CreateEnemy(1, curEnemyPos, Vector3.zero, false);
}
},2f);
}, 2f);
}
public override void ThreeAttackMode()
@@ -144,10 +146,10 @@ public class DropShip : Enemy
// 最后一段,直接用预先算好的玩家位置
targetPos = playerTarget;
}
targetPos=new Vector3(targetPos.x, 0f, targetPos.z);
targetPos = new Vector3(targetPos.x, 0f, targetPos.z);
Debug.Log($"发射第 {i} 发导弹,目标点 = {targetPos}");
components[curIndex].EnemyShoot(targetPos);
GameInit.Ins.PlayAudio("2.3导弹发射",transform,false);
GameInit.Ins.PlayAudio("2.3导弹发射", transform, false);
yield return new WaitForSeconds(oneAttackInterval);
}
@@ -155,7 +157,7 @@ public class DropShip : Enemy
cb?.Invoke();
}
public override void Show()
{
base.Show();
@@ -166,17 +168,17 @@ public class DropShip : Enemy
float endValue = 10;
if (GameInit.Ins.gamePlace == GamePlace.HangZhouLongHuTianJie)
endValue = 35f;
if(GameInit.Ins.gamePlace== GamePlace.Yangzhou_Hanjiang_TansuoZhongxin_wai)
if (GameInit.Ins.gamePlace == GamePlace.Yangzhou_Hanjiang_TansuoZhongxin_wai)
endValue = 16f;
if(GameInit.Ins.gamePlace== GamePlace.Guangzhou_Panyv_Zhanting)
if (GameInit.Ins.gamePlace == GamePlace.Guangzhou_Panyv_Zhanting)
endValue = -7f;
if(GameInit.Ins.gamePlace== GamePlace.Anhui_Wuhu_Guanwei)
if (GameInit.Ins.gamePlace == GamePlace.Anhui_Wuhu_Guanwei)
endValue = 13f;
if(GameInit.Ins.gamePlace== GamePlace.Zhejiang_Jinhua_KeJiGuan)
if (GameInit.Ins.gamePlace == GamePlace.Zhejiang_Jinhua_KeJiGuan)
endValue = 17f;
if(GameInit.Ins.gamePlace== GamePlace.ShanDong_Langfang_QingzhouTaihuacheng)
if (GameInit.Ins.gamePlace == GamePlace.ShanDong_Langfang_QingzhouTaihuacheng)
endValue = 20f;
if(GameInit.Ins.gamePlace== GamePlace.Shandong_Jining_Shangchang_nei)
if (GameInit.Ins.gamePlace == GamePlace.Shandong_Jining_Shangchang_nei)
endValue = 7f;
if (GameInit.Ins.gamePlace == GamePlace.Company1Floor)
{
@@ -193,7 +195,7 @@ public class DropShip : Enemy
_isShow = false;
});
}
if (GameInit.Ins.gamePlace == GamePlace.HangZhouLongHuTianJie||GameInit.Ins.gamePlace== GamePlace.Guangzhou_Panyv_Zhanting )
if (GameInit.Ins.gamePlace == GamePlace.HangZhouLongHuTianJie || GameInit.Ins.gamePlace == GamePlace.Guangzhou_Panyv_Zhanting)
{
transform.DOMoveX(endValue, 4).OnComplete(() =>
{
@@ -210,7 +212,7 @@ public class DropShip : Enemy
}
if (GameInit.Ins.gamePlace == GamePlace.Hubei_Xiangyang_Kejiguan)
{
transform.DOMove(new Vector3(-8.12f,transform.position.y,-3.71f), 4).OnComplete(() =>
transform.DOMove(new Vector3(-8.12f, transform.position.y, -3.71f), 4).OnComplete(() =>
{
isAttack = true;
foreach (var item in tailGas)
@@ -264,17 +266,17 @@ public class DropShip : Enemy
public void Fly()
{
isShield = true;
AnimatorComponent.SetBool("fly",true);
GameInit.Ins.PlayAudio("2.11冲刺",transform,false);
AnimatorComponent.SetBool("fly", true);
GameInit.Ins.PlayAudio("2.11冲刺", transform, false);
foreach (var item in tailGas)
{
item.SetActive(false);
}
MonoSingleton<CoroutineTaskManager>.Instance.WaitSecondTodo(() =>
{
isShield=false;
isShield = false;
StopFly();
},3f);
}, 3f);
}
public void StopFly()
@@ -283,16 +285,16 @@ public class DropShip : Enemy
{
item.SetActive(true);
}
AnimatorComponent.SetBool("fly",false);
AnimatorComponent.SetBool("fly", false);
userSillIng = false;
}
public override void Dead()
{
var pos=transform.position;
var pos = transform.position;
if (GameInit.Ins.gamePlace == GamePlace.ShanDong_Langfang_QingzhouTaihuacheng)
pos = new Vector3(16.6f, 0, 16.2f);
if(!isDead)
if (!isDead)
GameManager.Ins.CurLevelWin(pos);
base.Dead();
}
@@ -326,10 +328,10 @@ public class DropShip : Enemy
public override void ChangeHp(float value, object info, Transform _sender)
{
base.ChangeHp(value, info, _sender);
damagableObj.SetActive(health/maxHealth<=0.5f);
damagableObj.SetActive(health / maxHealth <= 0.5f);
}
private float enemyTime=45f;
private float enemyTime = 60f;
private float curEnemyTime;
public override void Update()
{
@@ -344,15 +346,15 @@ public class DropShip : Enemy
Quaternion targetRotation = Quaternion.LookRotation(targetDir);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 2f);
}
curEnemyTime-=Time.deltaTime;
curEnemyTime -= Time.deltaTime;
if (curEnemyTime <= 0)
{
if (GameManager.Ins.GetCurEnemyListCount() <= 8)
if (GameManager.Ins.GetCurEnemyListCount() <= 5)
{
ShowEnemy();
}
}
curEnemyTime = enemyTime;
}
}
}
}

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using BehaviorDesigner.Runtime;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Mozilla;
using DragonLi.Behaviour;
using DragonLi.Core;
using DragonLi.Frame;
@@ -88,7 +89,7 @@ public class Enemy : MonoBehaviour
public bool userSillIng;
public bool isAttack;
public bool isAttack { get; set; }
public EnemyComponent[] components;
@@ -138,12 +139,12 @@ public class Enemy : MonoBehaviour
public virtual void Attack()
{
isAttack = true;
}
public virtual void StopAttack()
{
isAttack=false;
}
public virtual void OneAttackMode()

View File

@@ -5,30 +5,41 @@ using BehaviorDesigner.Runtime;
using DG.Tweening;
using DragonLi.Behaviour;
using DragonLi.Frame;
using JetBrains.Annotations;
using UnityEngine;
using UnityEngine.AI;
public class Enemy1 : Enemy
{
public Transform playerPos;
public EnemyComponent gun;
private bool _isShow;
//控制攻击状态变量
private bool shouldAttack = false;
public override void Init()
{
base.Init();
playerPos=GameObject.FindGameObjectWithTag("Player").transform;
base.Init();
playerPos = GameObject.FindGameObjectWithTag("Player").transform;
//确保playerPos不为空
if (playerPos == null && GameManager.Ins.player != null)
{
playerPos = GameManager.Ins.transform;
}
}
public void SetShowWaitTime(float time)
{
isShield = true;
if(behaviourTree!=null)
behaviourTree.SetVariableValue("waitTime",(SharedFloat)time);
if (behaviourTree != null)
behaviourTree.SetVariableValue("waitTime", (SharedFloat)time);
}
public override void Attack()
{
base.Attack();
@@ -37,23 +48,36 @@ public class Enemy1 : Enemy
public void ShotGun()
{
AnimatorComponent.SetBool("shoting",true);
AnimatorComponent.SetBool("shoting", true);
gun.Play();
}
public override void StopAttack()
{
base.StopAttack();
AnimatorComponent.SetBool("shoting",false);
gun.Stop();
AnimatorComponent.SetBool("shoting", false);
gun.Stop();
}
public override void Update()
{
if(_isShow)
if (_isShow)
return;
base.Update();
isShield = false;
transform.LookAt(new Vector3(playerPos.position.x,transform.position.y,playerPos.position.z));
transform.LookAt(new Vector3(playerPos.position.x, transform.position.y, playerPos.position.z));
//移除距离判断,直接根据攻击状态决定是否攻击
if (shouldAttack)
{
ShotGun();
}
}
public void SetAttackState(bool attack)
{
shouldAttack = attack;
}
public override void Dead()
@@ -61,4 +85,4 @@ public class Enemy1 : Enemy
base.Dead();
gun.Stop();
}
}
}

View File

@@ -326,7 +326,7 @@ public class Leviathan : Enemy
}
private bool _isShow;
private float enemyTime=45f;
private float enemyTime=90f;
private float curEnemyTime;
public override void Update()
{
@@ -347,7 +347,7 @@ public class Leviathan : Enemy
curEnemyTime-=Time.deltaTime;
if (curEnemyTime <= 0)
{
if(GameManager.Ins.GetCurEnemyListCount()<=8)
if(GameManager.Ins.GetCurEnemyListCount()<=5)
ShowEnemy();
curEnemyTime = enemyTime;
}

View File

@@ -77,6 +77,8 @@ public class MachineDragon : Enemy
endValue = 0f;
if (GameInit.Ins.gamePlace == GamePlace.ShanDong_Langfang_QingzhouTaihuacheng)
endValue = 6.3f;
if (GameInit.Ins.gamePlace == GamePlace.Company1Floor)
endValue = 7f;
if (GameInit.Ins.gamePlace == GamePlace.Yangzhou_Hanjiang_TansuoZhongxin_wai
|| GameInit.Ins.gamePlace ==GamePlace.Zhejiang_Jinhua_KeJiGuan
|| GameInit.Ins.gamePlace ==GamePlace.Anhui_Wuhu_Guanwei
@@ -318,7 +320,7 @@ public class MachineDragon : Enemy
attackMode = 0;
}
private float enemyTime=45f;
private float enemyTime=90f;
private float curEnemyTime;
public override void Update()
{
@@ -342,7 +344,7 @@ public class MachineDragon : Enemy
curEnemyTime-=Time.deltaTime;
if (curEnemyTime <= 0)
{
if(GameManager.Ins.GetCurEnemyListCount()<=8)
if(GameManager.Ins.GetCurEnemyListCount()<=5)
ShowEnemy();
curEnemyTime = enemyTime;
}

View File

@@ -17,7 +17,7 @@ public class Player : MonoBehaviour
public Transform RightHand;
[Header("玩家最大血量")]
public float maxHp = 10000;
public float maxHp = 25000;
private float currentHp;
public float Health
{