private void processDie(DieSides pDie) { if (pDie == null) { return; } for (int i = 0; i < pDie.dieSideCount; i++) { //get the die side itself to calculate the position and orientation of the prefab to attach DieSide dieSide = pDie.GetDieSide(i); Vector3 position = dieSide.centerPoint + _offset * dieSide.normal; Quaternion orientation = Quaternion.LookRotation(_flip ? -dieSide.normal : dieSide.normal); //attach prefab first GameObject attachment = Instantiate(_prefab, pDie.transform); //then make sure all LOCAL settings are set correctly (so that it also performs correctly in worldspace) attachment.transform.localScale = Vector3.one * _scale; attachment.transform.localPosition = position; attachment.transform.localRotation = orientation; attachment.name = "" + i; //if the prefab is diesideaware, pass the index and dieside to the instance created from the prefab IDieSideAware dieSideAware = attachment.GetComponent <IDieSideAware>(); if (dieSideAware != null) { dieSideAware.SetDieSide(i, dieSide); } } }
private void removeChildrenForDie(DieSides pDie) { if (pDie == null) { return; } while (pDie.transform.childCount > 0) { DestroyImmediate(pDie.transform.GetChild(0).gameObject); } }