Exemplo n.º 1
0
        private RVOObject[] FindAIEntity(Vector3 center, float maxdis, GameObject pg)
        {
            Collider[]       tCollider      = Physics.OverlapSphere(center, maxdis);
            List <RVOObject> tListRVOObject = new List <RVOObject> ();

            for (int i = 0; i < tCollider.Length; i++)
            {
                float dis1 = Vector3.Distance(pg.transform.position, tCollider[i].gameObject.transform.position);
                //	Debug.Log (pg.transform.position.ToString());
                if (tCollider [i].tag == AITag && dis1 > 1.0f)
                {
                    bool isFind = false;
                    for (int j = 0; j < this.mWorld.mEntityCount; j++)
                    {
                        if (isFind)
                        {
                            break;
                        }
                        BaseAIComponent bAI = mWorld.mUEntity [j].GetComponent <BaseAIComponent> ();
                        if (bAI != null)
                        {
                            float dis = Vector3.Distance(bAI.mAIRT.transform.position, tCollider[i].gameObject.transform.position);
                            if (dis < 0.5f)
                            {
                                //Debug.Log (dis1+"  "+dis);
                                RVOObject tRVOObject = new RVOObject();
                                tRVOObject.mpos      = bAI.mAIRT.transform.position;
                                tRVOObject.mvelocity = mWorld.mUEntity [j].GetComponent <AIMove> ().mDirection *mWorld.mUEntity [j].GetComponent <AIMove> ().mVelocity;
                                tListRVOObject.Add(tRVOObject);
                                isFind = true;
                            }
                        }
                        else
                        {
                            AIMove aim = mWorld.mUEntity [j].GetComponent <AIMove> ();
                            if (aim != null)
                            {
                                GameObject g   = ((SimpleAI)(mWorld.mUEntity [j])).mAIRT;
                                float      dis = Vector3.Distance(g.transform.position, tCollider[i].gameObject.transform.position);
                                if (dis < 0.5f)
                                {
                                    RVOObject tRVOObject = new RVOObject();
                                    tRVOObject.mpos      = g.transform.position;
                                    tRVOObject.mvelocity = aim.mDirection * aim.mVelocity;
                                    tListRVOObject.Add(tRVOObject);
                                    isFind = true;
                                }
                            }
                        }
                    }
                }
            }
            return(tListRVOObject.ToArray());
        }
Exemplo n.º 2
0
        private GameObject getGameObjectFromEntity(UEntity pEntity)
        {
            BaseAIComponent bAI = pEntity.GetComponent <BaseAIComponent> ();

            if (bAI != null)
            {
                return(bAI.mAIRT);
            }
            else
            {
                return(((SimpleAI)pEntity).mAIRT);
            }
        }
Exemplo n.º 3
0
        /*
         *
         * add the must component to AIEntity
         *
         */

        public override void Init()
        {
            BaseAIComponent tBAIComponent = new BaseAIComponent();

            tBAIComponent.mAITemplate = mAI;
            tBAIComponent.bornPoint   = AIPos;
            tBAIComponent.Init();
            AIMove            mAIMove            = new AIMove();
            AIAnimation       mAIAnimation       = new AIAnimation();
            HPComponent       hpc                = new HPComponent();
            AIState           aiState            = new AIState();
            AIEmotion         mEmotion           = new AIEmotion();
            AIStrategy        mAIStrategy        = new AIStrategy();
            ObstacleComponent mObstacleComponent = new ObstacleComponent();
            AIGroupState      aiGroupState       = new AIGroupState();

            this.AddComponent <BaseAIComponent> (tBAIComponent);
            this.AddComponent <AIMove> (mAIMove);
            this.AddComponent <AIAnimation> (mAIAnimation);
            this.AddComponent <HPComponent> (hpc);
            this.AddComponent <AIState> (aiState);
            this.AddComponent <AIEmotion> (mEmotion);
            this.AddComponent <AIStrategy> (mAIStrategy);
            this.AddComponent <ObstacleComponent> (mObstacleComponent);
            this.AddComponent <AIGroupState> (aiGroupState);
            this.AddComponent <LODComponent> (new LODComponent());

            mAIStrategy.Init();
            aiGroupState.Init();
            aiState.Init();
            mAIAnimation.Init();
            mEmotion.Init();

            InfluenceMapTrigger tInfluenceMapTrigger = new InfluenceMapTrigger();

            tInfluenceMapTrigger.maxInfluence = 4.0f;
            tInfluenceMapTrigger.mWhere       = "friend";
            tInfluenceMapTrigger.mGameObject  = mAI;
            tInfluenceMapTrigger.mIMComputer  = DefaultFunc.friendComputer;
            tInfluenceMapTrigger.Init();

            UEntity tEntity = new UEntity();

            tEntity.AddComponent <InfluenceMapTrigger> (tInfluenceMapTrigger);
            this.mWorld.registerEntityAfterInit(tEntity);
            AIEntity.getList().Add(this);
        }