Inheritance: MonoBehaviour
Esempio n. 1
0
    IEnumerator FillChildrenEdgesWithFootprints()
    {
        long startTime = DateTime.Now.Ticks;

        EditorUtility.DisplayProgressBar("FillChildrenEdgesWithFootprints", "Filling children graphs with footprints", 0f);
        yield return(null);

        for (int i = 0; i < placer.transform.childCount; i++)
        {
            FootprintPlacer childPlacer = placer.transform.GetChild(i).GetComponent <FootprintPlacer>();
            if (!placer)
            {
                continue;
            }

            childPlacer.footprintPrefabsOnEdge = placer.footprintPrefabsOnEdge;

            try
            {
                childPlacer.UpdateData();
                childPlacer.FillWithEdgesWithFootprints();
                Debug.Log("FillChildrenEdgesWithFootprints... " + (i + 1) + "/" + placer.transform.childCount + " (" + (DateTime.Now.Ticks - startTime) / 10000000 + "s)");
                EditorUtility.DisplayProgressBar("FillChildrenEdgesWithFootprints", "Filling children graphs' edges with footprints " + (i + 1) + "/" + placer.transform.childCount, (float)i / placer.transform.childCount);
            }
            catch (Exception e)
            {
                Debug.Log("FootprintPlacerEditor::FillChildrenEdgesWithFootprints() - Error: " + e.Message);
                EditorUtility.ClearProgressBar();
            }
            yield return(null);
        }

        EditorUtility.ClearProgressBar();
    }
Esempio n. 2
0
    void OnEnable()
    {
        placer = (FootprintPlacer)target;

        placer.graph = placer.GetComponent<Graph>();
        if (placer.graph == null)
            placer.graph = placer.GetComponentInParent<Graph>();

        controls = new UtilityTools.EditorControls(placer.gameObject);
    }
Esempio n. 3
0
    void OnEnable()
    {
        placer = (FootprintPlacer)target;

        placer.graph = placer.GetComponent <Graph>();
        if (placer.graph == null)
        {
            placer.graph = placer.GetComponentInParent <Graph>();
        }

        controls = new UtilityTools.EditorControls(placer.gameObject);
    }
Esempio n. 4
0
        public void ExtractMainPrimitives(float childEdgeWidth)
        {
            if (mainPrimitives != null && mainPrimitives.Count > 0)
            {
                UtilityTools.Helper.DestroyChildren(transform);

                mainPrimitives.ForEach((p) =>
                {
                    GameObject subGraphObj = new GameObject("SubGraph");
                    subGraphObj.transform.SetParent(transform);
                    subGraphObj.transform.localPosition = Vector3.zero;
                    subGraphObj.transform.localScale    = Vector3.one;

                    Graph subGraph    = subGraphObj.AddComponent <Graph>();
                    subGraph.GraphID  = Guid.NewGuid().GetHashCode();
                    subGraphObj.name += subGraph.GraphID;

                    subGraph.nodes = new List <Node>();
                    foreach (var node in p.nodes)
                    {
                        subGraph.nodes.Add(node);
                    }
                    subGraph.edges = new List <Edge>();
                    foreach (var edge in p.edges)
                    {
                        Edge edgeCopy = new Edge(edge.Node1, edge.Node2, childEdgeWidth);
                        subGraph.edges.Add(edgeCopy);
                    }

                    subGraph.ProcessMinimalCycles();

                    subGraphs.Add(subGraph);

                    FootprintPlacer placer = GetComponent <FootprintPlacer>();
                    if (placer != null)
                    {
                        FootprintPlacer _placer        = subGraph.gameObject.AddComponent <FootprintPlacer>();
                        _placer.footprintPrefabsOnEdge = placer.footprintPrefabsOnEdge;
                        _placer.footprintPrefabsInside = placer.footprintPrefabsInside;
                        _placer.UpdateData();
                    }
                });
            }
        }
Esempio n. 5
0
        void ProcessSubPrimitives(Primitive p)
        {
            if (p.subEdges == null || p.subEdges.Count <= 0)
            {
                return;
            }

            // Copy local lists from primitive's sub nodes and edges
            List <Node> _nodes = new List <Node>();
            List <Edge> _edges = new List <Edge>();

            EdgeGraphUtility.CopyNodesAndEdges(p.subNodes, p.subEdges, out _nodes, out _edges);

            EdgeGraphUtility.CheckAdjacentNodes(ref _nodes, ref _edges);

            //subPrimitives = new List<Primitive>();
            List <Primitive> _subPrimitives = new List <Primitive>();

            // Extract primitives inside main primitives
            try
            {
                MinimalCycle.Extract(ref _nodes, ref _edges, ref _subPrimitives);
            }
            catch (Exception e)
            {
                Debug.LogWarning("Graph::GeneratePrimitiveSubPrimitives() - Error while extracting primitives: " + e.Message);
                return;
            }

            _subPrimitives.ForEach((sp) =>
            {
                sp.Process();
            });

            for (int i = _subPrimitives.Count - 1; i >= 0; i--)
            {
                if (!_subPrimitives[i].EvaluationResult)
                {
                    _subPrimitives.RemoveAt(i);
                }
            }

            _subPrimitives.ForEach((sp) =>
            {
                sp.parent = p.ID;

                GameObject subGraphObj = new GameObject("SubGraph");
                subGraphObj.transform.SetParent(transform);
                subGraphObj.transform.localPosition = Vector3.zero;
                subGraphObj.transform.localScale    = Vector3.one;

                Graph subGraph    = subGraphObj.AddComponent <Graph>();
                subGraph.GraphID  = Guid.NewGuid().GetHashCode();
                subGraphObj.name += subGraph.GraphID;

                subGraph.nodes = new List <Node>();
                foreach (var node in sp.nodes)
                {
                    subGraph.nodes.Add(node);
                }
                subGraph.edges = new List <Edge>();
                foreach (var edge in sp.edges)
                {
                    edge.Width = 0f;
                    subGraph.edges.Add(edge);
                }

                subGraph.ProcessMinimalCycles();

                subGraph.mainPrimitives[0].parent = p.ID;

                subGraphs.Add(subGraph);

                //subPrimitives.Add(subGraph.mainPrimitives[0]);

                FacadeBuilder builder = GetComponent <FacadeBuilder>();
                if (builder != null)
                {
                    FacadeBuilder subBuilder       = subGraph.gameObject.AddComponent <FacadeBuilder>();
                    subBuilder.inSet               = builder.inSet;
                    subBuilder.facadeStretchPrefab = builder.facadeStretchPrefab;
                    subBuilder.facadePrefabs       = builder.facadePrefabs;
                    subBuilder.roofMiddleMaterial  = builder.roofMiddleMaterial;
                    subBuilder.roofSideMaterial    = builder.roofSideMaterial;
                    subBuilder.roofHeight          = builder.roofHeight;
                    subBuilder.roofMiddleAddHeight = builder.roofMiddleAddHeight;
                    subBuilder.roofAccentWidth     = builder.roofAccentWidth;
                }

                FootprintPlacer placer = GetComponent <FootprintPlacer>();
                if (placer != null)
                {
                    FootprintPlacer _placer        = subGraph.gameObject.AddComponent <FootprintPlacer>();
                    _placer.footprintPrefabsOnEdge = placer.footprintPrefabsOnEdge;
                    _placer.footprintPrefabsInside = placer.footprintPrefabsInside;
                    _placer.UpdateData();
                }
            });
        }