/// <summary> /// Checks to ensure that the widget is still parented to the right panel. /// </summary> public void ParentHasChanged() { if (mPanel != null) { // This code allows drag & dropping of widgets onto different panels in the editor. bool valid = true; Transform t = cachedTransform.parent; // Run through the parents and see if this widget is still parented to the transform while (t != null) { if (t == mPanel.cachedTransform) { break; } if (!mPanel.WatchesTransform(t)) { valid = false; break; } t = t.parent; } // This widget is no longer parented to the same panel. Remove it and re-add it to a new one. if (!valid) { if (!keepMaterial || Application.isPlaying) { material = null; } mPanel = null; CreatePanel(); } } }