Exemplo n.º 1
0
        public List <ObjectNode> BuildSelectableObjectsList(IEnumerable <InterfaceableContainerPropertyDrawer.SelectableObject> selectableObjects, Object selectedObject, out bool selectingProjectAssets)
        {
            selectingProjectAssets = false;

            _rootNodes   = new List <ObjectNode>();
            _parentNodes = new Dictionary <Object, ObjectNode>();

            foreach (var selectableObject in selectableObjects)
            {
                if (selectedObject == selectableObject.Object)
                {
                    selectingProjectAssets = selectableObject.IsProjectAsset;
                }

                var selectableObjectNode = new ObjectNode
                {
                    Object   = selectableObject.Object,
                    NodeName = InterfaceableGUIHelper.GetObjectName(selectableObject.Object),

                    IsSelectable   = true,
                    IsPingable     = !selectableObject.IsComponent && InterfaceableGUIHelper.IsPingable(selectableObject.Object),
                    IsProjectAsset = selectableObject.IsProjectAsset,
                };

                if (selectableObject.IsComponent)
                {
                    selectableObjectNode.Parent = GetOrCreateParentNode(selectableObjectNode);
                }
                else
                {
                    _rootNodes.Add(selectableObjectNode);
                }
            }

            var missingParents = _parentNodes.Values.Where(n => n.Parent == null && !_rootNodes.Contains(n)).ToList();

            _rootNodes.AddRange(missingParents);
            var @return = SortedNodes(_rootNodes);

            _parentNodes.Clear();
            _rootNodes.Clear();

            return(@return);
        }
Exemplo n.º 2
0
        private ObjectNode GetOrCreateParentNode(ObjectNode childNode)
        {
            GameObject parent = null;

            var component = childNode.Object as Component;

            if (component != null)
            {
                parent = component.gameObject;
            }
            else
            {
                var gameobject = childNode.Object as GameObject;
                if (gameobject != null && gameobject.transform.parent != null)
                {
                    parent = gameobject.transform.parent.gameObject;
                }
            }

            if (parent != null)
            {
                ObjectNode parentNode;
                if (!_parentNodes.TryGetValue(parent, out parentNode))
                {
                    parentNode = new ObjectNode
                    {
                        Object         = parent,
                        IsSelectable   = false,
                        IsPingable     = InterfaceableGUIHelper.IsPingable(parent),
                        IsProjectAsset = InterfaceableGUIHelper.IsProjectAsset(parent),
                        NodeName       = InterfaceableGUIHelper.GetObjectName(parent)
                    };
                    _parentNodes.Add(parent, parentNode);
                    parentNode.Parent = GetOrCreateParentNode(parentNode);
                }
                parentNode.Children.Add(childNode);

                return(parentNode);
            }

            return(null);
        }
    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));
            }
        });
    }