public SectorUnity GetSectorUnityFromCache(Sector sector) { if (goContainer == null) { goContainer = new GameObject(); goContainer.name = "Sectors"; goContainer.transform.position = new Vector3(0, 0, 0); goContainer.transform.rotation = Quaternion.identity; goContainer.transform.localScale = new Vector3(1, 1, 1); } SectorUnity sectorUnity = null; if (lastSectorAssignmentCache.ContainsKey(sector.sectorPosition)) { sectorUnity = lastSectorAssignmentCache[sector.sectorPosition]; if (sectorUnity.IsInUse()) sectorUnity = null; else cacheSectors.Remove(sectorUnity); } if (sectorUnity == null) { if (cacheSectors.Count > 0) { sectorUnity = cacheSectors[cacheSectors.Count - 1]; cacheSectors.RemoveAt(cacheSectors.Count - 1); } else { GameObject g = new GameObject(); sectorUnity = (SectorUnity)g.AddComponent(typeof(SectorUnity)); sectorUnity.gameManagerUnity = gameManagerUnity; sectorUnity.transform.parent = goContainer.transform; unitySectors.Add(sectorUnity); } } sectorUnity.transform.position = GraphicsUnity.TilePositionToVector3(sector.tileOffset); sector.SetSectorGraphics(sectorUnity); sectorUnity.name = sector.sectorPosition.y + "," + sector.sectorPosition.x + "," + sector.sectorPosition.z; return sectorUnity; }