Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.53 KB | None | 0 0
  1. /// <summary>
  2. /// Places the prefab by instantiating it at a given location on the map.
  3. /// Modified to work over X/Y axis. Disregards topDown variable from ProDManager.
  4. /// Added layer argument.
  5. /// </summary>
  6. /// <param name='prefab'>
  7. /// The prefab.
  8. /// </param>
  9. /// <param name='map'>
  10. /// The map which the tile belongs to.
  11. /// </param>
  12. /// <param name='address'>
  13. /// The adress of the tile in the map.
  14. /// </param>
  15. /// <param name='orientation'>
  16. /// The orientation of the tile.
  17. /// </param>
  18. /// <param name='layer'>
  19. /// Where on the Z axis the prefab will be placed.
  20. /// </param>
  21. public void PlacePrefab(GameObject prefab, Map map, Address address, string[] orientation, float layer)
  22. {
  23.     if(prefab == null) {
  24.         Debug.LogError("Null is not a valid prefab for placement.");
  25.         return;
  26.     }
  27.    
  28.     // Setup variables
  29.     float prefab_X = 0;
  30.     float prefab_Y = 0;
  31.     float prefab_Z = layer;        
  32.    
  33.     // Location in worldMap
  34.     prefab_X = map.addressOnWorldMap.x * map.size_X * ProDManager.Instance.tileSpacingX;
  35.     prefab_Y = map.addressOnWorldMap.y * map.size_Y * ProDManager.Instance.tileSpacingY;
  36.    
  37.     // Location in Map
  38.     prefab_X += address.x * ProDManager.Instance.tileSpacingX; // Default tileSpacingX is 1
  39.     prefab_Y += address.y * ProDManager.Instance.tileSpacingY; // Default tileSpacingY is 1
  40.     prefab_Z += prefab.transform.position.z; // This adds the Z position of the prefab to prefab_Z
  41.    
  42.     GameObject cellGO = (GameObject) Instantiate(prefab, new Vector3(prefab_X, prefab_Y, prefab_Z), prefab.transform.rotation);
  43.    
  44.     // Re-parent the instantiated object. This is expensive, so only do it if GroupTiles is enabled
  45.     if (groupTiles) {
  46.         cellGO.transform.parent = this.parentObject.transform;
  47.     }
  48.    
  49.     allPrefabs.Add(cellGO.gameObject);
  50.    
  51.     return;
  52. }
  53.  
  54. /// <summary>
  55. /// Get the layer the prefab should go on. The layer modifies where on the Z axis the prefab is placed.
  56. /// </summary>
  57. /// <returns>
  58. /// Z-axis position as a float
  59. /// </returns>
  60. /// <param name='type'>
  61. /// The type of tile
  62. /// </param>
  63. public float GetLayer( string type )
  64. {
  65.     // Default values for layers
  66.     float levelLayer = 10;
  67.     float objectLayer = 8;
  68.     float sceneryLayer = 6;
  69.     float shadowLayer = 4;
  70.     float itemLayer = 2;
  71.     float characterLayer = 0;
  72.  
  73.     if(type == "Abyss") {
  74.         return levelLayer;
  75.     } else if(type == "Wall") {
  76.         return levelLayer;
  77.     } else if (type == "Path") {
  78.         return levelLayer;
  79.     } else if (type == "Door") {
  80.         return objectLayer;
  81.     } else if (type == "Entrance" || type == "Exit") {
  82.         return objectLayer;
  83.     }
  84.  
  85.     // Default return
  86.     return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement