Example #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);
            }
        }
    }
Example #2
0
    protected TerrainInfo InterfaceTerrainInfoToTerrainInfo(InterfaceTerrainInfo interfaceTerrainInfo)
    {
        TerrainInfo terrainInfo;

        TerrainBlueprintType terrainBlueprintType = InterfaceTerrainToolToTerrainBlueprintType(interfaceTerrainInfo.interfaceTerrainTool);

        switch (interfaceTerrainInfo.interfaceTerrainType)
        {
        case InterfaceTerrainType.Ground:

            // Ground
            TerrainGroundStyle terrainGroundStyle = InterfaceTerrainGroundStyleToTerrainGroundStyle(interfaceTerrainInfo.interfaceTerrainGroundStyle);
            float terrainGroundSegmentLength      = InterfaceTerrainGroundGrainToTerrainSegmentLength(interfaceTerrainInfo.interfaceTerrainGroundGrain);

            terrainInfo = new TerrainInfo(terrainBlueprintType, terrainGroundStyle, terrainGroundSegmentLength);

            break;

        case InterfaceTerrainType.Roller:

            //Roller
            TerrainRollerStyle terrainRollerStyle = InterfaceTerrainRollerStyleToTerrainRollerStyle(interfaceTerrainInfo.interfaceTerrainRollerStyle);
            float terrainRollerSpacing            = InterfaceTerrainRollerSpacingToTerrainRollerSpacing(interfaceTerrainInfo.interfaceTerrainRollerSpacing);
            bool  terrainRollerFixed = InterfaceTerrainRollerRotationSpeedToTerrainRollerFixed(interfaceTerrainInfo.interfaceTerrainRollerRotationSpeed);
            float terrainRollerSpeed = InterfaceTerrainRollerRotationSpeedAndInterfaceTerrainRollerRotationToTerrainRollerSpeed(interfaceTerrainInfo.interfaceTerrainRollerRotationSpeed, interfaceTerrainInfo.interfaceTerrainRollerRotationDirection);

            terrainInfo = new TerrainInfo(terrainBlueprintType, terrainRollerStyle, terrainRollerSpacing, terrainRollerFixed, terrainRollerSpeed);

            break;

        default:
            Debug.LogWarning("Invalid InterfaceTerrainType [" + interfaceTerrainInfo.interfaceTerrainType + "]. Defaulting to InterfaceTerrainType.Ground");
            goto case InterfaceTerrainType.Ground;
        }

        return(terrainInfo);
    }