public TerrainInfo(TerrainBlueprintType terrainBlueprintType, TerrainGroundStyle terrainGroundStyle, float terrainGroundSegmentLength) { this.terrainBlueprintType = terrainBlueprintType; this.terrainType = TerrainType.Ground; this.terrainGroundStyle = terrainGroundStyle; this.terrainGroundSegmentLength = terrainGroundSegmentLength; }
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); }
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(); } }