示例#1
0
 //注册一个游戏实体
 public void Register(QObj qObj, Transform transform)
 {
     qObj.SetID(++cnt);            //设置ID
     EntityMap.Add(qObj.id, qObj); //添加到字典中
     TransfromMap.Add(qObj.id, transform);
     quadTree.AddObj(qObj);        //添加到树中
 }
示例#2
0
 public void IsHere(QObj target)
 {
     //判断是否包含在矩形范围内
     if (rect.IsInclude(target.rect))
     {
         //如果包含,就查出可不可以添加到子节点里
         if (childs == null)
         {
             return;
         }
         int index = GetIndex(target);
         if (index >= 0)
         {
             if (objs.Count > 0)
             {
                 for (int i = objs.Count - 1; i >= 0; i--)
                 {
                     if (target.id == objs[i].id)
                     {
                         childs[index].AddObj(objs[i]); //添加到子节点
                         objs.Remove(objs[i]);          //从自身移除
                         break;
                     }
                 }
             }
         }
     }
     else//不在矩形范围内 说明物体可能移动出去了
     {
         if (objs.Count > 0)
         {
             for (int i = objs.Count - 1; i >= 0; i--)
             {
                 if (target.id == objs[i].id) //尝试找到是不是在自身的管理物体列表里 如果存在 那么的确是从自身范围移动出去的
                 {
                     objs.Remove(objs[i]);    //移除
                     if (father != null)
                     {
                         father.AddObj(target);//添加到父物体中 调用AddObj的时候 会自动添加到父物体对应的子节点里
                     }
                     break;
                 }
             }
         }
     }
 }