Exemple #1
0
        private bool DrawField()
        {
            using (gui.Horizontal())
            {
                var    isEmpty = string.IsNullOrEmpty(niceName);
                var    display = isEmpty ? string.Empty : niceName + " " + (foldout ? "^" : ">");
                var    value   = member.Value;
                string field;

                if (value == null)
                {
                    field = nullString;
                }
                else
                {
                    if (isToStringImpl)
                    {
                        field = value.ToString();
                    }
                    else
                    {
                        field = string.Format("{0} ({1})", value.ToString(), value.GetType().GetNiceName());
                    }
                }

                if (isEmpty)
                {
                    Foldout();
                }

                gui.Text(display, field);

                var fieldRect = gui.LastRect;
                gui.Cursor(fieldRect, MouseCursor.Link);
                if (!isEmpty && fieldRect.Contains(Event.current.mousePosition))
                {
                    if (EventsHelper.IsLMBMouseDown())
                    {
                        foldout = !foldout;
                    }
                }

                var drop = gui.RegisterFieldForDrop <UnityObject>(fieldRect, objs => objs.Select(x =>
                {
                    if (x == null)
                    {
                        return(null);
                    }

                    var go = x as GameObject;
                    if (go != null)
                    {
                        return(go.GetComponent(memberType));
                    }

                    return(x.GetType().IsA(memberType) ? x : null);
                }).FirstOrDefault());

                if (drop != null)
                {
                    value = memberValue = drop;
                }

                SelectionButton();
            }

            return(foldout);
        }