Example #1
0
        void Json2Obj(MyJson.JsonNode_Object _json, GameObject _obj, DelayProcess dp)
        {
            _obj.name = _json["name"].AsString();
            var comps = _json["components"].AsList();

            if (_json.ContainsKey("id"))
            {
                var id = _json["id"].AsInt();
                dp.mapObjs[id] = _obj;
            }
            //遍历填充组件
            foreach (MyJson.JsonNode_Object c in comps)
            {
                string type = c["type"].AsString();
                this.componentParsers[type].ReadFromJson(resmgr, _obj, c, dp);
            }

            //遍历填充树
            if (_json.ContainsKey("children"))
            {
                var children = _json["children"].AsList();
                foreach (MyJson.JsonNode_Object subjson in children)
                {
                    GameObject subobj = new GameObject();
                    subobj.transform.SetParent(_obj.transform);
                    Json2Obj(subjson, subobj, dp);
                }
            }
        }
        public Component ReadFromJson(IResMgr resmgr, GameObject node, MyJson.JsonNode_Object json, DelayProcess dp)
        {
            MeshFilter c = node.GetComponent(comptype) as MeshFilter;
            if (c == null)//这就可能了
                c = node.AddComponent<MeshFilter>();

          
            var mesh = resmgr.GetMesh(json["mesh"].AsString());
            c.mesh = mesh;
            return c;
        }
        public Component ReadFromJson(IResMgr resmgr, GameObject node, MyJson.JsonNode_Object json,DelayProcess dp)
        {
            BoxCollider c = node.GetComponent(comptype) as BoxCollider;
            if (c == null)
                c = node.AddComponent<BoxCollider>();
            Debug.Log(c);
            Debug.Log("tag=" + json);
            var center = StringHelper.ToVector3(json["center"].AsString());
            var size = StringHelper.ToVector3(json["size"].AsString());

            c.center = center;
            c.size = size;
            return c;
        }
 public Component ReadFromJson(IResMgr resmgr, GameObject node, MyJson.JsonNode_Object json, DelayProcess dp)
 {
     MeshRenderer c = node.GetComponent(comptype) as MeshRenderer;
     if (c == null)//这就可能了
         c = node.AddComponent<MeshRenderer>();
     var mats = json["mats"].AsList();
     Material[] rmats = new Material[mats.Count];
     for (int i = 0; i < mats.Count; i++)
     {
         string hashname = mats[i].AsString();
         rmats[i] = resmgr.GetMat(hashname);
     }
     c.materials = rmats;
     return c;
 }
 public Component ReadFromJson(IResMgr resmgr, GameObject node, MyJson.JsonNode_Object json, DelayProcess dp)
 {
     Transform c = node.GetComponent(comptype) as Transform;
     if (c == null)//这并不可能,只是例子
         c = node.AddComponent<Transform>();
     //Debug.Log(c);
     //Debug.Log("tag=" + json);
     var move = StringHelper.ToVector3(json["transmove"].AsString());
     var euler = StringHelper.ToQuaternion(json["transquat"].AsString());
     var scale = StringHelper.ToVector3(json["transscale"].AsString());
     c.localPosition = move;
     c.localScale = scale;
     c.localRotation = euler;
     return c;
 }
        public Component ReadFromJson(IResMgr resmgr, GameObject node, MyJson.JsonNode_Object json, DelayProcess dp)
        {
            SkinnedMeshRenderer c = node.GetComponent(comptype) as SkinnedMeshRenderer;
            if (c == null)//这就可能了
                c = node.AddComponent<SkinnedMeshRenderer>();

            //mats
            var mats = json["mats"].AsList();
            Material[] rmats = new Material[mats.Count];
            for (int i = 0; i < mats.Count; i++)
            {
                string hashname = mats[i].AsString();
                rmats[i] = resmgr.GetMat(hashname);
            }
            c.materials = rmats;
            //bound
            var center = StringHelper.ToVector3(json["center"].AsString());
            var size = StringHelper.ToVector3(json["size"].AsString());

            c.localBounds = new Bounds(center, size);

            //mesh
            var mesh = resmgr.GetMesh(json["mesh"].AsString());
            c.sharedMesh = mesh;

            //延迟恢复
            if (json.ContainsKey("rootboneobj"))
            {
                dp.delayCall += () =>
                {
                    c.rootBone = dp.mapObjs[json["rootboneobj"].AsInt()].transform;
                };
            }
            if (json.ContainsKey("boneobjs"))
            {
                dp.delayCall += () =>
                  {
                      var array = json["boneobjs"] as MyJson.JsonNode_Array;
                      List<Transform> bones = new List<Transform>();
                      foreach (var b in array)
                      {
                          bones.Add(dp.mapObjs[b.AsInt()].transform);
                      }
                      c.bones = bones.ToArray();
                  };
            }
            return c;
        }
        public Component ReadFromJson(IResMgr resmgr, GameObject node, MyJson.JsonNode_Object json, DelayProcess dp)
        {
            FB.PosePlus.AniPlayer c = node.GetComponent(comptype) as FB.PosePlus.AniPlayer;
            if (c == null)//这就可能了
                c = node.AddComponent<FB.PosePlus.AniPlayer>();

            var clips = json["clips"].AsList();
            c.clips = new List<FB.PosePlus.AniClip>();
            for (int i = 0; i < clips.Count; i++)
            {
                string hashname = clips[i].AsString();
                c.clips.Add(resmgr.GetAniClip(hashname));
            }
            
            return c;
        }
Example #8
0
        public GameObject GenNode()
        {
            resmgr = new ResMgr(this);
            string treefile = null;

            foreach (var b in bufs.Keys)
            {
                if (b.Contains(".jsontree.txt"))
                {
                    treefile = System.Text.Encoding.UTF8.GetString(this.bufs[b]);
                    break;
                }
            }
            MyJson.JsonNode_Object _json = MyJson.Parse(treefile) as MyJson.JsonNode_Object;

            _obj = new GameObject();
            DelayProcess dp = new DelayProcess();

            Json2Obj(_json, _obj, dp);
            dp.Do();
            return(_obj);
        }
Example #9
0
        void Json2Obj(MyJson.JsonNode_Object _json, GameObject _obj, DelayProcess dp)
        {
            _obj.name = _json["name"].AsString();
            var comps = _json["components"].AsList();
            if (_json.ContainsKey("id"))
            {
                var id = _json["id"].AsInt();
                dp.mapObjs[id] = _obj;
            }
            //遍历填充组件
            foreach (MyJson.JsonNode_Object c in comps)
            {

                string type = c["type"].AsString();
                this.componentParsers[type].ReadFromJson(resmgr, _obj, c, dp);
            }

            //遍历填充树
            if (_json.ContainsKey("children"))
            {
                var children = _json["children"].AsList();
                foreach (MyJson.JsonNode_Object subjson in children)
                {
                    GameObject subobj = new GameObject();
                    subobj.transform.SetParent(_obj.transform);
                    Json2Obj(subjson, subobj, dp);
                }
            }

        }
Example #10
0
        public GameObject GenNode()
        {
            resmgr = new ResMgr(this);
            string treefile = null;
            foreach (var b in bufs.Keys)
            {
                if (b.Contains(".jsontree.txt"))
                {
                    treefile = System.Text.Encoding.UTF8.GetString(this.bufs[b]);
                    break;
                }
            }
            MyJson.JsonNode_Object _json = MyJson.Parse(treefile) as MyJson.JsonNode_Object;

            _obj = new GameObject();
            DelayProcess dp = new DelayProcess();
            Json2Obj(_json, _obj, dp);
            dp.Do();
            return _obj;

        }
        public Component ReadFromJson(IResMgr resmgr, GameObject node, MyJson.JsonNode_Object json, DelayProcess dp)
        {
            BoxCollider c = node.GetComponent(comptype) as BoxCollider;

            if (c == null)
            {
                c = node.AddComponent <BoxCollider>();
            }
            Debug.Log(c);
            Debug.Log("tag=" + json);
            var center = StringHelper.ToVector3(json["center"].AsString());
            var size   = StringHelper.ToVector3(json["size"].AsString());

            c.center = center;
            c.size   = size;
            return(c);
        }
Example #12
0
        public Component ReadFromJson(IResMgr resmgr, GameObject node, MyJson.JsonNode_Object json, DelayProcess dp)
        {
            FB.PosePlus.AniPlayer c = node.GetComponent(comptype) as FB.PosePlus.AniPlayer;
            if (c == null)//这就可能了
            {
                c = node.AddComponent <FB.PosePlus.AniPlayer>();
            }

            var clips = json["clips"].AsList();

            c.clips = new List <FB.PosePlus.AniClip>();
            for (int i = 0; i < clips.Count; i++)
            {
                string hashname = clips[i].AsString();
                c.clips.Add(resmgr.GetAniClip(hashname));
            }

            return(c);
        }
Example #13
0
        public Component ReadFromJson(IResMgr resmgr, GameObject node, MyJson.JsonNode_Object json, DelayProcess dp)
        {
            Transform c = node.GetComponent(comptype) as Transform;

            if (c == null)//这并不可能,只是例子
            {
                c = node.AddComponent <Transform>();
            }
            //Debug.Log(c);
            //Debug.Log("tag=" + json);
            var move  = StringHelper.ToVector3(json["transmove"].AsString());
            var euler = StringHelper.ToQuaternion(json["transquat"].AsString());
            var scale = StringHelper.ToVector3(json["transscale"].AsString());

            c.localPosition = move;
            c.localScale    = scale;
            c.localRotation = euler;
            return(c);
        }
Example #14
0
        public Component ReadFromJson(IResMgr resmgr, GameObject node, MyJson.JsonNode_Object json, DelayProcess dp)
        {
            SkinnedMeshRenderer c = node.GetComponent(comptype) as SkinnedMeshRenderer;

            if (c == null)//这就可能了
            {
                c = node.AddComponent <SkinnedMeshRenderer>();
            }

            //mats
            var mats = json["mats"].AsList();

            Material[] rmats = new Material[mats.Count];
            for (int i = 0; i < mats.Count; i++)
            {
                string hashname = mats[i].AsString();
                rmats[i] = resmgr.GetMat(hashname);
            }
            c.materials = rmats;
            //bound
            var center = StringHelper.ToVector3(json["center"].AsString());
            var size   = StringHelper.ToVector3(json["size"].AsString());

            c.localBounds = new Bounds(center, size);

            //mesh
            var mesh = resmgr.GetMesh(json["mesh"].AsString());

            c.sharedMesh = mesh;

            //延迟恢复
            if (json.ContainsKey("rootboneobj"))
            {
                dp.delayCall += () =>
                {
                    c.rootBone = dp.mapObjs[json["rootboneobj"].AsInt()].transform;
                };
            }
            if (json.ContainsKey("boneobjs"))
            {
                dp.delayCall += () =>
                {
                    var array = json["boneobjs"] as MyJson.JsonNode_Array;
                    List <Transform> bones = new List <Transform>();
                    foreach (var b in array)
                    {
                        bones.Add(dp.mapObjs[b.AsInt()].transform);
                    }
                    c.bones = bones.ToArray();
                };
            }
            return(c);
        }
Example #15
0
        public Component ReadFromJson(IResMgr resmgr, GameObject node, MyJson.JsonNode_Object json, DelayProcess dp)
        {
            MeshRenderer c = node.GetComponent(comptype) as MeshRenderer;

            if (c == null)//这就可能了
            {
                c = node.AddComponent <MeshRenderer>();
            }
            var mats = json["mats"].AsList();

            Material[] rmats = new Material[mats.Count];
            for (int i = 0; i < mats.Count; i++)
            {
                string hashname = mats[i].AsString();
                rmats[i] = resmgr.GetMat(hashname);
            }
            c.materials = rmats;
            return(c);
        }
        public Component ReadFromJson(IResMgr resmgr, GameObject node, MyJson.JsonNode_Object json, DelayProcess dp)
        {
            MeshFilter c = node.GetComponent(comptype) as MeshFilter;

            if (c == null)//这就可能了
            {
                c = node.AddComponent <MeshFilter>();
            }


            var mesh = resmgr.GetMesh(json["mesh"].AsString());

            c.mesh = mesh;
            return(c);
        }