void Generate() { SkinnedMeshRenderer result = XUtility.FindOrCreateComponent <SkinnedMeshRenderer>(this); List <Transform> skeleton = new List <Transform>(); this.gameObject.GetComponentsInChildren <Transform>(true, skeleton); List <SkinnedMeshRenderer> renderers = new List <SkinnedMeshRenderer>(); foreach (Part p in this.mParts.Values) { if (p.element == null) { continue; } if (p.method == Method.Dress) { SkinnedMeshRenderer[] rs = p.element.GetComponentsInChildren <SkinnedMeshRenderer>(true); renderers.AddRange(rs); if (p.element.transform.parent != this.transform) { p.element.transform.parent = this.transform; } } else { // if p is not changed, dont destroy and attach if (p.changed) { GameObject locator = XUtility.FindGameObjectRecursively(this.gameObject, p.locator); XUtility.DestroyChildren(locator); XUtility.AttachGameObject(locator, p.element); p.element.SetActive(true); //XUtility.SetVisibleRecursively(p.element, true); } } } XUtility.CombineSkinnedMeshRenderer(result, skeleton, renderers); result.updateWhenOffscreen = true; }
public static GameObject FindOrCreateGameObject(GameObject parent, string name) { GameObject result = null; if (parent == null) { result = GameObject.Find(name); if (result == null) { result = new GameObject(name); } } else { result = XUtility.FindGameObjectInChildren(parent, name); if (result == null) { result = new GameObject(name); XUtility.AttachGameObject(parent, result); } } return(result); }