public void SetTileSize(TexturePack texturePack) { TileSize = texturePack.GetSpriteSize(); TileSize *= 0.97f; // Reduces chance that lines appear between sprites. }
/// <summary> /// Generates the environment with specified seed. If you pass same value for seed it will generate same environment. /// </summary> /// <param name="seed">Seed.</param> /// <param name="firstLevel">If set to <c>true</c> then player speech is started.</param> public void GenerateWithSeed(int seed, bool firstLevel) { if (parent == null) { parent = new GameObject("Cells"); } if (!nodeClusterManager) { nodeClusterManager = GetComponent <NodeClusterManager>(); } emptyFloorNodes.Clear(); Random.InitState(seed); var texturePacks = GetEnabledTexturePacks(); texturePack = texturePacks[Random.Range(0, texturePacks.Count)]; Utilities.instance.SetTileSize(texturePack); Vector2 txtureSize = texturePack.GetSpriteSize(); minDistanceBetweenStartAndEnd = ((GridSize.width * txtureSize.x) + (GridSize.height * txtureSize.y)) * 0.3f; float beginGeneratingTime = Time.realtimeSinceStartup; if (Utilities.instance.IsDebug) { Debug.Log("Destroying old environment if present"); } DestroyEnvironment(); if (Utilities.instance.IsDebug) { Debug.Log("Generating environment"); } InitialiseEnvironment(); for (int step = 0; step < NumberOfTransistionSteps; step++) { if (Utilities.instance.IsDebug) { Debug.Log("Performing transition step: " + (step + 1)); } PerformTransistionStep(); } if (Utilities.instance.IsDebug) { Debug.Log("Identifying clusters"); } // Identify clusters so they can be connected using Path manager nodeClusterManager.IdentifyClusters(Grid, GridSize); if (IsConnectedEnvironment) { nodeClusterManager.ConnectClusters(); // Need to re-identify main cavern to place enter and exit nodeClusterManager.IdentifyClusters(Grid, GridSize); } RemoveExtraneous(); // Must be called before floor cells are cached. nodeClusterManager.CalculateMainCluster(); CacheFloorCells(); if (Utilities.instance.IsDebug) { Debug.Log("Creating tiles"); } GenerateEnvironment(); if (Utilities.instance.IsDebug) { Debug.Log("Placing Entrance and Exit"); } PlaceEntranceAndExit(); BuildExterior(); if (firstLevel) { Events.instance.Raise(new LevelGeneratedSpeechRequired()); } else { Events.instance.Raise(new LevelGeneratedEvent()); } if (Utilities.instance.IsDebug) { Debug.Log("Generated environment in " + (Time.realtimeSinceStartup - beginGeneratingTime) + " seconds"); } }