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);
        }
    private static TResult GetDragAndDropResult <TResult>(Rect dropArea, bool selectingForProjectAsset, SerializedContainer serializedContainer)
        where TResult : class
    {
        TResult result   = null;
        bool?   dropping = null;

        switch (_currentEvent.rawType)
        {
        case EventType.DragExited:
        case EventType.DragUpdated:
        case EventType.DragPerform:
            dropping = false;
            if (!serializedContainer.MouseInRects(dropArea, _currentEvent.mousePosition))
            {
                break;
            }

            var single = DragAndDrop.objectReferences.SelectMany(o => GetObjectImplementationsOf <TResult>(o)).FirstOrDefault();
            if (single != null)
            {
                var singleObject = single as Object;
                if (singleObject != null && (!selectingForProjectAsset || InterfaceableGUIHelper.IsProjectAsset(singleObject)))
                {
                    dropping = true;
                }
            }
            DragAndDrop.visualMode = SerializedContainer.AnyDropping ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected;

            if (_currentEvent.type == EventType.DragPerform)
            {
                DragAndDrop.AcceptDrag();
                _currentEvent.Use();
                dropping = false;
                result   = single;
            }
            break;
        }

        if (dropping != null)
        {
            serializedContainer.SetDropping(dropping.Value);
        }

        return(result);
    }
Example #3
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 SelectableObject(Object @object)
 {
     Object         = @object;
     IsProjectAsset = InterfaceableGUIHelper.IsProjectAsset(Object);
     IsComponent    = Object is Component;
 }