예제 #1
0
        private void ResolveMethodTooltip(MethodBase methodBase, int numOfOverload, List <GUIContent> contents)
        {
            if (methodBase is MethodInfo)
            {
                contents.Add(new GUIContent(
                                 EditorReflectionUtility.GetOverloadingMethodNames(methodBase as MethodInfo),
                                 uNodeEditorUtility.GetIcon(methodBase)));
            }
            else if (methodBase is ConstructorInfo)
            {
                contents.Add(new GUIContent(
                                 EditorReflectionUtility.GetOverloadingConstructorNames(methodBase as ConstructorInfo),
                                 uNodeEditorUtility.GetIcon(methodBase)));
            }
            var mType = ReflectionUtils.GetMemberType(methodBase);

            #region Docs
            if (uNodePreference.GetPreference().showDocumentation&& XmlDoc.hasLoadDoc)
            {
                XmlElement documentation = XmlDoc.XMLFromMember(methodBase);
                if (documentation != null)
                {
                    contents.Add(new GUIContent("Documentation ▼ " + documentation["summary"].InnerText.Trim().AddLineInFirst()));
                }
                var parameters = methodBase.GetParameters();
                if (parameters.Length > 0)
                {
                    for (int x = 0; x < parameters.Length; x++)
                    {
                        Type PType = parameters[x].ParameterType;
                        if (PType != null)
                        {
                            contents.Add(new GUIContent(parameters[x].Name + " : " +
                                                        uNodeUtility.GetDisplayName(PType),
                                                        uNodeEditorUtility.GetTypeIcon(PType)));
                            if (documentation != null && documentation["param"] != null)
                            {
                                XmlNode paramDoc = null;
                                XmlNode doc      = documentation["param"];
                                while (doc.NextSibling != null)
                                {
                                    if (doc.Attributes["name"] != null && doc.Attributes["name"].Value.Equals(parameters[x].Name))
                                    {
                                        paramDoc = doc;
                                        break;
                                    }
                                    doc = doc.NextSibling;
                                }
                                if (paramDoc != null && !string.IsNullOrEmpty(paramDoc.InnerText))
                                {
                                    contents.Add(new GUIContent(paramDoc.InnerText.Trim()));
                                }
                            }
                        }
                    }
                }
            }
            #endregion
            //contents.Add(new GUIContent("Return	: " + mType.PrettyName(true), uNodeEditorUtility.GetTypeIcon(mType)));
            if (numOfOverload > 0)
            {
                contents.Add(new GUIContent("▲ " + (overrideIndex + 1).ToString() + " of " + numOfOverload + " ▼"));
            }
        }
예제 #2
0
        public override void OnGUI(Rect rect)
        {
            base.OnGUI(rect);
            if (Event.current.type == EventType.MouseEnterWindow || Event.current.type == EventType.MouseLeaveWindow)
            {
                if (tooltipWindow != null)
                {
                    tooltipWindow.Close();
                }
            }
            if (Event.current.type == EventType.Repaint)
            {
                if (hoverItem != null && lastHoverItem != hoverItem)
                {
                    List <GUIContent> contents = new List <GUIContent>();
                    if (hoverItem is TypeTreeView)
                    {
                        if (uNodePreference.GetPreference().showDocumentation&& XmlDoc.hasLoadDoc)
                        {
                            TypeTreeView item = hoverItem as TypeTreeView;

                            Texture icon = uNodeEditorUtility.GetIcon(item.type);
                            contents.Add(new GUIContent(item.displayName, icon));
                            contents.Add(new GUIContent("Target	: " + item.type.MemberType.ToString()));
                            contents.Add(new GUIContent("Type	: "+ item.type.PrettyName(true), uNodeEditorUtility.GetTypeIcon(item.type)));
                            XmlElement documentation = XmlDoc.XMLFromType(item.type);
                            if (documentation != null)
                            {
                                contents.Add(new GUIContent("<b>Documentation</b> ▼ " + documentation["summary"].InnerText.Trim().AddLineInFirst()));
                            }
                        }
                    }
                    else if (hoverItem is MemberTreeView)
                    {
                        var     item = hoverItem as MemberTreeView;
                        Texture icon = uNodeEditorUtility.GetIcon(item.member);
                        contents.Add(new GUIContent(item.displayName, icon));
                        contents.Add(new GUIContent("Target	: " + item.member.MemberType.ToString()));
                        contents.Add(new GUIContent("Static	: " + ReflectionUtils.GetMemberIsStatic(item.member)));
                        if (item.member != null)
                        {
                            var mType = ReflectionUtils.GetMemberType(item.member);
                            contents.Add(new GUIContent("Return	: " + mType.PrettyName(true), uNodeEditorUtility.GetTypeIcon(mType)));
                        }
                        if (uNodePreference.GetPreference().showDocumentation&& XmlDoc.hasLoadDoc)
                        {
                            XmlElement documentation = XmlDoc.XMLFromMember(item.member);
                            if (documentation != null)
                            {
                                contents.Add(new GUIContent("<b>Documentation ▼</b> " + documentation["summary"].InnerText.Trim().AddLineInFirst()));
                            }
                            switch (item.member.MemberType)
                            {
                            case MemberTypes.Method:
                            case MemberTypes.Constructor:
                                var parameters = (item.member as MethodBase).GetParameters();
                                if (parameters.Length > 0)
                                {
                                    for (int x = 0; x < parameters.Length; x++)
                                    {
                                        System.Type PType = parameters[x].ParameterType;
                                        if (PType != null)
                                        {
                                            contents.Add(new GUIContent("<b>" + parameters[x].Name + " : " + PType.PrettyName() + "</b>",
                                                                        uNodeEditorUtility.GetTypeIcon(PType)));
                                            if (documentation != null && documentation["param"] != null)
                                            {
                                                XmlNode paramDoc = null;
                                                XmlNode doc      = documentation["param"];
                                                while (doc.NextSibling != null)
                                                {
                                                    if (doc.Attributes["name"] != null && doc.Attributes["name"].Value.Equals(parameters[x].Name))
                                                    {
                                                        paramDoc = doc;
                                                        break;
                                                    }
                                                    doc = doc.NextSibling;
                                                }
                                                if (paramDoc != null && !string.IsNullOrEmpty(paramDoc.InnerText))
                                                {
                                                    contents.Add(new GUIContent(paramDoc.InnerText.Trim()));
                                                }
                                            }
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                    if (contents.Count > 0)
                    {
                        var position = window.position;
                        if (position.x + position.width + 300 <= Screen.currentResolution.width)
                        {
                            tooltipWindow = TooltipWindow.Show(new Vector2(position.x + position.width, position.y), contents, 300, 600);
                        }
                        else
                        {
                            tooltipWindow = TooltipWindow.Show(new Vector2(position.x - 300, position.y), contents, 300, 600);
                        }
                    }
                    else if (tooltipWindow != null)
                    {
                        tooltipWindow.Close();
                    }
                    lastHoverItem = hoverItem;
                }
            }
        }
예제 #3
0
        void InitMultipurposeMember(FieldInfo field)
        {
            MultipurposeMember member = field.GetValueOptimized(data.block) as MultipurposeMember;

            object[] fieldAttribute = field.GetCustomAttributes(true);
            if (!ReflectionUtils.TryCorrectingAttribute(data.block, ref fieldAttribute))
            {
                return;
            }
            if (member == null)
            {
                member = new MultipurposeMember();
                field.SetValueOptimized(data.block, member);
                Repaint();
            }
            if (member.target == null || member.target.isTargeted && member.target.IsTargetingPinOrNode)
            {
                var filter = ReflectionUtils.GetAttribute <FilterAttribute>(fieldAttribute) ?? new FilterAttribute()
                {
                    MaxMethodParam = int.MaxValue,
                };
                var port = AddPort(new PortData()
                {
                    getPortName    = () => field.Name,
                    getPortType    = () => typeof(MemberData),
                    getPortValue   = () => member.target,
                    filter         = filter,
                    onValueChanged = (obj) => {
                        var val = obj as MemberData;
                        RegisterUndo();
                        if (member.target.targetType != val.targetType || val.targetType != MemberData.TargetType.Values)
                        {
                            member.target = val;
                            owner.nodeView.MarkRepaint();
                            MemberDataUtility.UpdateMultipurposeMember(member);
                        }
                        else
                        {
                            member.target = val;
                        }
                        field.SetValueOptimized(data.block, member);
                        Repaint();
                    },
                });
                var control = port.portData.InstantiateControl(true);
                control.HideInstance(true);
                port.Add(new ControlView(control, true));
                //ControlConfig config = new ControlConfig() {
                //	owner = owner,
                //	value = member.target,
                //	type = typeof(MemberData),
                //	filter = filter,
                //	onValueChanged = (obj) => {
                //		var val = obj as MemberData;
                //		RegisterUndo();
                //		if(member.target.targetType != val.targetType || val.targetType != MemberData.TargetType.Values) {
                //			member.target = val;
                //			owner.MarkRepaint();
                //			uNodeEditorUtility.UpdateMultipurposeMember(member);
                //		} else {
                //			member.target = val;
                //		}
                //		field.SetValue(data.actionEvent, member);
                //		Repaint();
                //	},
                //};
                //MemberControl control = new MemberControl(config, true);
                //AddControl(field.Name, new ControlView(control, true));
            }
            if (member.target.isTargeted)
            {
                if (member.target.targetType != MemberData.TargetType.Values)
                {
                    if (!member.target.isStatic &&
                        (!member.target.IsTargetingUNode || !uNodePreference.GetPreference().hideUNodeInstance) &&
                        member.target.targetType != MemberData.TargetType.Type &&
                        member.target.targetType != MemberData.TargetType.Null)
                    {
                        MemberDataUtility.UpdateMemberInstance(member.target, member.target.startType);
                        var port = AddPort(new PortData()
                        {
                            portID         = "Instance",
                            getPortName    = () => "Instance",
                            getPortType    = () => member.target.startType,
                            getPortValue   = () => member.target?.instance,
                            filter         = new FilterAttribute(member.target.startType),
                            onValueChanged = (o) => {
                                RegisterUndo();
                                member.target.instance = o;
                                field.SetValueOptimized(data.block, member);
                            },
                        });
                        port.Add(new ControlView(port.portData.InstantiateControl(true), true));
                    }
                    else if (!uNodePreference.GetPreference().hideUNodeInstance&&
                             member.target.IsTargetingUNode && !member.target.IsTargetingNode)
                    {
                        MemberDataUtility.UpdateMemberInstance(member.target, member.target.startType);
                        var port = AddPort(new PortData()
                        {
                            portID         = "Instance",
                            getPortName    = () => "",
                            getPortType    = () => typeof(uNodeRoot),
                            getPortValue   = () => member.target?.instance,
                            filter         = new FilterAttribute(typeof(uNodeRoot)),
                            onValueChanged = (o) => {
                                RegisterUndo();
                                member.target.instance = o;
                                field.SetValueOptimized(data.block, member);
                            },
                        });
                        port.Add(new ControlView(port.portData.InstantiateControl(true), true));
                    }
                }
                if (member.target.SerializedItems?.Length > 0)
                {
                    MemberInfo[] members = null;
                    if (uNodePreference.GetPreference().inEditorDocumentation)
                    {
                        members = member.target.GetMembers(false);
                        if (members != null && members.Length > 0 && members.Length + 1 != member.target.SerializedItems.Length)
                        {
                            members = null;
                        }
                    }
                    uNodeFunction objRef = null;
                    switch (member.target.targetType)
                    {
                    case MemberData.TargetType.uNodeFunction: {
                        uNodeRoot root = member.target.GetInstance() as uNodeRoot;
                        if (root != null)
                        {
                            var gTypes = member.target.GenericTypes[0];
                            objRef = root.GetFunction(member.target.startName, gTypes != null ? gTypes.Length : 0, member.target.ParameterTypes[0]);
                        }
                        break;
                    }
                    }
                    int  totalParam = 0;
                    bool flag       = false;
                    for (int i = 0; i < member.target.SerializedItems.Length; i++)
                    {
                        if (i != 0)
                        {
                            if (members != null && (member.target.isDeepTarget || !member.target.IsTargetingUNode))
                            {
                                MemberInfo mData = members[i - 1];
                                if (mData is MethodInfo || mData is ConstructorInfo)
                                {
                                    var method     = mData as MethodInfo;
                                    var parameters = method != null?method.GetParameters() : (mData as ConstructorInfo).GetParameters();

                                    if (parameters.Length > 0)
                                    {
                                        totalParam++;
                                        if (totalParam > 1)
                                        {
                                            flag = true;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    totalParam = 0;
                    int methodDrawCount = 1;
                    for (int i = 0; i < member.target.SerializedItems.Length; i++)
                    {
                        if (i != 0)
                        {
                            if (members != null && (member.target.isDeepTarget || !member.target.IsTargetingUNode))
                            {
                                MemberInfo memberInfo = members[i - 1];
                                if (memberInfo is MethodInfo || memberInfo is ConstructorInfo)
                                {
                                    var method        = memberInfo as MethodInfo;
                                    var documentation = XmlDoc.XMLFromMember(memberInfo);
                                    if (flag)
                                    {
                                        AddControl(memberInfo.Name, null);
                                    }
                                    var parameters = method != null?method.GetParameters() : (memberInfo as ConstructorInfo).GetParameters();

                                    if (parameters.Length > 0)
                                    {
                                        while (parameters.Length + totalParam > member.parameters.Length)
                                        {
                                            ArrayUtility.Add(ref member.parameters, MemberData.empty);
                                        }
                                        for (int x = 0; x < parameters.Length; x++)
                                        {
                                            var parameter = parameters[x];
                                            if (parameter.ParameterType != null)
                                            {
                                                int index = totalParam;
                                                var param = member.parameters[index];
                                                var port  = AddPort(new PortData()
                                                {
                                                    getPortName    = () => ObjectNames.NicifyVariableName(parameter.Name),
                                                    getPortType    = () => parameter.ParameterType,
                                                    getPortValue   = () => param,
                                                    filter         = new FilterAttribute(parameter.ParameterType),
                                                    onValueChanged = (obj) => {
                                                        RegisterUndo();
                                                        param = obj as MemberData;
                                                        member.parameters[index] = param;
                                                        field.SetValueOptimized(data.block, member);
                                                        Repaint();
                                                    },
                                                });
                                                port.Add(new ControlView(port.portData.InstantiateControl(true), true));
                                            }
                                            totalParam++;
                                        }
                                        continue;
                                    }
                                }
                            }
                        }
                        System.Type[] paramsType = member.target.ParameterTypes[i];
                        if (paramsType != null && paramsType.Length > 0)
                        {
                            if (flag)
                            {
                                AddControl("Method " + (methodDrawCount), null);
                                methodDrawCount++;
                            }
                            while (paramsType.Length + totalParam > member.parameters.Length)
                            {
                                ArrayUtility.Add(ref member.parameters, MemberData.none);
                            }
                            for (int x = 0; x < paramsType.Length; x++)
                            {
                                System.Type PType = paramsType[x];
                                if (member.parameters[totalParam] == null)
                                {
                                    member.parameters[totalParam] = MemberData.none;
                                }
                                if (PType != null)
                                {
                                    int    index = totalParam;
                                    var    param = member.parameters[index];
                                    string pLabel;
                                    if (objRef != null)
                                    {
                                        pLabel = objRef.parameters[x].name;
                                    }
                                    else
                                    {
                                        pLabel = "P" + (x + 1);
                                    }
                                    var port = AddPort(new PortData()
                                    {
                                        getPortName    = () => ObjectNames.NicifyVariableName(pLabel),
                                        getPortType    = () => PType,
                                        getPortValue   = () => param,
                                        filter         = new FilterAttribute(PType),
                                        onValueChanged = (obj) => {
                                            RegisterUndo();
                                            param = obj as MemberData;
                                            member.parameters[index] = param;
                                            field.SetValueOptimized(data.block, member);
                                            Repaint();
                                        },
                                    });
                                    port.Add(new ControlView(port.portData.InstantiateControl(true), true));
                                }
                                totalParam++;
                            }
                        }
                    }
                    while (member.parameters.Length > totalParam)
                    {
                        ArrayUtility.RemoveAt(ref member.parameters, member.parameters.Length - 1);
                    }
                }
            }
        }