Exemplo n.º 1
0
        BehaveResult Tick(Tree sender)
        {
            BehaveGroup group = sender.ActiveAgent as BehaveGroup;

            if (group == null || group.Leader == null)
            {
                return(BehaveResult.Failure);
            }

            if (group.EscapeEnemy == null)
            {
                return(BehaveResult.Failure);
            }

            if (m_CurEscapeposition == Vector3.zero ||
                PEUtil.SqrMagnitudeH(group.Leader.position, m_CurEscapeposition) < 1.0f * 1.0f ||
                Time.time - m_LastRandomTime > 10.0f)
            {
                m_LastRandomTime = Time.time;

                PeTrans tr = group.Leader.GetComponent <PeTrans>();
                m_CurEscapeposition = GetEscapePosition(group, tr.position, tr.position - group.EscapeEnemy.position, 25.0f, 35.0f);
                if (m_CurEscapeposition == Vector3.zero)
                {
                    return(BehaveResult.Failure);
                }
                else
                {
                    group.MoveToPosition(m_CurEscapeposition, SpeedState.Run);
                }
            }

            return(BehaveResult.Running);
        }
Exemplo n.º 2
0
        BehaveResult Tick(Tree sender)
        {
            if (!GetData <Data>(sender, ref m_Data))
            {
                return(BehaveResult.Failure);
            }

            BehaveGroup group = sender.ActiveAgent as BehaveGroup;

            if (group == null || group.Leader == null)
            {
                return(BehaveResult.Failure);
            }

            if (group.HasAttackEnemy() || group.HasEscapeEnemy())
            {
                return(BehaveResult.Failure);
            }

            if (Time.time - m_Data.m_StartPatrolTime > m_Data.m_Time)
            {
                return(BehaveResult.Success);
            }

            if (Time.time - m_Data.m_LastSwitchTime > m_Data.m_SwitchTime)
            {
                m_Data.m_LastSwitchTime = Time.time;
                m_Data.m_SwitchTime     = Random.Range(5.0f, 10.0f);

                m_Data.m_CurrentPatrolPosition = GetPatrolPosition(sender);
                if (m_Data.m_CurrentPatrolPosition != Vector3.zero)
                {
                    group.MoveToPosition(m_Data.m_CurrentPatrolPosition, SpeedState.Walk);
                }
            }

            //if (m_Data.m_CurrentPatrolPosition != Vector3.zero)
            //{
            //    //group.Patrol(m_Data.m_CurrentPatrolPosition);
            //    foreach (PeEntity skEntity in group.Entities)
            //    {
            //        if (skEntity != null && !skEntity.IsDeath())
            //        {
            //            Motion_Move mover = skEntity.GetComponent<Motion_Move>();
            //            if (mover != null && group.Leader != null)
            //            {
            //                PeTrans tr1 = mover.GetComponent<PeTrans>();
            //                PeTrans tr2 = group.Leader.GetComponent<PeTrans>();
            //                if (tr1 != null && tr2 != null)
            //                {
            //                    if(skEntity == group.Leader)
            //                        mover.MoveTo(m_Data.m_CurrentPatrolPosition);
            //                    else
            //                    {
            //                        if(PEUtil.SqrMagnitudeH(tr1.position, tr2.position) > tr1.radius * tr1.radius * 16)
            //                        {
            //                            mover.MoveTo(m_Data.m_CurrentPatrolPosition + (tr1.position-tr2.position).normalized * tr1.radius * Random.Range(3.0f, 5.0f));
            //                        }
            //                    }
            //                }
            //            }
            //        }
            //    }
            //}

            return(BehaveResult.Running);
        }