Exemplo n.º 1
0
        /// <summary>
        /// 将场景内的对象保存到文件
        /// </summary>
        /// <param name="uiRoot"></param>
        /// <param name="path"></param>
        public static void SavePrefab(Transform uiRoot, string path)
        {
            DataBuffer db = new DataBuffer(1024);

            db.fakeStruct = TransfromModel.LoadFromObject(uiRoot, db);
            File.WriteAllBytes(path, db.ToBytes());
        }
Exemplo n.º 2
0
        static void ReflectionObject(Transform t, object o, TransfromModel mod)
        {
            var m = o.GetType().GetField(t.name);

            if (m != null)
            {
                if (typeof(Component).IsAssignableFrom(m.FieldType))
                {
                    m.SetValue(o, t.GetComponent(m.FieldType));
                }
            }
        }
Exemplo n.º 3
0
        unsafe public override void Load(FakeStruct fake)
        {
            transfrom = *(TransfromData *)fake.ip;
            var buff = fake.buffer;

            Int16[] coms = buff.GetData(transfrom.coms) as Int16[];
            if (coms != null)
            {
                for (int i = 0; i < coms.Length; i++)
                {
                    int index = coms[i];
                    i++;
                    int type = coms[i];
                    var fs   = buff.GetData(index) as FakeStruct;
                    if (fs != null)
                    {
                        var dc = ModelManager2D.Load(type);
                        if (dc != null)
                        {
                            dc.Load(fs);
                            components.Add(dc);
                        }
                    }
                }
            }
            Int16[] chi = fake.buffer.GetData(transfrom.child) as Int16[];
            if (chi != null)
            {
                for (int i = 0; i < chi.Length; i++)
                {
                    var fs = buff.GetData(chi[i]) as FakeStruct;
                    if (fs != null)
                    {
                        TransfromModel model = new TransfromModel();
                        model.Load(fs);
                        child.Add(model);
                    }
                }
            }
            name = buff.GetData(transfrom.name) as string;
            tag  = buff.GetData(transfrom.tag) as string;
        }
Exemplo n.º 4
0
        public unsafe static PrefabAsset LoadModels(byte[] buff, string name)
        {
            DataBuffer     db    = new DataBuffer(buff);
            TransfromModel model = new TransfromModel();

            model.Load(db.fakeStruct);
            var asset = new PrefabAsset();

            asset.models = model;
            asset.name   = name;
            for (int i = 0; i < prefabAssets.Count; i++)
            {
                if (prefabAssets[i].name == name)
                {
                    prefabAssets.RemoveAt(i); break;
                }
            }
            prefabAssets.Add(asset);
            return(asset);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 使用模型数据,实例化对象
        /// </summary>
        /// <param name="mod"></param>
        /// <param name="o"></param>
        /// <param name="parent"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        public static GameObject LoadToGame(TransfromModel mod, object o, Transform parent, string filter = "mod")
        {
            if (mod == null)
            {
#if DEBUG
                Debug.Log("Mod is null");
#endif
                return(null);
            }
            if (mod.tag == filter)
            {
                return(null);
            }
            var g = CreateNew(mod.transfrom.type);
            if (g == null)
            {
#if DEBUG
                Debug.Log("Name:" + mod.name + " is null");
#endif
                return(null);
            }
            var t = g.transform;
            if (parent != null)
            {
                t.SetParent(parent);
            }
            mod.LoadToObject(g.transform);
            mod.Main = g;
            var c = mod.child;
            for (int i = 0; i < c.Count; i++)
            {
                LoadToGame(c[i], o, t, filter);
            }
            if (o != null)
            {
                ReflectionObject(t, o, mod);
            }
            return(g);
        }