using System; using System.Collections; using System.Collections.Generic; using BehaviorDesigner.Runtime; using DragonLi.Core; using Mirror; using UnityEngine; public enum NpcType { Run, Fall, Die, Over, } public class NPC : Agent { private Collider _collider; public Collider selfCollider { get { if (_collider == null) _collider = GetComponent(); return _collider; } } public bool isUserFall; public NpcType state; public int id; public bool isOver; [Server] public virtual void OnSpawn(int curId,GameObject target,bool curIsUserFall) { base.OnSpawn(); id = curId; health = 10; originHealth = 10; aiPath.enabled = true; aiPath.maxSpeed = 3; isUserFall = curIsUserFall; // 初始设置(server) if (isServer) { state = NpcType.Run; if (aiPath != null) aiPath.enabled = true; if (rvoController != null) rvoController.enabled = true; if (selfCollider != null) selfCollider.enabled = true; // MonoSingleton.Instance.WaitSecondTodo(() => // { // ChangeState(NpcType.Fall); // }, 4f, this); } } public void ChangeState(NpcType npcType) { state = npcType; switch (state) { case NpcType.Fall: if (isUserFall) { AnimatorComponent.SetInteger("state",1); aiPath.maxSpeed = 1; } break; case NpcType.Die: AnimatorComponent.SetBool("dead",true); isOver = true; break; case NpcType.Over: isOver = true; NetworkServer.Destroy(gameObject); break; } } [ServerCallback] private void OnTriggerEnter(Collider other) { if (other.CompareTag("SafeDoor")) { ChangeState(NpcType.Over); GameManager.Ins.CreateExplosion(transform,EnemyType.Npc); } } }