using System.Collections; using System.Collections.Generic; using DG.Tweening; using DragonLi.Core; using Mirror; using UnityEngine; public class Airdrop : Agent { /// /// 怪物类型 /// #if UNITY_EDITOR [UnityEngine.DisplayOnly] #endif [SyncVar] public EnemyType type; [Header("等级")] #if UNITY_EDITOR [UnityEngine.DisplayOnly] #endif [SyncVar] public int lvl = 0; [Header("速度")] #if UNITY_EDITOR [UnityEngine.DisplayOnly] #endif [SyncVar] public float speed = 0; public GameObject kongtou_explosion_prefab; [SerializeField] private Vector3 startPosition; // 初始位置 [SerializeField] private Vector3 endPosition; // 下落位置 [SerializeField] private float duration = 5.0f; // 下落时间 /// /// 落地需要隐藏的节点 /// public GameObject[] hideNodes; private Transform _transform; [Server] public virtual void OnSpawn(EnemyType type, int lvl) { base.OnSpawn(); _transform = transform; this.type = type; this.lvl = lvl; EnemyInfo enemyInfo = GameManager.Ins.EnemyInfos[type][lvl]; speed = enemyInfo.Speed; health = enemyInfo.Hp; originHealth = enemyInfo.Hp; startPosition = transform.position; endPosition = new Vector3(transform.position.x, 0, transform.position.z); Fall(); } public void Fall() { //模拟降落伞运动 transform.DOJump(endPosition, 1.0f, 1, duration).SetEase(Ease.Linear) .OnComplete(() => { for (int i = 0; i < hideNodes.Length; i++) { hideNodes[i].SetActive(false); } CoroutineTaskManager.Instance.WaitSecondTodo(() => { if (_transform != null) { Vector3 newEndPosition = endPosition + Vector3.down * 5.0f; // 示例:向下移动 10 个单位 _transform.DOJump(newEndPosition, 1.0f, 1, duration).SetEase(Ease.Linear) .OnComplete(() => { NetworkServer.Destroy(_transform.gameObject); }); } }, 2F); }); } public void CreatEexplosion() { GameObject explosion = Instantiate(kongtou_explosion_prefab); NetworkServer.Spawn(explosion); explosion.transform.position = transform.position; CoroutineTaskManager.Instance.WaitSecondTodo(() => { NetworkServer.Destroy(explosion); }, 2F); } }