public void SetItemsOnMapData() { // init lists MapData.itemsOnMap = new List <InventoryItemData>(); // MapData.itemsPositionOnMap = new List<PositionOnMap>(); MapData.itemsMapCoordinates = new List <MapCoordinates>(); // Loop through transforms 1 level below map (=belongs to the map) foreach (Transform childTransform in MapManager.Instance.GetParentTransformByType(GetComponent <MapItemsContainer>())) { // get map item (chest) MapItemsContainer mapItem = childTransform.GetComponent <MapItemsContainer>(); // verify if it is not null if (mapItem != null) { // loop through all items linked to this map item (chest) foreach (InventoryItem inventoryItem in mapItem.LInventoryItems) { // set item data MapData.itemsOnMap.Add(inventoryItem.InventoryItemData); // set item position //MapData.itemsPositionOnMap.Add( // new PositionOnMap // { // offsetMinX = mapItem.GetComponent<RectTransform>().offsetMin.x, // offsetMinY = mapItem.GetComponent<RectTransform>().offsetMin.y, // offsetMaxX = mapItem.GetComponent<RectTransform>().offsetMax.x, // offsetMaxY = mapItem.GetComponent<RectTransform>().offsetMax.y // } // ); // set item coordinates MapData.itemsMapCoordinates.Add(MapManager.Instance.GetCoordinatesByWorldPosition(mapItem.transform.position)); } } } }
//public MapItemsContainer CreateInventoryItemContainerOnMap(PositionOnMap positionOnMap) //{ // // create new item on map // MapItemsContainer mapItem = Instantiate(inventoryItemOnMapTemplate, MapManager.Instance.GetParentTransformByType(GetComponent<MapItemsContainer>())).GetComponent<MapItemsContainer>(); // // place item on map to original position on map // mapItem.GetComponent<RectTransform>().offsetMin = new Vector2(positionOnMap.offsetMinX, positionOnMap.offsetMinY); // mapItem.GetComponent<RectTransform>().offsetMax = new Vector2(positionOnMap.offsetMaxX, positionOnMap.offsetMaxY); // // rename it // mapItem.gameObject.name = "TreasureChest"; // // set it as first sibling so it does not apper in front of heroes, cities or labels // // mapItem.transform.SetAsFirstSibling(); // // Create item label on map // MapObjectLabel mapItemLabel = Instantiate(inventoryItemOnMapLabelTemplate, MapManager.Instance.GetParentTransformByType(GetComponent<MapObjectLabel>())).GetComponent<MapObjectLabel>(); // // Link item to the lable and label to the item // mapItem.GetComponent<MapObject>().Label = mapItemLabel; // mapItemLabel.MapObject = mapItem.GetComponent<MapObject>(); // // activate item label on map // mapItemLabel.gameObject.SetActive(true); // // activate it // mapItem.gameObject.SetActive(true); // // return it as result // return mapItem; //} public MapItemsContainer CreateInventoryItemContainerOnMap(MapCoordinates mapCoordinates) { // create new item on map MapItemsContainer mapItem = Instantiate(inventoryItemOnMapTemplate, MapManager.Instance.GetParentTransformByType(GetComponent <MapItemsContainer>())).GetComponent <MapItemsContainer>(); // set position offset Vector3 itemPositionOffset = new Vector3(8f, 8f, 0); // place it to original position on map based on the tile coordinates mapItem.transform.position = MapManager.Instance.GetWorldPositionByCoordinates(mapCoordinates) - itemPositionOffset; // rename it mapItem.gameObject.name = "TreasureChest"; // set it as first sibling so it does not apper in front of heroes, cities or labels // mapItem.transform.SetAsFirstSibling(); // Create item label on map MapObjectLabel mapItemLabel = Instantiate(inventoryItemOnMapLabelTemplate, MapManager.Instance.GetParentTransformByType(GetComponent <MapObjectLabel>())).GetComponent <MapObjectLabel>(); // Link item to the lable and label to the item mapItem.GetComponent <MapObject>().Label = mapItemLabel; mapItemLabel.MapObject = mapItem.GetComponent <MapObject>(); // activate item label on map mapItemLabel.gameObject.SetActive(true); // activate it mapItem.gameObject.SetActive(true); // return it as result return(mapItem); }
public void SetActive(MapItemsContainer mapItem) { // Activate this object gameObject.SetActive(true); // Get party inventory UI PartyInventoryUI partyInventoryUI = transform.Find("Panel").GetComponentInChildren <PartyInventoryUI>(); // Loop through each item in the chest foreach (InventoryItem inventoryItem in mapItem.LInventoryItems) { // set item representation in inventory UI partyInventoryUI.SetItemRepresentationInInventoryUI(inventoryItem); } // do clean up, because by default PartyInventoryUI on enable fills in empty slots partyInventoryUI.RemoveAllEmptySlots(); }
void CreateInventoryItemsOnMap(MapData mapData) { // Get objects manager // ObjectsManager objectsManager = transform.root.GetComponentInChildren<ObjectsManager>(); // Init map items container MapItemsContainer mapItemsContainer = null; // Init position on map variable // PositionOnMap previousItemPositionOnMap = new PositionOnMap(); // init map coordinates variable MapCoordinates previousItemMapCoordinates = new MapCoordinates(); // Get game map transform GameMap gameMap = ObjectsManager.Instance.GetComponentInChildren <GameMap>(); // Create parties for (int i = 0; i < mapData.itemsOnMap.Count; i++) { // verify if do not have already container on map for this item if ((mapItemsContainer == null) // verify if item is not using same container by comparing current position with previous // all items which has identical position on map are placed into the same container // || (previousItemPositionOnMap != mapData.itemsPositionOnMap[i])) || (previousItemMapCoordinates.x != mapData.itemsMapCoordinates[i].x) || (previousItemMapCoordinates.y != mapData.itemsMapCoordinates[i].y)) { // create item container //mapItemsContainer = ObjectsManager.Instance.CreateInventoryItemContainerOnMap(mapData.itemsPositionOnMap[i]); mapItemsContainer = ObjectsManager.Instance.CreateInventoryItemContainerOnMap(mapData.itemsMapCoordinates[i]); // save previous position //previousItemPositionOnMap = mapData.itemsPositionOnMap[i]; previousItemMapCoordinates = mapData.itemsMapCoordinates[i]; } // create item InventoryItem inventoryItem = ObjectsManager.Instance.CreateInventoryItem(mapData.itemsOnMap[i], gameMap.transform); // link item to container mapItemsContainer.LInventoryItems.Add(inventoryItem); } }