示例#1
0
    public void Load()
    {
        if (File.Exists(Application.dataPath + "/ProceduralTracks/CurvesSavedData/" + gameObject.name + ".curve"))
        {
            ClearCurve();

            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.dataPath + "/ProceduralTracks/CurvesSavedData/" + gameObject.name + ".curve", FileMode.Open);
            BifurcationData data = (BifurcationData)bf.Deserialize(file);
            file.Close();

            if (extrudeShape == null)
            {
                extrudeShape = new ExtrudeShape();
            }

            for (int i = 0; i < data.nodesData.Length; ++i)
            {
                // Create Nodes
                Node node = CreateNode(transform.position, transform.rotation);
                node.Load(data.nodesData[i]);
            }

            planeX = data.planeX;

            // Create Splines
            CreateSpline(nodes[0], nodes[1]).ExtrudeSide(meshes[0], extrudeShape, "right", planeX);
            CreateSpline(nodes[0], nodes[2]).ExtrudeSide(meshes[1], extrudeShape, "left", planeX);
        }
        else
        {
            //Debug.Assert(true, "Data file not found");
            Create();
        }
    }
示例#2
0
    public void Save()
    {
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(Application.dataPath + "/ProceduralTracks/CurvesSavedData/" + gameObject.name + ".curve");

        BifurcationData data = new BifurcationData();

        List <NodeData> _nodesData = new List <NodeData>();

        if (nodes != null)
        {
            foreach (Node n in nodes)
            {
                _nodesData.Add(n.Serialize());
            }
            data.nodesData = _nodesData.ToArray();
        }

        data.planeX = planeX;

        //List<BezierSpline> _splinesData = new List<BezierSpline>();
        //foreach (BezierSpline b in splines)
        //{
        //    _splinesData.Add(b.Serialize());
        //}
        //data.splinesData = _splinesData.ToArray();

        bf.Serialize(file, data);
        file.Close();
    }
    public void Save()
    {
        BinaryFormatter bf = new BinaryFormatter();
        FileStream file = File.Create(Application.dataPath + "/ProceduralTracks/CurvesSavedData/" + gameObject.name + ".curve");

        BifurcationData data = new BifurcationData();

        List<NodeData> _nodesData = new List<NodeData>();
        if (nodes != null)
        {
            foreach (Node n in nodes)
            {
                _nodesData.Add(n.Serialize());
            }
            data.nodesData = _nodesData.ToArray();
        }

        List<BezierData> _splinesData = new List<BezierData>();
        foreach (BezierSpline b in splines)
        {
            _splinesData.Add(b.GetData());
        }
        data.splinesData = _splinesData.ToArray();

        data.planeX = planeX;

        bf.Serialize(file, data);
        file.Close();
    }