// Open a container with the inventory (interface function) public void OpenContainer() { SetOnContainerMenu(false); WORLD_Container closestContainerInRange = SortContainers(); if (closestContainerInRange != null) { // Layout the slots to begin with, initiallizes and populates array also m_slotArrayContainer = LIB_Inventory.LayoutSlots(closestContainerInRange.CONTAINER_SIZE, m_slotObject, m_containerSlotSubPanel); if (m_slotArrayContainer.Length > 0) { m_openContainer = closestContainerInRange; // Force the layout initially LIB_Inventory.ForceGridLayoutGroupRebuild(m_containerSlotSubPanel.GetComponent <RectTransform>()); } ToggleInventory(1); } else { m_openContainer = null; } }
// Gets the closest container from the list of containers in range, if none exist, returns null public WORLD_Container SortContainers() { int numberOfContainersInRange = m_containersInRange.Count; if (numberOfContainersInRange > 0) { // Sort the containers by distance WORLD_Container closestContainerInRange = m_containersInRange[0]; float closestDistance = Vector3.Distance(transform.position, closestContainerInRange.transform.position); // Find closest for (int i = 0; i < numberOfContainersInRange; ++i) { float candidateDistance = Vector3.Distance(transform.position, m_containersInRange[i].transform.position); m_containersInRange[i].m_openIcon.SetActive(true); if (candidateDistance < closestDistance) { closestDistance = candidateDistance; // Disable old closestContainerInRange.m_openIcon.SetActive(false); closestContainerInRange = m_containersInRange[i]; } else { // If I was comparing myself against the shorted distance, don't disable if (closestContainerInRange != m_containersInRange[i]) { m_containersInRange[i].m_openIcon.SetActive(false); } } } return(closestContainerInRange); } return(null); }
public void RemoveContainer(WORLD_Container toRemoveContainer) { m_containersInRange.Remove(toRemoveContainer); }
public void AddContainter(WORLD_Container toAddContainer) { m_containersInRange.Add(toAddContainer); }