Ejemplo n.º 1
0
        public override void Execute()
        {
            MYXZEntity entity = new MYXZEntity(Npc, 2);

            entity.RegisterObserver(AOIInfoModel.Update);

            entity.UpdatePosition();
            int mark = MYXZTimer.Instance.AddTimer(entity.UpdatePosition, Setting.AOI.UPDATE_RATE, -1);

            AOIInfoModel.AddEntityUpdateMark(entity, mark);
            MapModel.AddEntity(Npc.TargetGameObject, entity);
        }
Ejemplo n.º 2
0
 private void RefreshEntityInterests(MYXZEntity entity, EntityCollection <MYXZGrid> enumerable)
 {
     for (int x = entity.LocatedGridPosition.x - entity.InterstRadius;
          x < 2 * entity.InterstRadius; x++) //正方形的感兴趣范围
     {
         for (int y = entity.LocatedGridPosition.y - entity.InterstRadius;
              y < 2 * entity.InterstRadius; y++)
         {
             Vector2Int pos = new Vector2Int(x, y);
             if (AOIInfoModel.Contains(pos)) //如果这个pos在当前地图是合法的
             {
                 enumerable.Add(AOIInfoModel.AllGrids[pos]);
             }
         }
     }
 }
Ejemplo n.º 3
0
        public override void Execute()
        {
            Player.BaseSpeed    = 5;
            Player.TalkDistance = 5;

            PlayerModel.CurrentPlayer = Player;

            MYXZEntity entity = new MYXZEntity(Player, Setting.AOI.PLAYER_INTEREST_RADIUS);

            entity.RegisterObserver(AOIModel.Update);                                                   //当Entity的AOIPosition发生变化时会通知AOIModel

            entity.UpdatePosition();                                                                    //初始化调用一次
            int mark = MYXZTimer.Instance.AddTimer(entity.UpdatePosition, Setting.AOI.UPDATE_RATE, -1); //每隔一段时间更新一次坐标信息

            AOIModel.AddEntityUpdateMark(entity, mark);
            MapModel.AddEntity(Player.TargetGameObject, entity);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 当这个AOIInfoModel所管理的MYXZEntity的AOI坐标发生变化时,将会触发此函数
        /// </summary>
        /// <param name="sender">Entity</param>
        /// <param name="args">这个Entity之前所在的坐标</param>
        public void Update(IObservable <Vector2Int> sender, Vector2Int args)
        {
            MYXZEntity entity = (MYXZEntity)sender;

            if (AllGrids.ContainsKey(args))          //如果这个entity之前存在于此Model中
            {
                if (AllGrids[args].Contains(entity)) //移除
                {
                    AllGrids[args].Remove(entity);
                }
            }

            if (!AllGrids.ContainsKey(entity.LocatedGridPosition))  //
            {
                DebugHelper.Log("正在访问不存在的Grid" + entity.LocatedGridPosition, DebugType.Error);
                return;
            }

            AllGrids[entity.LocatedGridPosition].Add(entity);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 采用迭代器的方式来返回感兴趣物体列表
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public IEnumerable <MYXZEntity> InterestEntitys(MYXZEntity entity)
        {
            //采用返回迭代器的方式来返回相较List可以免去频繁查询下的GC

            if (entity.IsDirty)    //当Entity的AOI坐标发生变化后会被标记为Dirty,此后第一次调用此方法需要更新信息
            {
                EntityCollection <MYXZGrid> entityInterestEnumerable;
                if (m_entityInterests.ContainsKey(entity))  //如果已经创建过此entity的感兴趣物体迭代器
                {
                    entityInterestEnumerable = m_entityInterests[entity] as EntityCollection <MYXZGrid>;
                    entityInterestEnumerable.Clear();
                    RefreshEntityInterests(entity, entityInterestEnumerable);
                }
                else
                {
                    entityInterestEnumerable = new EntityCollection <MYXZGrid>();
                    RefreshEntityInterests(entity, entityInterestEnumerable);
                    m_entityInterests.Add(entity, entityInterestEnumerable);
                }
            }

            return(m_entityInterests[entity]);
        }
Ejemplo n.º 6
0
 public void AddEntityUpdateMark(MYXZEntity entity, int mark)
 {
     this.m_entityUpdateMark.Add(entity, mark);
 }
Ejemplo n.º 7
0
 public void AddEntity(GameObject go, MYXZEntity entity)
 {
     m_gameObject2Entity.Add(go, entity);
 }