Exemple #1
0
        public CustomInspectorElement(PropertyPath basePath, IInspector inspector, BindingContextElement root)
        {
            m_Root     = root;
            binding    = this;
            m_BasePath = basePath;
            name       = TypeUtility.GetTypeDisplayName(inspector.Type);
            Inspector  = inspector;
            try
            {
                m_Content = Inspector.Build();

                if (null == m_Content)
                {
                    return;
                }

                HasInspector = true;

                // If `IInspector.Build` was not overridden, it returns this element as its content.
                if (this != m_Content)
                {
                    Add(m_Content);
                    RegisterBindings(m_Content);
                    RegisterSearchHandlers(m_Content);
                }
            }
            catch (Exception exception)
            {
                Debug.LogException(exception);
            }
        }
        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);
            }
        }
 string GetTypeName(Type type)
 {
     if (type == typeof(Null))
     {
         return($"Null ({TypeUtility.GetTypeDisplayName(typeof(T))})");
     }
     return(TypeUtility.GetTypeDisplayName(type));
 }
Exemple #4
0
        void CacheDisplayText()
        {
            var name = m_Provider.Name;

            if (m_PreviousName == name)
            {
                return;
            }
            m_PreviousName = name;
            m_CachedText   = $"{(string.IsNullOrEmpty(name) ? TypeUtility.GetTypeDisplayName(m_Provider.GetType()) : name)} is not ready for display";
        }
        // Invoked by the Unity update loop
        void Update()
        {
            m_ScrollPosition  = m_ScrollView.scrollOffset;
            titleContent.text = !string.IsNullOrEmpty(m_Content.Name)
                ? m_Content.Name
                : TypeUtility.GetTypeDisplayName(m_Content.GetType());
            m_Content.Update();
            if (!m_Content.IsValid)
            {
                Close();
            }

            // We are saving here because we want to store the data inside the editor window so that it survives both
            // domain reloads and closing/re-opening Unity.
            m_Content.Save();
        }
 public static string GetNotConstructableWarningMessage(Type type)
 => $"Could not create an instance of type `{TypeUtility.GetTypeDisplayName(type)}`. A public parameter-less constructor or an explicit construction method is required.";
 public static string GetNotAssignableWarningMessage(Type type, Type assignableTo)
 => $"Could not create an instance of type `{TypeUtility.GetTypeDisplayName(type)}`: Type must be assignable to `{TypeUtility.GetTypeDisplayName(assignableTo)}`";