示例#1
0
    static void Main(string[] args)
    {
        var env = new Env();

        env.Test();

        var data = new xx.Data();
        var oh   = new xx.ObjectHelper();
        var dw   = new xx.DataWriter(data, oh);
        var L    = new xx.List <int>();

        L.Add(1);
        L.Add(2);
        dw.Write(L);
        Console.WriteLine(oh.ToString(data));
        Console.ReadLine();
        return;
    }
示例#2
0
    public static void Fill()
    {
        // 得到 input\ 文件列表
        var fileNames = Directory.GetFiles(Program.inputPath);

        // 找出 *.plist 用于生成 SpriteFrame
        var fns = fileNames.Where(fn => fn.EndsWith(".plist"));

        foreach (var fn in fns)
        {
            var fs = GetFrames(fn);
            foreach (var f in fs)
            {
                var sf = new PKG.CatchFish.Configs.SpriteFrame();
                if (Program.frames.ContainsKey(f))
                {
                    throw new System.Exception("发现重复的帧名:" + f);
                }
                Program.frames[f] = sf;
                sf.frameName      = f;
                sf.plistName      = fn.Substring(Program.inputPath.Length + 1); // 移除目录路径部分. 只留下文件名
            }
        }

        // 找出 *.physics.xml 转为物理顶点
        fns = fileNames.Where(fn => fn.EndsWith(".physics.xml"));
        foreach (var fn in fns)
        {
            var bodydef = Physics.FromXML(fn);
            foreach (var body in bodydef.Bodies.Body)
            {
                if (!Program.frames.ContainsKey(body.Name))
                {
                    throw new System.Exception("未找到与物理帧名相同的帧:" + body.Name);
                }
                if (Program.fishFrames.ContainsKey(body.Name))
                {
                    throw new System.Exception("发现重复创建的鱼帧名:" + body.Name);
                }

                var ff = new PKG.CatchFish.Configs.FishSpriteFrame();
                Program.fishFrames[body.Name] = ff;
                ff.frame            = Program.frames[body.Name];
                ff.physics          = new PKG.CatchFish.Configs.Physics();
                ff.physics.polygons = new xx.List <xx.List <xx.Pos> >();
                foreach (var fixture in body.Fixture)
                {
                    foreach (var polygon in fixture.Polygon)
                    {
                        var vs = new xx.List <xx.Pos>();
                        foreach (var vertex in polygon.Vertex)
                        {
                            vs.Add(new xx.Pos {
                                x = (float)vertex.X, y = (float)-vertex.Y
                            });                                                               // y 值反向
                        }
                        ff.physics.polygons.Add(vs);
                    }
                }
            }
        }

        // 找出 *.lockpointers.xml 转为 首选锁定点, 锁定线
        fns = fileNames.Where(fn => fn.EndsWith(".lockpointers.xml"));
        foreach (var fn in fns)
        {
            var bodydef = Physics.FromXML(fn);
            foreach (var body in bodydef.Bodies.Body)
            {
                if (!Program.fishFrames.ContainsKey(body.Name))
                {
                    throw new System.Exception("未找到鱼帧:" + body.Name);
                }
                var ff = Program.fishFrames[body.Name];
                if (ff.lockPoints != null)
                {
                    throw new System.Exception("重复创建的锁定线 位于鱼帧:" + body.Name);
                }
                ff.lockPoints = new xx.List <xx.Pos>();

                foreach (var fixture in body.Fixture)
                {
                    if (fixture.Polygon.Count == 0)
                    {
                        throw new System.Exception("未找到 锁定线 数据 位于鱼帧:" + body.Name);
                    }
                    foreach (var polygon in fixture.Polygon)
                    {
                        if (polygon.Vertex.Count == 0)
                        {
                            throw new System.Exception("未找到 锁定线 数据 位于鱼帧:" + body.Name);
                        }
                        foreach (var vertex in polygon.Vertex)
                        {
                            ff.lockPoints.Add(new xx.Pos {
                                x = (float)vertex.X, y = (float)-vertex.Y
                            });                                                                          // y 值反向
                        }
                    }
                }
            }
        }

        // 找出 *.lockpointer.xml 转为 首选锁定点
        fns = fileNames.Where(fn => fn.EndsWith(".lockpointer.xml"));
        foreach (var fn in fns)
        {
            var bodydef = Physics.FromXML(fn);
            foreach (var body in bodydef.Bodies.Body)
            {
                if (!Program.fishFrames.ContainsKey(body.Name))
                {
                    throw new System.Exception("未找到鱼帧:" + body.Name);
                }
                var ff = Program.fishFrames[body.Name];
                if (ff.lockPoint.x != 0 || ff.lockPoint.y != 0)
                {
                    throw new System.Exception("重复创建的 首选锁定点 位于鱼帧:" + body.Name);
                }

                foreach (var fixture in body.Fixture)
                {
                    if (fixture.Circle.Count == 0)
                    {
                        throw new System.Exception("未找到 首选锁定点 数据 位于鱼帧:" + body.Name);
                    }
                    if (fixture.Circle.Count > 1)
                    {
                        throw new System.Exception("首选锁定点 数据过多 位于鱼帧:" + body.Name);
                    }

                    var circle = fixture.Circle[0];
                    ff.lockPoint = (new xx.Pos {
                        x = (float)circle.X, y = (float)-circle.Y
                    });                                                                        // y 值反向
                }
            }
        }
    }