コード例 #1
0
    private void PushPreviousNodes(LinkedListNode <GameObject> node)
    {
        float garbageDistance = LevelManager.instance.GetGarbageDistance();

        LinkedListNode <GameObject> curNode      = node;
        LinkedListNode <GameObject> previousNode = curNode.Previous;

        while (previousNode != null)
        {
            Garbage curGarbage  = curNode.Value.GetComponent <Garbage>();
            Garbage nextGarbage = previousNode.Value.GetComponent <Garbage>();
            Vector2 offset      = (nextGarbage.GetPos() - curGarbage.GetPos());
            float   distance    = offset.magnitude;
            if (distance < garbageDistance)
            {
                nextGarbage.MoveForward(garbageDistance - distance);
                curNode      = curNode.Previous;
                previousNode = previousNode.Previous;
            }
            else
            {
                break;
            }
        }
    }
コード例 #2
0
    private LinkedListNode <GameObject> FindPreviousNodeBeforePoint(Vector2 point, int targetPathIndex, Vector2 targetNodePos)
    {
        float pointToTarget = (targetNodePos - point).magnitude;

        // forward iteration
        LinkedListNode <GameObject> node = garbages.First;

        while (node != null)
        {
            Garbage garbage  = node.Value.GetComponent <Garbage>();
            int     curIndex = garbage.GetCurPathIndex();
            if (curIndex < targetPathIndex) // node < PathNode
            {
                return(node);
            }
            else if (curIndex == targetPathIndex) // node == PathNode
            {
                float nodeToPathNode = (targetNodePos - garbage.GetPos()).magnitude;
                if (nodeToPathNode > pointToTarget)
                {
                    return(node);
                }
            }
            node = node.Next;
        }
        return(node);
    }