public void Draw(LevelSkeleton levelSkeleton)
    {
        if (_lineRendererGameObjects != null)
        {
            _lineRendererGameObjects.ForEach(_ => Destroy(_));
        }


        if (_pointGameObjects != null)
        {
            _pointGameObjects.ForEach(_ => Destroy(_));
        }

        _lineRendererGameObjects = new List <GameObject>();
        _pointGameObjects        = new List <GameObject>();

        levelSkeleton.Lines.ToList().ForEach(_ =>
        {
            var lineRendererGameObject = CreateLine(_.Points.pointA.Position, _.Points.pointB.Position);
            _lineRendererGameObjects.Add(lineRendererGameObject);
        });

        levelSkeleton.Points.ToList().ForEach(_ =>
        {
            var pointGameObject = CreatePoint(_);
            _pointGameObjects.Add(pointGameObject);
        });
    }
    // Start is called before the first frame update
    void Start()
    {
        var levelSkeletonGeneratorParams = new LevelSkeletonGeneratorParams();
        var levelSkeletonGenerator       = new LevelSkeletonGenerator(levelSkeletonGeneratorParams);

        _levelSkeleton = levelSkeletonGenerator.Execute();

        var levelSkeletonRenderer = GetComponent <LevelSkeletonRenderer>();

        levelSkeletonRenderer.Draw(_levelSkeleton);
    }
예제 #3
0
 public static bool IsDuplicateLines(this LevelSkeleton skeleton)
 {
     return((from line in skeleton.Lines
             let otherLines = skeleton.Lines.Except(new List <SkeletonLine> {
         line
     })
                              where otherLines.Any(_ =>
                                                   _.ContainsSkeletonPoint(line.Points.pointA.Position) &&
                                                   _.ContainsSkeletonPoint(line.Points.pointB.Position))
                              select line)
            .Any());
 }
예제 #4
0
    public static bool IsLinesIntersects(this LevelSkeleton skeleton)
    {
        foreach (var line in skeleton.Lines)
        {
            if (skeleton.Lines.Where(_ => _ != line && !_.ContainsSkeletonPoint(line.Points.pointA) && !_.ContainsSkeletonPoint(line.Points.pointB)).Any(_ => _.FindIntersection(line).HasValue))
            {
                return(true);
            }
        }

        return(false);
    }
예제 #5
0
    public static void Draw(this LevelSkeleton skeleton)
    {
        skeleton.Lines.ToList().ForEach(_ =>
        {
            Debug.DrawLine(_.Points.pointA.Position, _.Points.pointB.Position, Color.green);
        });

        skeleton.Points.ToList().ForEach(_ =>
        {
            Gizmos.color = Color.yellow;
            Gizmos.DrawSphere(_.Position, 0.1f);
        });
    }
예제 #6
0
    public static LevelSkeleton ToBasementSkeleton(this LevelSkeleton skeleton)
    {
        var basementSkeleton = new LevelSkeleton();

        var newLines = skeleton.ToGraph().AlgorithmByPrim().Edges.ToList().Select(_ =>
        {
            return(new SkeletonLine(_.Vertexes.ToList()[0].Data, _.Vertexes.ToList()[1].Data, new EntityType(Color.blue, "Basement")));
        });

        basementSkeleton.AddLines(newLines);

        return(basementSkeleton);
    }
예제 #7
0
    public static Graph <SkeletonPoint> ToGraph(this LevelSkeleton skeleton)
    {
        var vertexDictionary = new Dictionary <string, Vertex <SkeletonPoint> >();

        skeleton.Points.ToList().ForEach(_ =>
        {
            vertexDictionary.Add(_.Id, new Vertex <SkeletonPoint>(_));
        });

        var edges = skeleton.Lines.Select(_ => new Edge <SkeletonPoint>(vertexDictionary[_.Points.pointA.Id], vertexDictionary[_.Points.pointB.Id], _.Length));

        return(new Graph <SkeletonPoint>(vertexDictionary.Values.ToList(), edges));
    }
예제 #8
0
    public void Draw(LevelSkeleton levelSkeleton)
    {
        Clear();
        _lineRendererGameObjects = new List <GameObject>();
        _pointGameObjects        = new List <GameObject>();

        levelSkeleton.Lines.ToList().ForEach(_ =>
        {
            var lineRendererGameObject = CreateLine(_.Points.pointA.Position, _.Points.pointB.Position, _.Type, _.Id);
            _lineRendererGameObjects.Add(lineRendererGameObject);
        });

        levelSkeleton.Points.ToList().ForEach(_ =>
        {
            var pointGameObject = CreatePoint(_, _.Id);
            _pointGameObjects.Add(pointGameObject);
        });
    }
예제 #9
0
    public static List <List <SkeletonLine> > GetCycles(this LevelSkeleton skeleton)
    {
        var cycles = new List <List <SkeletonLine> >();

        var graphCycles = skeleton.ToGraph().GetCycles();

        foreach (var graphCycle in graphCycles)
        {
            var cycle = new List <SkeletonLine>();
            graphCycle.ForEach(edge => cycle.Add(skeleton.Lines.First(_ => _.ContainsSkeletonPoint(edge.VertexA.Data) && _.ContainsSkeletonPoint(edge.VertexB.Data))));

            if (!cycles.Any(_ => _.IsCycleEquals(cycle)))
            {
                cycles.Add(cycle);
            }
        }

        return(cycles);
    }
예제 #10
0
    public static LevelSkeleton ToTriangleSkeleton(this LevelSkeleton skeleton)
    {
        var fullSkeleton = new LevelSkeleton();

        fullSkeleton.AddLines(skeleton.Lines);

        var linesToRemove = new List <SkeletonLine>();
        var isFirst       = true;

        while (isFirst || linesToRemove.Count > 0)
        {
            isFirst       = false;
            linesToRemove = new List <SkeletonLine>();
            var lines = fullSkeleton.Lines.OrderBy(_ => _.Length).ToList();

            foreach (var line in lines)
            {
                var l = fullSkeleton.Lines.Except(new[] { line })
                        .Except(linesToRemove)
                        .Where(_ => _.FindIntersection(line) != null && _.Length > line.Length)
                        .ToList();

                if (l.Count > 0)
                {
                    l = l.OrderBy(_ => _.Length).ToList();
                    linesToRemove.Add(l.Last());
                    break;
                }

                linesToRemove.AddRange(l.Except(linesToRemove));
            }

            if (linesToRemove.Count > 0)
            {
                fullSkeleton.RemoveLines(linesToRemove);
            }
        }

        fullSkeleton.SetLineType(new EntityType(Color.red, "Additional"));

        return(fullSkeleton);
    }