コード例 #1
0
 //分割的递归算法 这里通过生成的霍夫曼树 生成最后需要显示的数据
 void Divide(nodeData node, bool dir, Vector2 pos, float width, float height)
 {
     if ((node.leftChild == null && node.rightChild == null) || (width * height < 2500)) //如果是叶子节点 或者是面积小于某个特定值 则停止继续递归
     {
         if (node.CommandName == null)                                                   //证明不是根节点 由于面积限制而进入此逻辑的 因为在霍夫曼树中生成的中间节点是没有CommandName属性的
         {
             displayNode disNode = new displayNode();
             disNode.position = new Rect(pos.x, pos.y, width, height);
             disNode.nodeData = null;
             disNode.state    = displayNodeState.MultiNodes;
             disNode.nodeList = new List <nodeData>();
             GetMultiTypeDisplayNode(disNode, node);
             displayNodeList.Add(disNode);
         }
         else //叶子节点
         {
             displayNode disNode = new displayNode();
             disNode.position = new Rect(pos.x, pos.y, width, height);
             disNode.nodeData = node;
             disNode.state    = displayNodeState.normal;
             displayNodeList.Add(disNode);
         }
         return;
     }
     if (node.leftChild != null)
     {
         float ratio = node.leftChild.ExecutorCount * 1.0f / node.ExecutorCount;
         if (dir)
         {
             float   subWidth = width * ratio;
             Vector2 subV     = new Vector2(pos.x, pos.y);
             Divide(node.leftChild, !dir, subV, subWidth, height);
         }
         else
         {
             float   subHeight = height * ratio;
             Vector2 subV      = new Vector2(pos.x, pos.y);
             Divide(node.leftChild, !dir, subV, width, subHeight);
         }
     }
     if (node.rightChild != null)
     {
         float ratio = node.rightChild.ExecutorCount * 1.0f / node.ExecutorCount;
         if (dir)
         {
             float   subWidth = width * ratio;
             Vector2 subV     = new Vector2(pos.x + width - subWidth, pos.y);
             Divide(node.rightChild, !dir, subV, subWidth, height);
         }
         else
         {
             float   subHeight = height * ratio;
             Vector2 subV      = new Vector2(pos.x, pos.y + height - subHeight);
             Divide(node.rightChild, !dir, subV, width, subHeight);
         }
     }
 }
コード例 #2
0
 //停止递归后 该显示节点可能包含多个事件 递归将所有的事件信息保存起来 用于显示
 void GetMultiTypeDisplayNode(displayNode disNode, nodeData node)
 {
     if (node.leftChild == null && node.rightChild == null)
     {
         disNode.nodeList.Add(node);
         return;
     }
     if (node.leftChild != null)
     {
         GetMultiTypeDisplayNode(disNode, node.leftChild);
     }
     if (node.rightChild != null)
     {
         GetMultiTypeDisplayNode(disNode, node.rightChild);
     }
 }