void SetTarget() { try { var value = Provider.GetContent(); if (null == value) { Debug.LogError($"{TypeUtility.GetTypeDisplayName(Provider.GetType())}: Releasing content named '{Provider.Name}' because it returned null value."); m_RequestQuit = true; return; } // Removing from the hierarchy here because Unity will try to bind the elements to a serializedObject and // we want to use our own bindings. This will be fixed in UIToolkit directly. m_ContentRoot.RemoveFromHierarchy(); m_ContentNotReadyRoot.RemoveFromHierarchy(); var visitor = new SetTargetVisitor { Content = this, Inspector = m_ContentRoot }; PropertyContainer.Accept(visitor, ref value); Root.contentContainer.Add(m_ContentRoot); } catch (Exception ex) { Debug.LogError($"{TypeUtility.GetTypeDisplayName(Provider.GetType())}: Releasing content named '{Provider.Name}' because it threw an exception."); m_RequestQuit = true; Debug.LogException(ex); } }
private void AssignObject(Object newObject) { //It seems, at least in 2019.4 with IMGUI, that just rebinding the inspector is not enough; we need to recreate it. m_Inspector?.RemoveFromHierarchy(); m_Inspector = null; m_Header?.RemoveFromHierarchy(); m_Header = null; // TODO Display a missing script notice or something? if (!newObject) { return; } m_SerializedObject = new SerializedObject(newObject); m_Inspector = new InspectorElement(); m_Header = m_OwnerList.CreateHeader(m_Index, m_SerializedObject, m_Inspector); if (m_Header != null) { Add(m_Header); } Add(m_Inspector); this.Bind(m_SerializedObject); }