Exemplo n.º 1
0
 /// <summary>
 /// 得到子节点
 /// </summary>
 /// <param name="name"></param>
 /// <exception cref="SimpleJsonException">该Node不是一个Object,name  is null or empty</exception>
 ///
 /// <returns></returns>
 public JsonNode this[string name]
 {
     get
     {
         if (NodeType != NodeType.Object)
         {
             throw new SimpleJsonException("该Node不是一个Object");
         }
         if (string.IsNullOrEmpty(name))
         {
             throw new SimpleJsonException(string.Format("param : name  is null or empty"));
         }
         if (NodeDic.ContainsKey(name))
         {
             return(NodeDic[name]);
         }
         return(null);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 添加子节点
        /// <p>注意:该节点是Object</p>
        /// </summary>
        /// <exception cref="SimpleJsonException">该Node不是一个Object,被添加的Node不能是ArrayElemnt,该节点已经存在子节点对应的名称了</exception>
        /// <param name="name"></param>
        /// <param name="node">子节点</param>
        public void AddSubNode(string name, JsonNode node)
        {
            if (NodeType == NodeType.Object)
            {
            }
            else
            {
                throw new SimpleJsonException("该Node不是一个Object or ArrayElementObject");
            }

            if (NodeDic.ContainsKey(name))
            {
                throw new SimpleJsonException(string.Format("该节点已经存在子节点对应的名称了:{0}", name));
            }

            if (node == null)
            {
                node          = new JsonNode();
                node.NodeType = NodeType.Value;
            }
            node.SuperNode = this;
            NodeDic.Add(name, node);
        }
Exemplo n.º 3
0
 public override void Update(GameManager game, float delta)
 {
     foreach (int entity in _entityList)
     {
         GAstarComponent astarComponent = game.Entities.GetComponentOf <GAstarComponent>(entity);
         GTransform      transform      = game.Entities.GetComponentOf <GTransform>(entity);
         Node            endNode        = NodeDic[astarComponent._goal];
         if (astarComponent._active)
         {
             openList.Enqueue(NodeDic[new Vector2((int)transform._position.x, (int)-transform._position.z)], 0);
         }
         while (astarComponent._active)
         {
             Node current = openList.Dequeue();
             for (int i = 0; i < 8; i++)
             {
                 if (current.neighbours[i].value > 0)
                 {
                     if (NodeDic.ContainsKey(new Vector2(current.neighbours[i].position.x, current.neighbours[i].position.z)))
                     {
                         Node child = NodeDic[new Vector2(current.neighbours[i].position.x, current.neighbours[i].position.z)];
                         if (child == endNode)
                         {
                             astarComponent._active = false;
                             child.jump             = current.neighbours[i].jump;
                             child.parent           = current;
                             current = endNode;
                             break;
                         }
                         if (!openList.Contains(child) && !closedList.Contains(child))
                         {
                             gameObjs[new Vector2(current.position.x, current.position.z)].renderer.material.color = Color.red;
                             float dst = Vector3.Distance(child.position, endNode.position);
                             child.jump   = current.neighbours[i].jump;
                             child.parent = current;
                             child.value  = child.parent.value + current.neighbours[i].value;
                             openList.Enqueue(child, dst + child.value);
                         }
                     }
                     else
                     {
                         Debug.Log("Did not exist " + new Vector2(current.neighbours[i].position.x, current.neighbours[i].position.z));
                     }
                 }
             }
             closedList.Add(current);
             if (!astarComponent._active)
             {
                 while (current.parent != null)
                 {
                     finalList.Add(current.position, current.jump);
                     gameObjs[new Vector2(current.position.x, current.position.z)].transform.localScale   *= 4;
                     gameObjs[new Vector2(current.position.x, current.position.z)].renderer.material.color = Color.yellow;
                     current = current.parent;
                     //astarComponent._path.Add(current.position, current.jump);
                 }
                 //Sätt ihop dessa loopar
                 astarComponent._current = finalList.Last().Key;
                 for (int i = finalList.Count - 1; i >= 0; i--)
                 {
                     //finalList[finalList.ElementAt(i - 1).Key] = finalList.ElementAt(i).Value;
                     if (finalList.ElementAt(i).Value)
                     {
                         astarComponent._path.Add(finalList.ElementAt(i).Key, false);
                         astarComponent._path[finalList.ElementAt(i + 1).Key] = true;
                         Debug.Log("Fix Jump " + finalList.ElementAt(i + 1).Key);
                     }
                     else
                     {
                         astarComponent._path.Add(finalList.ElementAt(i).Key, finalList.ElementAt(i).Value);
                     }
                 }
                 astarComponent._index = 0;
                 finalList.Clear();
                 closedList.Clear();
                 openList.Clear();
             }
         }
     }
 }