示例#1
0
    //protected void Draw(InterfaceTerrainType interfaceTerrainType, int terrainStyle) {
    protected void Draw(InterfaceTerrainInfo interfaceTerrainInfo)
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (editorController.MouseClaim(editorInterfaceKeyboard.gameObject))
            {
                drawStage = 1;
                Vector3 m = editorController.GetMousePos();
                drawPoints    = new Vector3[2];
                drawPoints[0] = m;
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            if (drawStage == 1)
            {
                drawStage = 0;
                Vector3 m = editorController.GetMousePos();
                drawPoints[1] = m;

                if ((drawPoints[0] - drawPoints[1]).magnitude > 2f)
                {
                    TerrainInfo        terrainInfo        = InterfaceTerrainInfoToTerrainInfo(interfaceTerrainInfo);
                    TerrainObjectMaker terrainObjectMaker = new TerrainObjectMaker(terrainInfo);

                    Vector3 partPointsDiff = drawPoints[1] - drawPoints[0];
                    switch (terrainInfo.terrainBlueprintType)
                    {
                    case TerrainBlueprintType.CurveBezierCubic:
                        terrainObjectMaker.AddNode(drawPoints[0]);
                        terrainObjectMaker.AddNode(drawPoints[0] + partPointsDiff * 0.25f);
                        terrainObjectMaker.AddNode(drawPoints[0] + partPointsDiff * 0.75f);
                        terrainObjectMaker.AddNode(drawPoints[1]);
                        break;

                    case TerrainBlueprintType.CurveCircularArc:
                        terrainObjectMaker.AddNode(drawPoints[0]);
                        terrainObjectMaker.AddNode(drawPoints[0] + partPointsDiff * 0.5f);
                        terrainObjectMaker.AddNode(drawPoints[1]);
                        break;

                    case TerrainBlueprintType.StraightLine:
                        terrainObjectMaker.AddNode(drawPoints[0]);
                        terrainObjectMaker.AddNode(drawPoints[1]);
                        break;
                    }

                    terrainObjectMaker.SetIsEditable(true);

                    terrainObjectMaker.CreateTerrain();
                }

                editorController.MouseReleaseNextFrame(editorInterfaceKeyboard.gameObject);
            }
        }
    }
示例#2
0
    void GenerateLevelFromString(string levelString, bool edit)
    {
        Debug.Log("Generating level from levelString: " + levelString);

        LevelDataRead levelData = new LevelDataRead(levelString);

        //TODO: Generate level from levelData

        // 1) Read version

        string version = levelData.ReadString();

        Debug.Log("Version is: " + version);

        // 2) Read how many terrains there are
        int numTerrains = levelData.ReadInt();

        for (int t = 0; t < numTerrains; t++)
        {
            // Read type
            TerrainBlueprintType type = (TerrainBlueprintType)levelData.ReadInt();

            // Read style
            TerrainGroundStyle style = (TerrainGroundStyle)levelData.ReadInt();

            // Read segment length
            float segmentLength = levelData.ReadFloat();

            TerrainInfo        terrainInfo        = new TerrainInfo(type, style, segmentLength);
            TerrainObjectMaker terrainObjectMaker = new TerrainObjectMaker(terrainInfo);

            for (int i = 0; i < terrainObjectMaker.GetNodeAmount(); i++)
            {
                terrainObjectMaker.AddNode((Vector3)levelData.ReadVector2());
            }

            terrainObjectMaker.SetIsEditable(edit);
            terrainObjectMaker.CreateTerrain();
        }

        // 3) Read how many rollers there are
        int numRollers = levelData.ReadInt();

        for (int t = 0; t < numRollers; t++)
        {
            // Read type
            TerrainBlueprintType type = (TerrainBlueprintType)levelData.ReadInt();

            // Read style
            TerrainRollerStyle style = (TerrainRollerStyle)levelData.ReadInt();
            float spacing            = levelData.ReadFloat();
            bool  isFixed            = levelData.ReadBool();
            float speed = levelData.ReadFloat();

            TerrainInfo        terrainInfo        = new TerrainInfo(type, style, spacing, isFixed, speed);
            TerrainObjectMaker terrainObjectMaker = new TerrainObjectMaker(terrainInfo);

            for (int i = 0; i < terrainObjectMaker.GetNodeAmount(); i++)
            {
                terrainObjectMaker.AddNode((Vector3)levelData.ReadVector2());
            }

            terrainObjectMaker.SetIsEditable(edit);
            terrainObjectMaker.CreateTerrain();
        }
    }