Esempio n. 1
0
        public override void OnInspectorGUI()
        {
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Space();

            _targetEvents.ChangeTargetTypeIfNecessary(_binding.TargetType);
            _sourceCallbacks.ChangeTargetTypeIfNecessary(_binding.SourceType);

            _binding.SourceDefinition.Kind = (BindingMemberKind)EditorGUILayout.EnumPopup("Reference", _binding.SourceDefinition.Kind);

            if (_binding.SourceDefinition.Kind == BindingMemberKind.Instance)
            {
                _binding.SourceDefinition.Instance = (BindableMonoBehaviour)EditorGUILayout.ObjectField("Source", _binding.SourceDefinition.Instance, typeof(BindableMonoBehaviour), true);
            }
            else
            {
                int selected = _sourceTypeCollection.IndexOf(_binding.SourceDefinition?.Type);
                selected = EditorGUILayout.Popup("Source", selected, _sourceTypeCollection.Names.ToArray());
                _binding.SourceDefinition.Type = _sourceTypeCollection.TypeAt(selected);
            }

            _binding.Target = EditorGUILayout.ObjectField("Target", _binding.Target, typeof(UnityObject), true);

            if (!_binding.HasSourceAndTarget)
            {
                ResetBinding();
                return;
            }

            GuiLine();

            if (_sourceCallbacks.Count == 0)
            {
                EditorGUILayout.HelpBox("No source callbacks found.", MessageType.Info);
                _binding.SourceIdentifier.Valid = false;
                return;
            }

            if (_targetEvents.Count == 0)
            {
                EditorGUILayout.HelpBox("No target events found.", MessageType.Info);
                _binding.TargetIdentifier.Valid = false;
                return;
            }

            var sourceIndex = IndexedIdentifier.For(_binding.SourceIdentifier, _sourceCallbacks.Names);
            var targetIndex = IndexedIdentifier.For(_binding.TargetIdentifier, _targetEvents.Names);

            sourceIndex.Index = EditorGUILayout.Popup("Callback", sourceIndex.Index, Nicify(_sourceCallbacks.Names));
            targetIndex.Index = EditorGUILayout.Popup("Event", targetIndex.Index, Nicify(_targetEvents.Names));

            if (EditorGUI.EndChangeCheck())
            {
                MarkDirty();
            }
        }
Esempio n. 2
0
        public override void OnInspectorGUI()
        {
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Space();

            if (_sourceMethods.ChangeTargetTypeIfNecessary(_binding.SourceType))
            {
                _binding.SourceIdentifier.Name = string.Empty;
            }

            _binding.SourceDefinition.Kind = (BindingMemberKind)EditorGUILayout.EnumPopup("Reference", _binding.SourceDefinition.Kind);
            _binding.EventTriggerType      = (EventTriggerType)EditorGUILayout.EnumPopup("Trigger", _binding.EventTriggerType);


            if (_binding.SourceDefinition.Kind == BindingMemberKind.Instance)
            {
                _binding.SourceDefinition.Instance = (BindableMonoBehaviour)EditorGUILayout.ObjectField("Source", _binding.SourceDefinition.Instance, typeof(BindableMonoBehaviour), true);
            }
            else
            {
                int selected = _sourceTypeCollection.IndexOf(_binding.SourceDefinition?.Type);
                selected = EditorGUILayout.Popup("Source", selected, _sourceTypeCollection.Names.ToArray());
                _binding.SourceDefinition.Type = _sourceTypeCollection.TypeAt(selected);
            }

            if (!_binding.HasSource)
            {
                ResetBinding();
                return;
            }

            var sourceIndex = IndexedIdentifier.For(_binding.SourceIdentifier, _sourceMethods.Names);

            if (_sourceMethods.Any())
            {
                sourceIndex.Index = EditorGUILayout.Popup("Source Callback", sourceIndex.Index, Nicify(_sourceMethods.Names));
            }
            else
            {
                EditorGUILayout.HelpBox("No methods found in source.", MessageType.Info);
                return;
            }
        }
Esempio n. 3
0
        public override void OnInspectorGUI()
        {
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Space();

            if (_listProperties.ChangeTargetTypeIfNecessary(_binding.SourceType))
            {
                _binding.ListIdentifier.Name = string.Empty;
            }

            _binding.Source = (BindableMonoBehaviour)EditorGUILayout.ObjectField("Source", _binding.Source, typeof(BindableMonoBehaviour), true);

            if (_binding.Source == null)
            {
                return;
            }

            var listIndex = IndexedIdentifier.For(_binding.ListIdentifier, _listProperties.Names);

            listIndex.Index = EditorGUILayout.Popup("List", listIndex.Index, Nicify(_listProperties.Names));

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Mapping", EditorStyles.boldLabel);

            if (_listProperty.arraySize == 0)
            {
                EditorGUILayout.HelpBox("Add prefabs which bind to the types in your list.\n", MessageType.Info);
            }

            for (int i = 0; i < _listProperty.arraySize; i++)
            {
                var item = _listProperty.GetArrayElementAtIndex(i);
                var name = TypeNameFromSerializeProperty(item);

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(name, GUILayout.Width(125));
                EditorGUILayout.PropertyField(item, GUIContent.none);

                if (GUILayout.Button("×", GUILayout.Width(20)))
                {
                    item.objectReferenceValue = null;
                    _listProperty.DeleteArrayElementAtIndex(i);
                    break;
                }

                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.Space();

            if (GUILayout.Button("Add prefab"))
            {
                _listProperty.InsertArrayElementAtIndex(_listProperty.arraySize);
            }

            serializedObject.ApplyModifiedProperties();

            if (EditorGUI.EndChangeCheck())
            {
                MarkDirty();
            }
        }
Esempio n. 4
0
        public override void OnInspectorGUI()
        {
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Space();

            if (_targetProperties.ChangeTargetTypeIfNecessary(_binding.TargetType))
            {
                _binding.TargetIdentifier.Name = string.Empty;
            }
            if (_sourceProperties.ChangeTargetTypeIfNecessary(_binding.SourceType))
            {
                _binding.SourceIdentifier.Name = string.Empty;
            }

            _binding.SourceDefinition.Kind = (BindingMemberKind)EditorGUILayout.EnumPopup("Reference", _binding.SourceDefinition.Kind);

            if (_binding.SourceDefinition.Kind == BindingMemberKind.Instance)
            {
                _binding.SourceDefinition.Instance = (BindableMonoBehaviour)EditorGUILayout.ObjectField("Source", _binding.SourceDefinition.Instance, typeof(BindableMonoBehaviour), true);
            }
            else
            {
                int selected = _sourceTypeCollection.IndexOf(_binding.SourceDefinition?.Type);
                selected = EditorGUILayout.Popup("Source", selected, _sourceTypeCollection.Names.ToArray());
                _binding.SourceDefinition.Type = _sourceTypeCollection.TypeAt(selected);
            }

            _binding.Target = EditorGUILayout.ObjectField("Target", _binding.Target, typeof(UnityObject), true);

            if (!_binding.HasSourceAndTarget)
            {
                ResetBinding();
                return;
            }

            GuiLine();

            var sourceIndex = IndexedIdentifier.For(_binding.SourceIdentifier, _sourceProperties.Names);
            var targetIndex = IndexedIdentifier.For(_binding.TargetIdentifier, _targetProperties.Names);

            if (_sourceProperties.Any())
            {
                sourceIndex.Index = EditorGUILayout.Popup("Source Property", sourceIndex.Index, Nicify(_sourceProperties.Names));
            }
            else
            {
                EditorGUILayout.HelpBox("No properties found in source.", MessageType.Info);
                return;
            }

            if (_targetProperties.Any())
            {
                targetIndex.Index = EditorGUILayout.Popup("Target Property", targetIndex.Index, Nicify(_targetProperties.Names));
            }
            else
            {
                EditorGUILayout.HelpBox("No properties found in target.", MessageType.Info);
                return;
            }

            _binding.BindingMode = (BindingMode)EditorGUILayout.EnumPopup("Mode", _binding.BindingMode);

            if (!TwoWayAvailable && _binding.BindingMode == BindingMode.TwoWay)
            {
                EditorGUILayout.HelpBox("Not available. Will default to OneWay", MessageType.Info);
            }

            GuiLine();

            // Handle converters
            var _converterNames     = ConversionProvider.AvailableConverterNames.Select(n => n.Replace("Coverter", string.Empty)).ToArray();
            var converterIdentifier = _binding.ConverterIdentifier;
            var converterIndex      = IndexedIdentifier.For(converterIdentifier, ConversionProvider.AvailableConverterNames.ToList());

            converterIndex.Index = EditorGUILayout.Popup("Conversion", converterIndex.Index, _converterNames);

            var converterProperties = ConversionProvider.PropertiesFor(converterIdentifier);

            EditorGUI.indentLevel++;
            foreach (var prop in converterProperties)
            {
                object propertyValue = converterIdentifier.GetPropertyValue(prop.Name);
                object newValue      = null;

                if (prop.PropertyType == typeof(int))
                {
                    newValue = EditorGUILayout.IntField(prop.Name, (int)propertyValue);
                }

                if (prop.PropertyType == typeof(float))
                {
                    newValue = EditorGUILayout.FloatField(prop.Name, (float)propertyValue);
                }

                if (prop.PropertyType == typeof(string))
                {
                    newValue = EditorGUILayout.TextField(prop.Name, (string)propertyValue);
                }

                if (prop.PropertyType == typeof(bool))
                {
                    newValue = EditorGUILayout.Toggle(prop.Name, (bool)propertyValue);
                }

                if (prop.PropertyType == typeof(Color))
                {
                    newValue = EditorGUILayout.ColorField(prop.Name, (Color)propertyValue);
                }

                if (prop.PropertyType == typeof(Color32))
                {
                    newValue = EditorGUILayout.ColorField(prop.Name, (Color32)propertyValue);
                }

                if (prop.PropertyType == typeof(Rect))
                {
                    newValue = EditorGUILayout.RectField(prop.Name, (Rect)propertyValue);
                }

                if (prop.PropertyType == typeof(LayerMask))
                {
                    newValue = EditorGUILayout.LayerField(prop.Name, (LayerMask)propertyValue);
                }

                if (prop.PropertyType == typeof(Vector2))
                {
                    newValue = EditorGUILayout.Vector2Field(prop.Name, (Vector2)propertyValue);
                }

                if (prop.PropertyType == typeof(Vector3))
                {
                    newValue = EditorGUILayout.Vector3Field(prop.Name, (Vector3)propertyValue);
                }

                if (prop.PropertyType == typeof(Vector4))
                {
                    newValue = EditorGUILayout.Vector4Field(prop.Name, (Vector4)propertyValue);
                }

                if (prop.PropertyType.IsEnum)
                {
                    newValue = EditorGUILayout.EnumPopup(prop.Name, (Enum)propertyValue);
                }

                converterIdentifier.SetPropertyValue(prop.Name, newValue);
            }
            EditorGUI.indentLevel--;

            if (EditorGUI.EndChangeCheck())
            {
                MarkDirty();
            }
        }