Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Places the prefab by instantiating it at a given location on the map.
- /// Modified to work over X/Y axis. Disregards topDown variable from ProDManager.
- /// Added layer argument.
- /// </summary>
- /// <param name='prefab'>
- /// The prefab.
- /// </param>
- /// <param name='map'>
- /// The map which the tile belongs to.
- /// </param>
- /// <param name='address'>
- /// The adress of the tile in the map.
- /// </param>
- /// <param name='orientation'>
- /// The orientation of the tile.
- /// </param>
- /// <param name='layer'>
- /// Where on the Z axis the prefab will be placed.
- /// </param>
- public void PlacePrefab(GameObject prefab, Map map, Address address, string[] orientation, float layer)
- {
- if(prefab == null) {
- Debug.LogError("Null is not a valid prefab for placement.");
- return;
- }
- // Setup variables
- float prefab_X = 0;
- float prefab_Y = 0;
- float prefab_Z = layer;
- // Location in worldMap
- prefab_X = map.addressOnWorldMap.x * map.size_X * ProDManager.Instance.tileSpacingX;
- prefab_Y = map.addressOnWorldMap.y * map.size_Y * ProDManager.Instance.tileSpacingY;
- // Location in Map
- prefab_X += address.x * ProDManager.Instance.tileSpacingX; // Default tileSpacingX is 1
- prefab_Y += address.y * ProDManager.Instance.tileSpacingY; // Default tileSpacingY is 1
- prefab_Z += prefab.transform.position.z; // This adds the Z position of the prefab to prefab_Z
- GameObject cellGO = (GameObject) Instantiate(prefab, new Vector3(prefab_X, prefab_Y, prefab_Z), prefab.transform.rotation);
- // Re-parent the instantiated object. This is expensive, so only do it if GroupTiles is enabled
- if (groupTiles) {
- cellGO.transform.parent = this.parentObject.transform;
- }
- allPrefabs.Add(cellGO.gameObject);
- return;
- }
- /// <summary>
- /// Get the layer the prefab should go on. The layer modifies where on the Z axis the prefab is placed.
- /// </summary>
- /// <returns>
- /// Z-axis position as a float
- /// </returns>
- /// <param name='type'>
- /// The type of tile
- /// </param>
- public float GetLayer( string type )
- {
- // Default values for layers
- float levelLayer = 10;
- float objectLayer = 8;
- float sceneryLayer = 6;
- float shadowLayer = 4;
- float itemLayer = 2;
- float characterLayer = 0;
- if(type == "Abyss") {
- return levelLayer;
- } else if(type == "Wall") {
- return levelLayer;
- } else if (type == "Path") {
- return levelLayer;
- } else if (type == "Door") {
- return objectLayer;
- } else if (type == "Entrance" || type == "Exit") {
- return objectLayer;
- }
- // Default return
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement