Ejemplo n.º 1
0
    /// <summary>
    /// 搜索范围内的NPC
    /// </summary>
    /// <param name="range"></param>
    /// <returns></returns>
    private List <RoleInstance> SearchNPC(int range = 16, MapRoleBehavior mapRoleBehaviour = MapRoleBehavior.Enemy)
    {
        List <RoleInstance> npcList = new List <RoleInstance>();

        foreach (var role in MapRuntimeData.Instance.Roles)
        {
            //排除RoleInstance为空
            if (role == null)
            {
                continue;
            }

            //排除RoleView为空
            if (role.View == null)
            {
                continue;
            }

            //排除隐藏角色
            if (!role.View.gameObject.activeInHierarchy)
            {
                continue;
            }

            //排除其他MapRoleBehaviour
            if (role.View.m_Behavior != mapRoleBehaviour)
            {
                continue;
            }

            //排除战斗状态角色
            if (role.IsInBattle())
            {
                continue;
            }

            //排除死亡的非关键角色
            if (!role.View.m_IsKeyRole && role.IsDead())
            {
                continue;
            }

            if ((role.View.transform.position - _player.View.transform.position).magnitude < range) //附近所有角色,默认16
            {
                npcList.Add(role);
            }
        }
        return(npcList);
    }
Ejemplo n.º 2
0
 public void SetBehavior(MapRoleBehavior behavior)
 {
     m_Behavior = behavior;
 }