コード例 #1
0
    public void Render(UTFieldWrapper fieldWrapper)
    {
        Type baseType        = fieldWrapper.InspectorHint.baseType;
        var  compatibleTypes = UTComponentScanner.FindCompatibleTypes(baseType);

        var val          = (UTMemberInfo)fieldWrapper.Value;
        int currentIndex = -1;

        if (val != null)
        {
            currentIndex = Array.IndexOf(compatibleTypes.TypeNames, val.TypeName);
        }
        EditorGUILayout.BeginVertical();
        int newIndex = -1;

        if (fieldWrapper.Label != null)
        {
            newIndex = EditorGUILayout.Popup(fieldWrapper.Label, currentIndex, compatibleTypes.NicifiedTypeNames);
        }
        else
        {
            newIndex = EditorGUILayout.Popup(currentIndex, compatibleTypes.NicifiedTypeNames);
        }

        if (currentIndex != newIndex)
        {
            if (newIndex == -1)
            {
                fieldWrapper.Value = null;
                val = null;
            }
            else
            {
                var    type            = UTInternalCall.GetType(compatibleTypes.TypeNames [newIndex]);
                var    writableMembers = UTComponentScanner.FindPublicWritableMembersOf(type);
                string propertyPath    = null;
                if (writableMembers.MemberInfos.Length > 0)
                {
                    propertyPath = writableMembers.MemberInfos[0].Name;
                }
                val = new UTMemberInfo(type.FullName, propertyPath);
                fieldWrapper.Value = val;
            }
        }

        GUI.enabled = val != null && !string.IsNullOrEmpty(val.TypeName);
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel(" ");
        if (GUILayout.Button(val.FieldPath, EditorStyles.popup))
        {
            var genericMenu = BuildMenu(val.Type, val.SetFieldPath);
            genericMenu.ShowAsContext();
        }
        EditorGUILayout.EndHorizontal();
        GUI.enabled = true;

        EditorGUILayout.EndVertical();
    }
コード例 #2
0
    public void Render(UTFieldWrapper fieldWrapper)
    {
        Type baseType = fieldWrapper.InspectorHint.baseType;
        var compatibleTypes = UTComponentScanner.FindCompatibleTypes (baseType);

        var val = (UTMemberInfo)fieldWrapper.Value;
        int currentIndex = -1;
        if (val != null) {
            currentIndex = Array.IndexOf (compatibleTypes.TypeNames, val.TypeName);
        }
        EditorGUILayout.BeginVertical ();
        int newIndex = -1;
        if (fieldWrapper.Label != null) {
            newIndex = EditorGUILayout.Popup (fieldWrapper.Label, currentIndex, compatibleTypes.NicifiedTypeNames);
        } else {
            newIndex = EditorGUILayout.Popup (currentIndex, compatibleTypes.NicifiedTypeNames);
        }

        if (currentIndex != newIndex) {
            if (newIndex == -1) {
                fieldWrapper.Value = null;
                val = null;
            } else {
                var type = UTInternalCall.GetType (compatibleTypes.TypeNames [newIndex]);
                var writableMembers = UTComponentScanner.FindPublicWritableMembersOf(type);
                string propertyPath = null;
                if (writableMembers.MemberInfos.Length > 0) {
                    propertyPath = writableMembers.MemberInfos[0].Name;
                }
                val = new UTMemberInfo (type.FullName, propertyPath);
                fieldWrapper.Value = val;
            }
        }

        GUI.enabled = val != null && !string.IsNullOrEmpty(val.TypeName);
        EditorGUILayout.BeginHorizontal ();
        EditorGUILayout.PrefixLabel (" ");
        if (GUILayout.Button (val.FieldPath, EditorStyles.popup)) {
            var genericMenu = BuildMenu (val.Type, val.SetFieldPath);
            genericMenu.ShowAsContext ();
        }
        EditorGUILayout.EndHorizontal ();
        GUI.enabled = true;

        EditorGUILayout.EndVertical ();
    }