Exemplo n.º 1
0
        void DrawProviderPreview(Rect position, ReceiverLinkerItem linkerItem, ReceiverMethod method, Type receiverType, MonoBehaviour targetObject)
        {
            var controlPosition = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(" "));

            IDataProviderObject provider = null;

            if (receiverType != null)
            {
                provider = ReceiverComponentBuilder.FindProvider(targetObject, receiverType, ReceiverComponentBuilder.TypeDataProviderObject);
            }

            if (provider != null)
            {
                GUI.enabled = false;
                EditorGUI.ObjectField(
                    new Rect(controlPosition.x, controlPosition.y, controlPosition.width, EditorGUIUtility.singleLineHeight),
                    provider as Component,
                    typeof(Component),
                    true
                    );
                GUI.enabled = true;
            }
            else
            {
                var style = new GUIStyle();
                style.normal.textColor = Color.red;
                EditorGUI.LabelField(
                    new Rect(controlPosition.x, controlPosition.y, controlPosition.width, EditorGUIUtility.singleLineHeight),
                    "Provider not found!",
                    style
                    );
            }
        }
Exemplo n.º 2
0
 public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
 {
     if (property.serializedObject.isEditingMultipleObjects)
     {
         return(0);
     }
     return(2 * EditorGUIUtility.singleLineHeight * ReceiverMethod.GetAll(property.serializedObject.targetObject).Count);
 }
Exemplo n.º 3
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (property.serializedObject.isEditingMultipleObjects)
            {
                return;
            }

            EditorGUI.BeginProperty(position, label, property);

            var linker  = new ReceiverLinker();
            var members = property.FindPropertyRelative(nameof(linker.Members));

            var accessorList = new List <ReceiverLinkerItem>();

            {
                for (int i = 0; i < members.arraySize; i++)
                {
                    accessorList.Add(LoadObject(members.GetArrayElementAtIndex(i)));
                }
            }

            members.ClearArray();

            var targetObject     = property.serializedObject.targetObject as MonoBehaviour;
            var targetObjectType = targetObject.GetType();

            foreach (var method in ReceiverMethod.GetAll(targetObject))
            {
                var option = DrawProviderOptions(position, accessorList.Find(item => item.Receiver == method.Name), method, targetObject);
                position.y += EditorGUIUtility.singleLineHeight;

                var linkerItem = new ReceiverLinkerItem();
                linkerItem.Receiver     = method.Name;
                linkerItem.ReceiverType = option.ReceiverTypeName;
                linkerItem.Path         = option.Path;

                if (!string.IsNullOrEmpty(option.ReceiverTypeName))
                {
                    int size = members.arraySize;
                    members.InsertArrayElementAtIndex(size);
                    var obj = members.GetArrayElementAtIndex(size);
                    SaveObject(obj, linkerItem);
                }
                if (linkerItem.ReceiverType != ReceiverLinker.IgnoreReceiver)
                {
                    DrawProviderPreview(position, linkerItem, method, option.ReceiverType, targetObject);
                }
                position.y += EditorGUIUtility.singleLineHeight;
            }

            EditorGUI.EndProperty();
        }
Exemplo n.º 4
0
        PopupOption DrawProviderOptions(Rect position, ReceiverLinkerItem linkerItem, ReceiverMethod method, object targetObject)
        {
            var controlPosition = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(CleanMethodName(method.Name)));

            var options = new List <PopupOption>
            {
                // None-option
                new PopupOption(receiverTypeName: ReceiverLinker.IgnoreReceiver),
                // Automatic option where the receiver type is the parameter type
                new PopupOption(method.Type, receiverTypeName: "")
            };

            options.AddRange(GetOptions(targetObject, method.Type));

            var guiOptions = options.ConvertAll(option => option.PopupString);
            //guiOptions[0] = "<none>";

            var selectedIndex = options.FindIndex(option => option.MatchesLinker(linkerItem));

            if (selectedIndex < 0)
            {
                // Can happen if class or method name is changed
                selectedIndex = options.Count;
                options.Add(new PopupOption(path: linkerItem.Path.Split('/'), receiverTypeName: linkerItem.ReceiverType));
                guiOptions.Add(linkerItem.ReceiverType + '/' + linkerItem.Path);
            }

            int index = EditorGUI.Popup(
                new Rect(controlPosition.x, controlPosition.y, controlPosition.width, EditorGUIUtility.singleLineHeight),
                selectedIndex,
                guiOptions.ToArray()
                );

            return(options[index]);
        }