IEnumerator constructAll(List <IslandGO> islands)
        {
            for (int i = 0; i < islands.Count; i++)
            {
                constructDockGO(islands[i]);
                yield return(null);
            }

            for (int i = 0; i < islands.Count; i++)
            {
                IslandGO   islandGOComponent = islands[i].GetComponent <IslandGO>();
                GameObject eDock             = islandGOComponent.getExportDock();
                GameObject iDock             = islandGOComponent.getImportDock();
                if (eDock != null)
                {
                    dockList.Add(eDock);
                    eDock.GetComponent <DependencyDock>().constructConnectionArrows();
                }
                if (iDock != null)
                {
                    dockList.Add(iDock);
                    iDock.GetComponent <DependencyDock>().constructConnectionArrows();
                }
                yield return(null);
            }

            Debug.Log("Finished with Dock-GameObject construction!");
            status = Status.Finished;
            cb();
        }
        private void Deactivate(IslandGO islandGO)
        {
            List <Region> regions = islandGO.getRegions();

            for (int c = 0; c < regions.Count; c++)
            {
                List <Building> building = regions[c].getBuildings();
                for (int b = 0; b < building.Count; b++)
                {
                    building[b].gameObject.SetActive(false);
                }
                regions[c].gameObject.SetActive(false);
            }
            islandGO.getExportDock().SetActive(false);
            islandGO.getImportDock().SetActive(false);
            islandGO.getCoast().SetActive(false);
        }
        private void constructDockGO(IslandGO island)
        {
            CartographicIsland islandStructure = island.getIslandStructure();

            //Get graph vertex associated with the island
            BidirectionalGraph <GraphVertex, GraphEdge> depGraph = islandStructure.getBundle().getParentProject().getDependencyGraph();

            GraphVertex vert = islandStructure.getDependencyVertex();

            if (vert != null)
            {
                float importSize = GlobalVar.minDockSize;
                float exportSize = GlobalVar.minDockSize;

                //Outgoing edges -Bundle depends on...
                IEnumerable <GraphEdge> outEdges;
                depGraph.TryGetOutEdges(vert, out outEdges);
                List <GraphEdge> edgeList = outEdges.ToList();
                importSize = Helperfunctions.mapDependencycountToSize(edgeList.Count);
                //Import Dock
                GameObject importD = island.getImportDock();
                importD.transform.localScale = new Vector3(importSize, importSize, importSize);
                //Link dependencies
                DependencyDock dockComponent = importD.GetComponent <DependencyDock>();
                dockComponent.setDockType(DockType.ImportDock);
                foreach (GraphEdge e in edgeList)
                {
                    GameObject ed = e.Target.getIsland().getIslandGO().GetComponent <IslandGO>().getExportDock();
                    dockComponent.addDockConnection(ed.GetComponent <DependencyDock>(), e.getWeight());
                }

                #region determine optimal Position for ImportDock
                List <GameObject> doNotCollideList = new List <GameObject>();
                doNotCollideList.Add(island.getCoast());
                bool foundLocation = findSuitablePosition2D(importD, doNotCollideList, island.gameObject, 500);
                if (!foundLocation)
                {
                    Debug.Log("Could not find suitable location for " + importD.name);
                }
                #endregion



                //Ingoing edges -Other Bundles depends on this one...
                depGraph.TryGetInEdges(vert, out outEdges);
                edgeList   = outEdges.ToList();
                exportSize = Helperfunctions.mapDependencycountToSize(edgeList.Count);
                //Export Dock
                GameObject exportD    = island.getExportDock();
                float      eDockWidth = exportD.GetComponent <MeshFilter>().sharedMesh.bounds.size.x *exportSize;
                float      iDockWidth = importD.GetComponent <MeshFilter>().sharedMesh.bounds.size.x *importSize;
                //exportD.transform.position = importD.transform.position + Vector3.left * (iDockWidth + eDockWidth) * 0.5f;
                exportD.transform.localScale = new Vector3(exportSize, exportSize, exportSize);
                //Link dependencies
                dockComponent = exportD.GetComponent <DependencyDock>();
                dockComponent.setDockType(DockType.ExportDock);
                foreach (GraphEdge e in edgeList)
                {
                    GameObject id = e.Source.getIsland().getIslandGO().GetComponent <IslandGO>().getImportDock();
                    dockComponent.addDockConnection(id.GetComponent <DependencyDock>(), e.getWeight());
                }

                #region determine optimal Position for ExportDock
                doNotCollideList.Clear();
                doNotCollideList.Add(island.getCoast());
                foundLocation = findSuitablePosition2D(exportD, doNotCollideList, importD, 500);
                if (!foundLocation)
                {
                    Debug.Log("Could not find suitable location for " + exportD.name);
                }
                #endregion


                #region extend Island collider based on new Docksizes
                island.GetComponent <CapsuleCollider>().radius += Mathf.Max(importSize, exportSize) * Mathf.Sqrt(2f);
                #endregion
            }
        }
        private void bakeIslandMesh(IslandGO islandGOComponent)
        {
            GameObject             islandGO      = islandGOComponent.gameObject;
            List <CombineInstance> currentCiList = new List <CombineInstance>();

            foreach (Region region in islandGOComponent.getRegions())
            {
                foreach (Building b in region.getBuildings())
                {
                    CombineInstance ci       = new CombineInstance();
                    CompilationUnit cu       = b.getCU();
                    long            loc      = cu.getLoc();
                    int             modelIdx = Helperfunctions.mapLOCtoLevel(loc);

                    if (cu.implementsServiceComponent())
                    {
                        ci.mesh = SILod2Prefabs[modelIdx].GetComponent <MeshFilter>().sharedMesh;
                    }
                    else if (cu.declaresService())
                    {
                        ci.mesh = SDLod2Prefabs[modelIdx].GetComponent <MeshFilter>().sharedMesh;
                    }
                    else
                    {
                        ci.mesh = CULod2Prefabs[modelIdx].GetComponent <MeshFilter>().sharedMesh;
                    }

                    ci.subMeshIndex = 0;
                    ci.transform    = islandGO.transform.worldToLocalMatrix * b.gameObject.transform.localToWorldMatrix;
                    currentCiList.Add(ci);
                }

                CombineInstance ciCountry = new CombineInstance();
                ciCountry.mesh         = region.getRegionArea().GetComponent <MeshFilter>().sharedMesh;
                ciCountry.subMeshIndex = 0;
                ciCountry.transform    = Matrix4x4.identity;
                currentCiList.Add(ciCountry);
            }

            #region Add coast to FinalCombineList
            CombineInstance ciCoast = new CombineInstance();
            ciCoast.mesh         = islandGOComponent.getCoast().GetComponent <MeshFilter>().sharedMesh;
            ciCoast.subMeshIndex = 0;
            ciCoast.transform    = Matrix4x4.identity;
            currentCiList.Add(ciCoast);
            #endregion

            #region Add docks to FinalCombineList
            GameObject expDock = islandGOComponent.getExportDock();
            GameObject impDock = islandGOComponent.getImportDock();

            CombineInstance eDockCI = new CombineInstance();
            eDockCI.mesh         = eDockLod1Prefab.GetComponent <MeshFilter>().sharedMesh;
            eDockCI.subMeshIndex = 0;
            eDockCI.transform    = islandGOComponent.transform.worldToLocalMatrix * expDock.transform.localToWorldMatrix;

            CombineInstance iDockCI = new CombineInstance();
            iDockCI.mesh         = iDockLod1Prefab.GetComponent <MeshFilter>().sharedMesh;
            iDockCI.subMeshIndex = 0;
            iDockCI.transform    = islandGOComponent.transform.worldToLocalMatrix * impDock.transform.localToWorldMatrix;

            currentCiList.Add(eDockCI);
            currentCiList.Add(iDockCI);
            #endregion

            #region Replace Island Mesh and Materials with baked one
            MeshRenderer bakedMR = islandGO.AddComponent <MeshRenderer>();
            bakedMR.sharedMaterial = holomaterial;
            MeshFilter bakedMF = islandGO.AddComponent <MeshFilter>();
            bakedMF.mesh = new Mesh();
            bakedMF.sharedMesh.CombineMeshes(currentCiList.ToArray(), true, true);

            #endregion
        }