Example #1
0
    private static bool TraverseRecursively(Shape shape, List<ChainItem> chain)
    {        
        _traversedShapes.Add(shape);
        bool chainItemHasConnector = false;

        ChainItem chainItem = new ChainItem();
        chainItem.Shape = shape;
        chainItem.TargetDirection = shape.CurrentDirection;
        chain.Add(chainItem);

        var connector = FindConnectorWithConnection(shape);
        if (connector != null && shape.HasConnection(connector.CurrentDirection))
        {
            //Debug.LogWarning(connector.name);
            chainItemHasConnector = true;
            _unTraversedConnectors.Remove(connector);
        }

        var neighbors = NodesGrid.FindConnectedNeighborShapes(shape);

        bool hasFirstChain = false;
        foreach (var neighbor in neighbors)
        {            
            if (!_traversedShapes.Contains(neighbor))
            {
                List<ChainItem> targetChain = chain;
                if (hasFirstChain)
                    targetChain = chainItem.childChain;

                bool nextChainItemHasConnector = TraverseRecursively(neighbor, targetChain);
                chainItemHasConnector |= nextChainItemHasConnector;
                hasFirstChain = true;
            }
        }

        //если текущая нода не соединена с коннектором и дочерние ответвления тоже не соединены с коннектором, то удалить данный узел.
        if (!chainItemHasConnector)
        {
            //chainItem.Shape.name += "_RemovedChainItem";
            chain.Remove(chainItem);
        }

        return chainItemHasConnector;
    }
Example #2
0
    // Update is called once per frame
    private void Update()
    {
        if (_path == null)
        {
            return;
        }

        if (PathIsTraversed())
        {
            _path = null;
            _currentWaypointIndex = 0;

            if (!_isClonedInCurrentShape)
                _prevOutDirection = _currentShape.GetOutDirection(_prevOutDirection);//получение направления выхода из текущей shape

            var prevShape = _currentShape;
            _currentShape = NodesGrid.GetNextShape(_currentShape, _prevOutDirection);
            if (prevShape != _currentShape)
                TryAddShapeToList(_currentShape);

            if (_currentShape == null || _currentShape.IsInRotateProcess || !_currentShape.HasConnection(_prevOutDirection))
            {
                DestroySelf();
                return;
            }

            _path = _currentShape.GetPath(_prevOutDirection);
            _isClonedInCurrentShape = false;
            _parentSignal = null;
        }

        bool isUpdated = UpdateCurrentWaypoint();
        Vector3 moveDirection = GetMoveDirection(_currentWaypoint);

        if (isUpdated)
        {
            TryClone();
            CorrectMovement(moveDirection);
        }

        Rotate(_currentWaypoint);
        Move(_currentWaypoint, moveDirection);  
    }