public void addGrandParent() { if (depth < 2) { return; // has no grand parent } // revive grand parent FractalBox grandp = (FractalBox)GameObject.Instantiate(gm.templateFractal); grandp.addWalls(); grandp.initChilds(); grandp.depth = parent.depth - 1; // set the grand parent as the first child of the GameManager object grandp.transform.parent = gm.transform; // revive uncles for (int i = 0; i < Fractal.blockPos.Length; i++) { if (childIndex == i) // make grand parent adopt parent { grandp.transform.localScale = new Vector3(Fractal.maxSize, Fractal.maxSize, Fractal.maxSize) / Fractal.relaSize / Fractal.relaSize; parent.transform.parent = grandp.transform; parent.transform.localPosition = new Vector3(Fractal.blockPos[i].x, 0, Fractal.blockPos[i].y); grandp.setChild(i, parent); } else { grandp.addChild(i, parent.depth, 1); } } parent.parent = grandp; gm.baseFrac = grandp; }
// grandParent-death-and-revive public void removeGrandParent() { if (depth < 2) { return; // has no grand parent } gm.baseFrac = parent; FractalBox grandp = parent.parent; grandp.removeWalls(); for (int i = 0; i < Fractal.blockPos.Length; i++) { if (grandp.getChild(i).Equals(parent)) // find the childIndex { childIndex = i; continue; } // distroy uncles Destroy(grandp.getChild(i).gameObject); } // set the parent as the first child of the GameManager object parent.transform.parent = gm.transform; parent.transform.localPosition = Vector3.zero; Destroy(grandp.gameObject); }
// create the first fractal at depth 0 void Start() { fractal = (FractalBox)GameObject.Instantiate(templateFractal); fractal.initialize(depth, 0); player.transform.parent = fractal.transform; fractal.transform.parent = transform; baseFrac = fractal; }
// change current fractal private void changeFractal(FractalBox fb, bool desc) { if (desc) { fb.initialize(fb.depth, 0); fb.removeTile(); } else { fractal.removeChild(); fractal.addTexture(); } fractal = fb; player.transform.parent = fb.transform; }
public void setChild(int i, FractalBox fb) { childs [i] = fb; }