public void GetContainerContents(Rect rect, bool droppingFor, out GUIContentRect iconContent, out GUIContentRect labelContent)
        {
            Texture icon;
            string  resultString, resultTip;

            if (ObjectFieldProperty.hasMultipleDifferentValues)
            {
                icon         = null;
                resultString = "-";
                resultTip    = null;
            }
            else
            {
                var @object = ObjectField;
                if (InterfaceableGUIHelper.IsProjectAsset(@object) && (@object is Component || @object is GameObject))
                {
                    icon = EditorGUIUtility.FindTexture("PrefabNormal Icon");
                }
                else
                {
                    icon = EditorGUIUtility.ObjectContent(@object, null).image;
                }

                resultString = resultTip = BuildEditorResultString(ResultType, ObjectField);
                if (resultString == null)
                {
                    resultString = "null";
                }
            }

            iconContent  = icon == null ? new GUIContentRect(null, rect) : new GUIContentRect(new GUIContent(icon, resultTip), rect);
            labelContent = new GUIContentRect(new GUIContent(resultString, !droppingFor ? resultTip : null), rect);
        }
Exemplo n.º 2
0
        private void DrawControls(GUIStyle style, GUIContentRect nodeGUI, GUIContentRect foldoutGUI, GUIContentRect iconGUI, GUIContentRect nameGUI)
        {
            style = DetermineObjectStyle(style, _objectNode, _serializedContainer.ObjectField);
            GUI.Label(nodeGUI, _displayFoldout ? foldoutGUI : nodeGUI, style);

            style.normal.background = null;
            if (iconGUI.Content != null)
            {
                GUI.Label(iconGUI, iconGUI, style);
            }
            GUI.Label(nameGUI, nameGUI, style);
        }
Exemplo n.º 3
0
        private void CreateContentRects(GUIStyle style, int indentLevel, out GUIContentRect nodeGUI, out GUIContentRect foldoutGUI, out GUIContentRect iconGUI, out GUIContentRect labelGUI)
        {
            GUIContent iconContent, labelContent;
            var        foldoutContent = GetFoldoutContent(indentLevel);

            GetObjectNodeContents(_objectNode, out iconContent, out labelContent);

            nodeGUI    = new GUIContentRect(GUIContent.none, GUILayoutUtility.GetRect(foldoutContent, style));
            foldoutGUI = new GUIContentRect(foldoutContent, nodeGUI);
            iconGUI    = new GUIContentRect(iconContent, nodeGUI);
            labelGUI   = new GUIContentRect(labelContent, nodeGUI);

            foldoutGUI.SetWidth(InterfaceableGUIHelper.GetMinWidth(foldoutContent, style) + 2.0f);

            iconGUI.MoveNextTo(foldoutGUI);
            iconGUI.SetWidth(iconContent == null ? 0.0f : (InterfaceableGUIHelper.GetScaledTextureWidth(iconContent.image, foldoutGUI.Rect.height, style) + 2.0f));

            labelGUI.MoveNextTo(iconGUI);
            labelGUI.SetWidth(InterfaceableGUIHelper.GetMinWidth(labelContent, style));
        }
    private static void DrawInterfaceableContainer <TResult>(Rect position, GUIContent label, SerializedContainer serializedContainer)
        where TResult : class
    {
        _currentEvent = Event.current;
        var resultTypeName = NeverLab.Interfaceable.InterfaceableContainerBase.ConstructResolvedName(CachedType <TResult> .Type);

        if (string.IsNullOrEmpty(label.tooltip))
        {
            label.tooltip = resultTypeName;
        }
        var labelRect = new GUIContentRect(label, position);

        labelRect.SetWidth(EditorGUIUtility.labelWidth);

        var resultRect = new GUIContentRect(null, position);

        resultRect.MoveNextTo(labelRect);
        resultRect.Rect.xMax -= (ButtonSpace + ButtonWidth) * 2;

        var nullButonRect = new GUIContentRect(null, position);

        nullButonRect.MoveNextTo(resultRect, ButtonSpace);
        nullButonRect.SetWidth(ButtonWidth);

        var listButtonRect = new GUIContentRect(null, position);

        listButtonRect.MoveNextTo(nullButonRect, ButtonSpace);
        listButtonRect.SetWidth(ButtonWidth);

        var isProjectAsset = serializedContainer.IsProjectAsset;
        var pingable       = !serializedContainer.ObjectFieldProperty.hasMultipleDifferentValues && InterfaceableGUIHelper.IsPingable(serializedContainer.ObjectField);
        var dragDropResult = GetDragAndDropResult <TResult>(resultRect, isProjectAsset, serializedContainer);

        EditorGUI.LabelField(labelRect, label);
        InterfaceableGUIHelper.EnabledBlock(() =>
        {
            GUI.enabled = pingable;

            InterfaceableGUIHelper.ColorBlock(() =>
            {
                if (serializedContainer.Selecting || serializedContainer.Dropping)
                {
                    GUI.color = new Color(1, 1, 1, 2);
                }
                else
                {
                    GUI.color = pingable ? new Color(1, 1, 1, 2) : Color.white;
                }

                DrawField(serializedContainer, resultRect, pingable);
            });
        });

        if (dragDropResult != null)
        {
            serializedContainer.ObjectField = dragDropResult as Object;
            GUI.changed = true;
        }

        if (GUI.Button(nullButonRect, new GUIContent("○", "Set to null"), InterfaceableGUIHelper.InspectorStyles.NullOutButton))
        {
            serializedContainer.ObjectField = null;
        }

        InterfaceableGUIHelper.EnabledBlock(() =>
        {
            if (GUI.Button(listButtonRect, new GUIContent("◉", "Select from list"), InterfaceableGUIHelper.InspectorStyles.SelectFromListButton))
            {
                _selectWindow = InterfaceableContainerSelectWindow.ShowSelectWindow(resultTypeName, isProjectAsset, serializedContainer, GetSelectable <TResult>(isProjectAsset));
            }
        });
    }
        private void DrawControls(GUIStyle style, GUIContentRect nodeGUI, GUIContentRect foldoutGUI, GUIContentRect iconGUI, GUIContentRect nameGUI)
        {
            style = DetermineObjectStyle(style, _objectNode, _serializedContainer.ObjectField);
            GUI.Label(nodeGUI, _displayFoldout ? foldoutGUI : nodeGUI, style);

            style.normal.background = null;
            if(iconGUI.Content != null)
            {
                GUI.Label(iconGUI, iconGUI, style);
            }
            GUI.Label(nameGUI, nameGUI, style);
        }
        private void CreateContentRects(GUIStyle style, int indentLevel, out GUIContentRect nodeGUI, out GUIContentRect foldoutGUI, out GUIContentRect iconGUI, out GUIContentRect labelGUI)
        {
            GUIContent iconContent, labelContent;
            var foldoutContent = GetFoldoutContent(indentLevel);
            GetObjectNodeContents(_objectNode, out iconContent, out labelContent);

            nodeGUI = new GUIContentRect(GUIContent.none, GUILayoutUtility.GetRect(foldoutContent, style));
            foldoutGUI = new GUIContentRect(foldoutContent, nodeGUI);
            iconGUI = new GUIContentRect(iconContent, nodeGUI);
            labelGUI = new GUIContentRect(labelContent, nodeGUI);

            foldoutGUI.SetWidth(IUnifiedGUIHelper.GetMinWidth(foldoutContent, style) + 2.0f);

            iconGUI.MoveNextTo(foldoutGUI);
            iconGUI.SetWidth(iconContent == null ? 0.0f : (IUnifiedGUIHelper.GetScaledTextureWidth(iconContent.image, foldoutGUI.Rect.height, style) + 2.0f));

            labelGUI.MoveNextTo(iconGUI);
            labelGUI.SetWidth(IUnifiedGUIHelper.GetMinWidth(labelContent, style));
        }