Esempio n. 1
0
    void ReadFile(string vFileName)
    {
        List <MyFloat> vipts = new List <MyFloat>();

        string     path = ("Assets/Resources/" + vFileName);
        FileStream fs   = new FileStream(path, FileMode.Open);

        string content = "";

        using (StreamReader reader = new StreamReader(fs, true))
        {
            content = reader.ReadToEnd();
        }
        string[] lines = content.Split('\n');
        for (int i = 0; i < lines.Length; ++i)
        {
            if (lines[i].Length < 3)
            {
                continue;
            }
            string[] nums = lines[i].Split(',');
            for (int j = 0; j < nums.Length; ++j)
            {
                //Debug.Log ("iteration number: " + j + " and num: " + nums[j] + " length of nums: " + nums[j].Length);
                if (nums[j].Length == 0)
                {
                    break;
                }
                if (nums[j].Substring(0, 1).Equals(" "))
                {
                    nums[j] = nums[j].Substring(1);
                }
                if (nums[j].Length > 0)
                {
                    vipts.Add(new MyFloat(float.Parse(nums[j])));
                }
            }
        }
        polys = new List <Poly>();
        float[] ipts;
        ipts = new float[vipts.Count];
        println("loaded " + vipts.Count + " points");
        for (int i = 0; i < vipts.Count; ++i)
        {
            ipts[i] = vipts[i].floatValue();
        }

        for (int i = 0; i < vipts.Count;)
        {
            int  nbrSides = (int)ipts[i++];
            Poly poly     = new Poly(nbrSides);
            for (int j = 0; j < nbrSides; ++j)
            {
                poly.AddDot(ipts[i + j * 2], ipts[i + j * 2 + 1]);
            }
            i += nbrSides * 2;
            polys.Add(poly);
        }
        println("loaded " + polys.Count + " polys");
        dxs = (width - lm * 2) / (float)(maxx - minx);
        dys = (height - tm * 2) / (float)(maxy - miny);
    }