Exemplo n.º 1
0
 //反解析设置层和子物体
 public void SetLayerAndChild(UnityTreeModel parent)
 {
     try {
         List <String> strs = FindAllValueByStr(parent.Name);
         if (strs.Count <= 0)
         {
             return;
         }
         else
         {
             for (int i = 0; i < strs.Count; i++)
             {
                 UnityTreeModel model = new UnityTreeModel();
                 model.childs = new List <UnityTreeModel>();
                 model.Name   = strs[i];
                 if (objWithLayer.ContainsKey(model.Name))
                 {
                     model.layer = objWithLayer[model.Name];
                 }
                 parent.childs.Add(model);
                 model.parent = parent;
                 SetLayerAndChild(model);
             }
         }
     }
     catch (Exception ex)
     { }
 }
Exemplo n.º 2
0
        public override void DeSerializeObject(string message)
        {
            //清空objWithParent和objWithLayer
            objWithParent.Clear();
            objWithLayer.Clear();

            //先解析特殊数据和objWithParent和objWithLayer
            String[] strs = message.Split(new String[] { "%" }, StringSplitOptions.RemoveEmptyEntries);
            if (strs.Length < 3)
            {
                return;
            }
            //特殊处理
            UnityTreeModel treeModel = MyUnityLayer.UnityLayerModel;

            String[] specialStr = strs[0].Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            treeModel.Name  = specialStr[0];
            treeModel.layer = int.Parse(specialStr[1]);


            //第一个是父子关系
            String[] parentRealtive = strs[1].Split(new String[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < parentRealtive.Length; i++)
            {
                String[] twoParams = parentRealtive[i].Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                if (twoParams.Length >= 2)
                {
                    if (!objWithParent.ContainsKey(twoParams[0]))
                    {
                        objWithParent.Add(twoParams[0], twoParams[1]);
                    }
                }
                else
                {
                    return;
                }
            }
            //第二个是节点关系
            String[] layerRealtive = strs[2].Split(new String[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < layerRealtive.Length; i++)
            {
                if ((layerRealtive[i].StartsWith("(") || (layerRealtive[i].StartsWith(")"))))
                {
                    continue;
                }
                String[] twoParams = layerRealtive[i].Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                if (twoParams.Length >= 2)
                {
                    if (!objWithLayer.ContainsKey(twoParams[0]))
                    {
                        objWithLayer.Add(twoParams[0], int.Parse(twoParams[1]));
                    }
                }
                else
                {
                    return;
                }
            }

            //开始填充
            SetLayerAndChild(treeModel);
        }