Пример #1
0
    // 寻路找怪处理
    void FindEnamyTick()
    {
        if (m_bNotEnamyNpcFlag != 0)
        {
            return;
        }
        //如果有目标名字则寻找该目标,进行交互
        if (m_Path.AutoSearchTargetName != "")
        {
            Obj_Character obj = Singleton <ObjManager> .GetInstance().FindObjCharacterInSceneByName(m_Path.AutoSearchTargetName);

            if (obj && obj.ObjType == Games.GlobeDefine.GameDefine_Globe.OBJ_TYPE.OBJ_NPC)
            {
                Obj_NPC objNpc = obj as Obj_NPC;
                //根据目标NPC的势力确认是对话还是攻击
                if (Reputation.IsEnemy(objNpc) || Reputation.IsNeutral(objNpc))
                {
                    Singleton <ObjManager> .GetInstance().MainPlayer.StopMove();

                    m_Path.AutoSearchPosCache.Clear();
                    m_Path.ResetPath();
                    IsAutoSearching = false;
                    m_EndPointCache.Clean();

                    //如果是地方NPC,则开始攻击
                    Singleton <ObjManager> .GetInstance().MainPlayer.OnSelectTarget(objNpc.gameObject);

                    Singleton <ObjManager> .GetInstance().MainPlayer.OnEnterCombat(objNpc.GetComponent <Obj_Character>());

                    m_bNotEnamyNpcFlag = 1;

                    // 杀怪任务寻路结束,如果没在自动战斗状态,则进入自动战斗
                    Obj_MainPlayer mainPlayer = Singleton <ObjManager> .GetInstance().MainPlayer;

                    if (null != mainPlayer && !mainPlayer.GetAutoCombatState() && Singleton <ObjManager> .Instance.MainPlayer.IsOpenCabalAuto)
                    {
                        mainPlayer.EnterAutoCombat();
                        GameManager.gameManager.MissionManager.MissionAutoCombat = true;
                    }
                }
                else
                {
                    m_bNotEnamyNpcFlag = 2;
                    return;
                }
            }
        }
    }
Пример #2
0
    //初始化
    void Awake()
    {
        m_Path = new AutoSearchPath();
        m_Path.ResetPath();

        m_bIsAutoSearching = false;

        m_EndPointCache = new AutoSearchPoint();
        //InitMapConnectPath();
    }
    /// <summary>
    /// 重计算路径
    /// </summary>
    /// <returns><c>true</c>, if path was calculated, <c>false</c> otherwise.</returns>
    private bool CalculatePath()
    {
        if (null == m_mainPlayer)
        {
            return(false);
        }
        m_fReCalcPathtimer = m_fReCalcPathInterval;
        if (m_mainPlayer.NavAgent == null || m_mainPlayer.NavAgent.enabled == false)
        {
            return(false);
        }
        // navMeshAgent寻路的当前场景目标点
        Vector3 currentSceneDestination = Vector3.zero;

        // 如果目标点在当前场景
        if (m_Destination.SceneID == GameManager.gameManager.RunningScene)
        {
            currentSceneDestination = new Vector3(m_Destination.PosX, 0, m_Destination.PosZ);
            currentSceneDestination = ActiveScene.GetTerrainPosition(currentSceneDestination);
            // 判断是否已经到了目标点
            Vector3 playerPos   = m_mainPlayer.Position;
            float   distanceSqr = (playerPos.x - currentSceneDestination.x) * (playerPos.x - currentSceneDestination.x) +
                                  (playerPos.y - currentSceneDestination.y) * (playerPos.y - currentSceneDestination.y) +
                                  (playerPos.z - currentSceneDestination.z) * (playerPos.z - currentSceneDestination.z);
            if (distanceSqr < m_fCornerReachCheckDistanceSqr)
            {
                return(false);
            }
        }
        else
        {
            // todo
            AutoSearchPoint startPoint = AutoSearchPoint.MakePoint(m_mainPlayer.gameObject);

            m_Path.ResetPath();
            if (GameManager.gameManager.AutoSearch.FindPath(startPoint, m_Destination, ref m_Path))
            {
            }
            return(false);
        }

        // 利用NavMeshAgent寻得路径
        if (m_mainPlayer.NavAgent.CalculatePath(currentSceneDestination, m_NavPath))
        {
            m_NavPathCorners = m_NavPath.corners;
            // 第0个点是当前位置
            m_nNextCornerIdx = 1;
            return(true);
        }
        else
        {
            CancelGuide();
            return(false);
        }
    }