void initEC() { createlist = new LinkedList <EndlessCorridorHolder>(); //建立最中間的 EndlessCorridorHolder prefab = getRandomEndlessCorridorPrefab(); EndlessCorridorHolder initObj = (EndlessCorridorHolder)GameObject.Instantiate(prefab, Vector3.zero, Quaternion.Euler(-90, 0, 0)); halfIndex = createSize / 2; initObj.initEC(halfIndex, this, doRescale); createlist.AddLast(initObj); //add head EndlessCorridorHolder refObj = initObj; for (int i = halfIndex - 1; i >= 0; i--) { EndlessCorridorHolder newObj = createEcByRef(i, refObj, refObj.getHeadDummy(), 2.0f); createlist.AddFirst(newObj); refObj = newObj; } Head = refObj; // add tail refObj = initObj; for (int i = halfIndex + 1; i < createSize; i++) { EndlessCorridorHolder newObj = createEcByRef(i, refObj, refObj.getTailDummy(), 0.5f); createlist.AddLast(newObj); refObj = newObj; } Tail = refObj; }
void addHead() { //修改其他元素序號 // 0 1 2 3 4 變成 // 1 2 3 4 5 foreach (EndlessCorridorHolder element in createlist) { element.ListIndex = element.ListIndex + 1; } //刪除Tail元素 createlist.RemoveLast(); Destroy(Tail.gameObject); Tail = createlist.Last.Value; EndlessCorridorHolder newObj = createEcByRef(0, Head, Head.getHeadDummy(), 2.0f); createlist.AddFirst(newObj); Head = newObj; }