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); }
public void SplitMixedGarbage(GameObject mixedGarbage, List <int> splitCodes) { LinkedListNode <GameObject> mixedNode = garbages.Find(mixedGarbage); Garbage mixGarbage = mixedNode.Value.GetComponent <Garbage>(); foreach (int code in splitCodes) { GameObject garbage = LevelManager.instance.CreateGarbageAtPos(code, mixedGarbage.transform.position); garbage.GetComponent <Garbage>().SetTarget(mixGarbage.GetCurPathIndex()); garbages.AddBefore(mixedNode, garbage); } LinkedListNode <GameObject> newNode = mixedNode.Previous; PushPreviousNodes(newNode); RemoveGarbage(mixedNode); }