/// <summary>Get all the children view of a given view.</summary>
        public static ScriptableObject[] GetAllViewChildren(ScriptableObject view)
        {
            if (!view)
            {
                return(new ScriptableObject[0]);
            }

            view.EnsureOfType(Types.View);

            return(view.GetPropertyValue <Array>("allChildren")
                   .Cast <ScriptableObject>()
                   .ToArray());
        }
        /// <summary>Returns all the parents of a given view.</summary>
        public static ScriptableObject[] GetViewHierarchy(ScriptableObject view)
        {
            if (!view)
            {
                return(new ScriptableObject[0]);
            }

            view.EnsureOfType(Types.View);

            var list = new List <ScriptableObject>()
            {
                view
            };
            var parent = view.GetPropertyValue <ScriptableObject>("parent");

            while (parent)   // Get the least specific view
            {
                view = parent;
                list.Add(view);
                parent = view.GetPropertyValue <ScriptableObject>("parent");
            }

            return(list.ToArray());
        }
예제 #3
0
        /// <summary>Create a new instance and automatically assigns the window, view and container.</summary>
        public ViewPyramid(ScriptableObject viewOrWindow)
        {
            if (!viewOrWindow)
            {
                m_window    = null;
                m_view      = null;
                m_container = null;
            }
            else if (viewOrWindow.IsOfType(typeof(EditorWindow)))
            {
                m_window    = viewOrWindow as EditorWindow;
                m_view      = m_window.GetFieldValue <View>("m_Parent");
                m_container = m_view.GetPropertyValue <ContainerWindow>("window");
            }
            else if (viewOrWindow.IsOfType(Types.View))
            {
                m_window    = null;
                m_view      = viewOrWindow;
                m_container = m_view.GetPropertyValue <ContainerWindow>("window");
            }
            else if (viewOrWindow.IsOfType(Types.ContainerWindow))
            {
                m_window    = null;
                m_view      = viewOrWindow.GetPropertyValue <ContainerWindow>("rootView");
                m_container = viewOrWindow;
            }
            else
            {
                throw new ArgumentException("Param must be of type EditorWindow, View or ContainerWindow", "viewOrWindow");
            }

            if (!m_window && m_view && m_view.IsOfType(Types.HostView))
            {
                m_window = m_view.GetPropertyValue <EditorWindow>("actualView");
            }

            m_windowInstanceID    = m_window ? m_window.GetInstanceID() : 0;
            m_viewInstanceID      = m_view ? m_view.GetInstanceID() : 0;
            m_containerInstanceID = m_container ? m_container.GetInstanceID() : 0;
        }