コード例 #1
0
    public static void SaveTrack(Dictionary <string, GameObject> cones)
    {
        // Get track name
        string track_name = GameControl.track_name + ".dat";

        // Create the "savable" class to the track
        TrackData track = new TrackData();

        // Get car reference
        GameObject car_object = GameObject.Find("Car").transform.GetChild(0).gameObject;

        // Create a "savable" car
        CarData car_data = new CarData(car_object.transform.position, car_object.transform.eulerAngles);

        // Save on the track class
        track.car = car_data;

        // Loop throgh the dictionary of cones
        foreach (KeyValuePair <string, GameObject> cone in cones)
        {
            // Create a new "savable" cone class and copy the data from the cone of the game
            ConeData cone_class = new ConeData(int.Parse(cone.Value.name), cone.Value.transform.position, cone.Value.transform.eulerAngles);

            // Gambiarra to get the neighbors of the cone
            foreach (KeyValuePair <string, GameObject> cone_neighbor in cone.Value.GetComponent <neighbor>().neighbors)
            {
                cone_class.neighbor.Add(int.Parse(cone_neighbor.Value.name));
            }

            // Add the cone to the list on track class
            track.cone_list.Add(cone_class);
        }

        var path = Application.dataPath + "/../Track/";

        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }

        BinaryFormatter bf     = new BinaryFormatter();
        FileStream      stream = new FileStream(Application.dataPath + "/../Track/" + track_name, FileMode.Create);

        // Save track on file
        bf.Serialize(stream, track);
        stream.Close();
    }
コード例 #2
0
ファイル: Model.cs プロジェクト: pkwzsqsdly/HGUI
        /// <summary>
        /// 创建一个圆锥,返回顶点和三角形
        /// </summary>
        /// <param name="r">半径</param>
        /// <param name="h">高度</param>
        /// <param name="arc">三角形弧度,越小精度越高,范围0-360取整</param>
        /// <returns>顶点,三角形</returns>
        public static ConeData CreateCone(float r, float h, float arc)
        {
            int a  = (int)arc;
            int c  = 360 / a;
            int vc = c + 2;

            Vector3[] vertex = new Vector3[vc];
            int[]     tri    = new int[c * 6];
            int       o      = c;
            int       s      = 0;
            int       i      = 0;

            for (; i < c; i++)
            {
                vertex[i].x    = -MathH.Sin(s) * r;
                vertex[i].z    = MathH.Cos(s) * r;
                tri[i * 3]     = i + 1;
                tri[i * 3 + 1] = c;
                tri[i * 3 + 2] = i;
                tri[o * 3]     = i;
                tri[o * 3 + 1] = c + 1;
                tri[o * 3 + 2] = i + 1;
                o++;
                s += a;
            }
            i--;
            o--;
            vertex[c + 1].y = h;
            tri[i * 3]      = 0;
            tri[o * 3 + 2]  = 0;
            ConeData cd = new ConeData();

            cd.Vertex = vertex;
            cd.Tri    = tri;
            return(cd);
        }
コード例 #3
0
ファイル: Model.cs プロジェクト: pkwzsqsdly/HGUI
        /// <summary>
        /// 创建一个cube
        /// </summary>
        /// <param name="size">尺寸</param>
        /// <returns></returns>
        public static ConeData CreateCube(Vector3 size)
        {
            float rx = size.x * 0.5f;
            float ry = size.y * 0.5f;
            float rz = size.z * 0.5f;

            var vert = new Vector3[8];

            vert[0] = new Vector3(-rx, -ry, -rz);
            vert[1] = new Vector3(-rx, ry, -rz);
            vert[2] = new Vector3(rx, ry, -rz);
            vert[3] = new Vector3(rx, -ry, -rz);

            vert[4] = new Vector3(-rx, -ry, rz);
            vert[5] = new Vector3(-rx, ry, rz);
            vert[6] = new Vector3(rx, ry, rz);
            vert[7] = new Vector3(rx, -ry, rz);

            ConeData cd = new ConeData();

            cd.Vertex = vert;
            cd.Tri    = Cubetri;
            return(cd);
        }