Ejemplo n.º 1
0
        private void OnEnable()
        {
            var finder = new PropertyFinder(serializedObject);

            _propertyBinderEditor =
                new PropertyBinderEditor(serializedObject.FindProperty("_boolPropertyBinders"), "bool");
        }
Ejemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            // Initialise reference to target script
            var targetScript = (OneWayPropertyBinding)target;

            Type viewPropertyType;

            ShowViewPropertyMenu(
                new GUIContent("View property", "Property on the view to bind to"),
                PropertyFinder.GetBindableProperties(targetScript.gameObject)
                .OrderBy(property => property.ReflectedType.Name)
                .ThenBy(property => property.Name)
                .ToArray(),
                updatedValue => targetScript.uiPropertyName = updatedValue,
                targetScript.uiPropertyName,
                out viewPropertyType
                );

            var viewAdapterTypeNames = GetAdapterTypeNames(
                type => viewPropertyType == null ||
                TypeResolver.FindAdapterAttribute(type).OutputType == viewPropertyType
                );

            ShowAdapterMenu(
                new GUIContent("View adapter", "Adapter that converts values sent from the view-model to the view."),
                viewAdapterTypeNames,
                targetScript.viewAdapterTypeName,
                newValue =>
            {
                // Get rid of old adapter options if we changed the type of the adapter.
                if (newValue != targetScript.viewAdapterTypeName)
                {
                    targetScript.viewAdapterOptions = null;
                }

                UpdateProperty(
                    updatedValue => targetScript.viewAdapterTypeName = updatedValue,
                    targetScript.viewAdapterTypeName,
                    newValue
                    );
            }
                );

            ShowAdapterOptionsMenu(
                "View adapter options",
                targetScript.viewAdapterTypeName,
                options => targetScript.viewAdapterOptions = options,
                targetScript.viewAdapterOptions
                );

            var adaptedViewPropertyType = AdaptTypeBackward(viewPropertyType, targetScript.viewAdapterTypeName);

            ShowViewModelPropertyMenu(
                new GUIContent("View-model property", "Property on the view-model to bind to."),
                TypeResolver.FindBindableProperties(targetScript),
                updatedValue => targetScript.viewModelPropertyName = updatedValue,
                targetScript.viewModelPropertyName,
                property => property.PropertyType == adaptedViewPropertyType
                );
        }
Ejemplo n.º 3
0
        private void OnEnable()
        {
            var finder = new PropertyFinder(serializedObject);

            _floatPropertyBinderEditor =
                new PropertyBinderEditor(serializedObject.FindProperty("_floatPropertyBinders"), "float");
        }
        public void FindPropertyInfos_ForClassWithMixedProperties()
        {
            var classDefinition = CreateClassDefinition(typeof(ClassWithDifferentProperties));
            var propertyFinder  =
                new PropertyFinder(
                    typeof(ClassWithDifferentProperties),
                    classDefinition,
                    true,
                    true,
                    new ReflectionBasedMemberInformationNameResolver(),
                    classDefinition.PersistentMixinFinder,
                    new PropertyMetadataReflector(),
                    new DomainModelConstraintProvider());

            Assert.That(
                propertyFinder.FindPropertyInfos(),
                Is.EqualTo(
                    new[]
            {
                GetProperty(typeof(ClassWithDifferentPropertiesNotInMapping), "BaseString"),
                GetProperty(typeof(ClassWithDifferentPropertiesNotInMapping), "BaseUnidirectionalOneToOne"),
                GetProperty(typeof(ClassWithDifferentPropertiesNotInMapping), "BasePrivateUnidirectionalOneToOne"),
                GetProperty(typeof(ClassWithDifferentProperties), "Int32"),
                GetProperty(typeof(ClassWithDifferentProperties), "String"),
                GetProperty(typeof(ClassWithDifferentProperties), "UnidirectionalOneToOne"),
                GetProperty(typeof(ClassWithDifferentProperties), "PrivateString")
            }));
        }
Ejemplo n.º 5
0
        private void OnEnable()
        {
            var finder = new PropertyFinder(serializedObject);

            _vector3PropertyBinderEditor =
                new PropertyBinderEditor(serializedObject.FindProperty("_vector3PropertyBinders"), "Vector3");
        }
Ejemplo n.º 6
0
 public Cache(Type type)
 {
     Type       = type;
     Fields     = new FieldFinder(this);
     Properties = new PropertyFinder(this);
     Methods    = new MethodFinder(this);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the properties defined 
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public IDictionary<string, string> GetProperties(string value)
        {
            var finder = new PropertyFinder();
            propertyRegex.Replace(value, finder.Log);

            return finder.Properties;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the properties defined
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public IDictionary <string, string> GetProperties(string value)
        {
            var finder = new PropertyFinder();

            propertyRegex.Replace(value, finder.Log);

            return(finder.Properties);
        }
Ejemplo n.º 9
0
        public void GetPropertyTest()
        {
            PropertyClass propertyClass = new PropertyClass();

            PropertyInfo actual = PropertyFinder <PropertyClass> .Find(x => x.GetMe);

            PropertyInfo expected = propertyClass.GetType().GetProperty("GetMe");

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 10
0
        void OnEnable()
        {
            var finder = new PropertyFinder(serializedObject);

            _inputMin = finder["_inputMin"];
            _inputMax = finder["_inputMax"];

            _propertyBinderEditor
                = new PropertyBinderEditor(finder["_propertyBinders"]);
        }
Ejemplo n.º 11
0
        protected void OnEnable()
        {
            if (target == null)
            {
                return;
            }

            var pf = new PropertyFinder <RenderTextureInputSettings>(serializedObject);

            m_SourceRTxtr = pf.Find(w => w.m_SourceRTxtr);
        }
        private PropertyInfo GetPropertyInfo(Expression <Func <T, object> > expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }

            var property = PropertyFinder.FromExpression(expression);

            return(property ?? throw new ArgumentException("Invalid Property expression", nameof(expression)));
        }
Ejemplo n.º 13
0
        public System.Collections.Generic.Dictionary <string, Func <object, object> > GetProperties(Type type)
        {
            PropertyFinder finder = new PropertyFinder();

            GetInstancePropertyValueExpression getGenerator = new GetInstancePropertyValueExpression();

            System.Collections.Generic.Dictionary <string, Type> properties = finder.GetProperties(type);

            return(properties.ToDictionary(
                       keyValue => keyValue.Key,
                       keyValue => getGenerator.GetFunc(type, keyValue.Key)));
        }
Ejemplo n.º 14
0
        protected override void OnEnable()
        {
            base.OnEnable();

            if (target == null)
            {
                return;
            }

            var pf = new PropertyFinder <EXRRecorderSettings>(serializedObject);

            m_Inputs = pf.Find(w => w.m_InputsSettings);
        }
        protected void OnEnable()
        {
            if (target == null)
            {
                return;
            }

            var pf = new PropertyFinder <CBRenderTextureInputSettings>(serializedObject);

            m_Source       = pf.Find(w => w.source);
            m_CameraTag    = pf.Find(w => w.m_CameraTag);
            m_RenderSize   = pf.Find(w => w.m_RenderSize);
            m_RenderAspect = pf.Find(w => w.m_RenderAspect);
        }
Ejemplo n.º 16
0
        protected void OnEnable()
        {
            if (target == null)
            {
                return;
            }

            var pf = new PropertyFinder <ScreenCaptureInputSettings>(serializedObject);

            m_RenderSize   = pf.Find(w => w.m_OutputSize);
            m_RenderAspect = pf.Find(w => w.m_AspectRatio);

            m_ResSelector = new ResolutionSelector();
        }
Ejemplo n.º 17
0
        public override void OnInspectorGUI()
        {
            // Initialise reference to target script
            var targetScript = (OneWayPropertyBinding)target;

            Type viewPropertyType = null;

            ShowViewPropertyMenu(
                new GUIContent("View property", "Property on the view to bind to"),
                targetScript,
                PropertyFinder.GetBindableProperties(targetScript.gameObject)
                .OrderBy(property => property.PropertyInfo.ReflectedType.Name)
                .ThenBy(property => property.PropertyInfo.Name)
                .ToArray(),
                updatedValue => targetScript.uiPropertyName = updatedValue,
                targetScript.uiPropertyName,
                out viewPropertyType
                );

            var viewAdapterTypeNames = TypeResolver.TypesWithAdapterAttribute
                                       .Where(type => viewPropertyType == null || TypeResolver.FindAdapterAttribute(type).OutputType == viewPropertyType)
                                       .Select(type => type.Name)
                                       .ToArray();

            ShowAdapterMenu(
                new GUIContent("View adapter", "Adapter that converts values sent from the view-model to the view."),
                viewAdapterTypeNames,
                targetScript.viewAdapterTypeName,
                newValue =>
            {
                UpdateProperty(
                    updatedValue => targetScript.viewAdapterTypeName = updatedValue,
                    targetScript.viewAdapterTypeName,
                    newValue
                    );
            }
                );

            var adaptedViewPropertyType = AdaptTypeBackward(viewPropertyType, targetScript.viewAdapterTypeName);

            ShowViewModelPropertyMenu(
                new GUIContent("View-model property", "Property on the view-model to bind to."),
                targetScript,
                TypeResolver.FindBindableProperties(targetScript),
                updatedValue => targetScript.viewModelPropertyName = updatedValue,
                targetScript.viewModelPropertyName,
                property => property.PropertyType == adaptedViewPropertyType
                );
        }
        public void FindPropertyInfos_ForClassWithOneSideRelationProperties()
        {
            var classDefinition = CreateClassDefinition(typeof(ClassWithVirtualRelationEndPoints));
            var propertyFinder  =
                new PropertyFinder(
                    typeof(ClassWithVirtualRelationEndPoints),
                    classDefinition,
                    true,
                    true,
                    new ReflectionBasedMemberInformationNameResolver(),
                    classDefinition.PersistentMixinFinder,
                    new PropertyMetadataReflector(),
                    new DomainModelConstraintProvider());

            Assert.That(propertyFinder.FindPropertyInfos(), Is.Empty);
        }
Ejemplo n.º 19
0
        protected void OnEnable()
        {
            if (target == null)
            {
                return;
            }

            var pf = new PropertyFinder <AdamBeautyInputSettings>(serializedObject);

            m_Source        = pf.Find(w => w.source);
            m_RenderSize    = pf.Find(w => w.m_RenderSize);
            m_RenderTexture = pf.Find(w => w.m_RenderTexture);
            m_AspectRatio   = pf.Find(w => w.m_AspectRatio);
            m_SuperSampling = pf.Find(w => w.m_SuperSampling);
            m_FinalSize     = pf.Find(w => w.m_FinalSize);
        }
        public void Initialize()
        {
            var classDefinition = CreateClassDefinition(typeof(ClassWithDifferentProperties));
            var propertyFinder  =
                new PropertyFinder(
                    typeof(ClassWithDifferentProperties),
                    classDefinition,
                    true,
                    true,
                    new ReflectionBasedMemberInformationNameResolver(),
                    classDefinition.PersistentMixinFinder,
                    new PropertyMetadataReflector(),
                    new DomainModelConstraintProvider());

            Assert.That(propertyFinder.Type, Is.SameAs(typeof(ClassWithDifferentProperties)));
            Assert.That(propertyFinder.IncludeBaseProperties, Is.True);
        }
        protected void OnEnable()
        {
            if (target == null)
            {
                return;
            }

            var pf = new PropertyFinder <CBRenderTextureInputSettings>(serializedObject);

            m_Source          = pf.Find(w => w.source);
            m_CameraTag       = pf.Find(w => w.m_CameraTag);
            m_RenderSize      = pf.Find(w => w.m_RenderSize);
            m_RenderAspect    = pf.Find(w => w.m_RenderAspect);
            m_FlipFinalOutput = pf.Find(w => w.m_FlipFinalOutput);
            m_Transparency    = pf.Find(w => w.m_AllowTransparency);
            m_CaptureUI       = pf.Find(w => w.m_CaptureUI);
        }
        public void Transform_CheckIgnore_PropertyNotInResult()
        {
            var numProp = PropertyFinder.FromExpression <NullClassFixture>(f => f.Num);
            var tranDic = new Dictionary <PropertyInfo, IPropertyTransformer>
            {
                [numProp] = new PropertyTransformerFixture
                {
                    ShouldIgnore = true
                }
            };

            var transformer = new TypeTransformer(typeof(NullClassFixture), false, tranDic);

            var tranObj = transformer.Transform(new NullClassFixture());

            Assert.DoesNotContain(tranObj.Properties, x => x.Name == nameof(NullClassFixture.Num));
        }
        protected void OnEnable()
        {
            if (target == null)
            {
                return;
            }

            var pf = new PropertyFinder <RenderTextureSamplerSettings>(serializedObject);

            m_Source          = pf.Find(w => w.source);
            m_RenderSize      = pf.Find(w => w.m_RenderSize);
            m_AspectRatio     = pf.Find(w => w.m_AspectRatio);
            m_SuperSampling   = pf.Find(w => w.m_SuperSampling);
            m_FinalSize       = pf.Find(w => w.m_OutputSize);
            m_CameraTag       = pf.Find(w => w.m_CameraTag);
            m_FlipFinalOutput = pf.Find(w => w.m_FlipFinalOutput);
            m_ResSelector     = new ResolutionSelector();
        }
        protected override void OnEnable()
        {
            base.OnEnable();

            if (target == null)
            {
                return;
            }

            var pf       = new PropertyFinder <MP4RecorderSettings>(serializedObject);
            var encoding = pf.Find(w => w.m_MP4EncoderSettings);
            var settings = target as MP4RecorderSettings;

            m_VideoBitRateMode = encoding.FindPropertyRelative(() => settings.m_MP4EncoderSettings.videoBitrateMode);
            m_VideoBitRate     = encoding.FindPropertyRelative(() => settings.m_MP4EncoderSettings.videoTargetBitrate);
            m_VideoMaxTasks    = encoding.FindPropertyRelative(() => settings.m_MP4EncoderSettings.videoMaxTasks);
            m_AutoSelectBR     = pf.Find(w => w.m_AutoSelectBR);
        }
Ejemplo n.º 25
0
        protected void OnEnable()
        {
            if (target == null)
            {
                return;
            }

            var pf = new PropertyFinder <Camera360InputSettings>(serializedObject);

            m_Source    = pf.Find(w => w.source);
            m_CameraTag = pf.Find(w => w.m_CameraTag);

            m_StereoSeparation = pf.Find(w => w.m_StereoSeparation);
            m_FlipFinalOutput  = pf.Find(w => w.m_FlipFinalOutput);
            m_CubeMapSz        = pf.Find(w => w.m_MapSize);
            m_OutputWidth      = pf.Find(w => w.m_OutputWidth);
            m_OutputHeight     = pf.Find(w => w.m_OutputHeight);
            m_RenderStereo     = pf.Find(w => w.m_RenderStereo);
        }
Ejemplo n.º 26
0
        protected void OnEnable()
        {
            if (target == null)
            {
                return;
            }

            var pf = new PropertyFinder <AudioInputSettings>(serializedObject);

            m_PreserveAudio = pf.Find(w => w.m_PreserveAudio);

#if RECORD_AUDIO_MIXERS
            m_AudioMixerGroups     = serializedObject.FindProperty <AudioInputSettings>(x => x.m_AudioMixerGroups);
            m_AudioMixerGroupsList = new ReorderableList(serializedObject, m_AudioMixerGroups, true, true, true, true);
            m_AudioMixerGroupsList.drawElementCallback =
                (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                var element = m_AudioMixerGroupsList.serializedProperty.GetArrayElementAtIndex(index);
                rect.y += 2;
                EditorGUI.PropertyField(
                    new Rect(rect.x - 25, rect.y, rect.width - 90, EditorGUIUtility.singleLineHeight),
                    element.FindPropertyRelative("m_MixerGroup"), GUIContent.none);
                EditorGUI.PropertyField(
                    new Rect(rect.x + rect.width - 85, rect.y, 20, EditorGUIUtility.singleLineHeight),
                    element.FindPropertyRelative("m_Isolate"), GUIContent.none);
                EditorGUI.LabelField(
                    new Rect(rect.x + rect.width - 65, rect.y, 60, EditorGUIUtility.singleLineHeight),
                    new GUIContent("Isolate", "Isolate group from mix"));
            };

            m_AudioMixerGroupsList.drawHeaderCallback = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, "Audio Mixer Groups");
            };
#endif
        }
        public void Transform_CheckPropertyTransformer()
        {
            var numProp = PropertyFinder.FromExpression <NullClassFixture>(f => f.Num);
            var tranDic = new Dictionary <PropertyInfo, IPropertyTransformer>
            {
                [numProp] = new PropertyTransformerFixture
                {
                    ShouldIgnore    = false,
                    FixtureName     = "AAA",
                    FixtureValue    = "BBB",
                    NeedDestructure = true
                }
            };

            var transformer = new TypeTransformer(typeof(NullClassFixture), false, tranDic);

            var tranObj = transformer.Transform(new NullClassFixture());

            Assert.Equal(typeof(NullClassFixture).Name, tranObj.TypeTag);
            Assert.Contains(tranObj.Properties,
                            x => x.Name == "AAA" &&
                            x.Value.Equals("BBB") &&
                            x.NeedsDestruct);
        }
Ejemplo n.º 28
0
        public override void OnInspectorGUI()
        {
            if (CannotModifyInPlayMode())
            {
                GUI.enabled = false;
            }

            UpdatePrefabModifiedProperties();

            var defaultLabelStyle = EditorStyles.label.fontStyle;

            EditorStyles.label.fontStyle = viewEventPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            ShowEventMenu(
                UnityEventWatcher.GetBindableEvents(targetScript.gameObject)
                .OrderBy(evt => evt.Name)
                .ToArray(),
                updatedValue => targetScript.ViewEventName = updatedValue,
                targetScript.ViewEventName
                );

            EditorStyles.label.fontStyle = viewPropertyPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            Type viewPropertyType;

            ShowViewPropertyMenu(
                new GUIContent("View property", "Property on the view to bind to"),
                PropertyFinder.GetBindableProperties(targetScript.gameObject)
                .OrderBy(prop => prop.ViewModelTypeName)
                .ThenBy(prop => prop.MemberName)
                .ToArray(),
                updatedValue => targetScript.ViewPropertName = updatedValue,
                targetScript.ViewPropertName,
                out viewPropertyType
                );

            // Don't let the user set other options until they've set the event and view property.
            var guiPreviouslyEnabled = GUI.enabled;

            if (string.IsNullOrEmpty(targetScript.ViewEventName) ||
                string.IsNullOrEmpty(targetScript.ViewPropertName))
            {
                GUI.enabled = false;
            }

            var viewAdapterTypeNames = GetAdapterTypeNames(
                type => viewPropertyType == null ||
                TypeResolver.IsTypeCastableTo(TypeResolver.FindAdapterAttribute(type).OutputType, viewPropertyType)
                );

            EditorStyles.label.fontStyle = viewAdapterPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            ShowAdapterMenu(
                new GUIContent(
                    "View adapter",
                    "Adapter that converts values sent from the view-model to the view."
                    ),
                viewAdapterTypeNames,
                targetScript.ViewAdapterTypeName,
                newValue =>
            {
                // Get rid of old adapter options if we changed the type of the adapter.
                if (newValue != targetScript.ViewAdapterTypeName)
                {
                    Undo.RecordObject(targetScript, "Set view adapter options");
                    targetScript.ViewAdapterOptions = null;
                }

                UpdateProperty(
                    updatedValue => targetScript.ViewAdapterTypeName = updatedValue,
                    targetScript.ViewAdapterTypeName,
                    newValue,
                    "Set view adapter"
                    );
            }
                );

            EditorStyles.label.fontStyle = viewAdapterOptionsPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            Type viewAdapterType;

            viewAdapterOptionsFade.target = ShouldShowAdapterOptions(
                targetScript.ViewAdapterTypeName,
                out viewAdapterType
                );
            ShowAdapterOptionsMenu(
                "View adapter options",
                viewAdapterType,
                options => targetScript.ViewAdapterOptions = options,
                targetScript.ViewAdapterOptions,
                viewAdapterOptionsFade.faded
                );

            EditorGUILayout.Space();

            EditorStyles.label.fontStyle = viewModelPropertyPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            var adaptedViewPropertyType = AdaptTypeBackward(
                viewPropertyType,
                targetScript.ViewAdapterTypeName
                );

            ShowViewModelPropertyMenu(
                new GUIContent(
                    "View-model property",
                    "Property on the view-model to bind to."
                    ),
                TypeResolver.FindBindableProperties(targetScript),
                updatedValue => targetScript.ViewModelPropertyName = updatedValue,
                targetScript.ViewModelPropertyName,
                prop => TypeResolver.IsTypeCastableTo(prop.PropertyType, adaptedViewPropertyType)
                );

            var viewModelAdapterTypeNames = GetAdapterTypeNames(
                type => adaptedViewPropertyType == null ||
                TypeResolver.IsTypeCastableTo(adaptedViewPropertyType, TypeResolver.FindAdapterAttribute(type).OutputType)
                );

            EditorStyles.label.fontStyle = viewModelAdapterPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            ShowAdapterMenu(
                new GUIContent(
                    "View-model adapter",
                    "Adapter that converts from the view back to the view-model"
                    ),
                viewModelAdapterTypeNames,
                targetScript.ViewModelAdapterTypeName,
                newValue =>
            {
                if (newValue != targetScript.ViewModelAdapterTypeName)
                {
                    Undo.RecordObject(targetScript, "Set view-model adapter options");
                    targetScript.ViewModelAdapterOptions = null;
                }

                UpdateProperty(
                    updatedValue => targetScript.ViewModelAdapterTypeName = updatedValue,
                    targetScript.ViewModelAdapterTypeName,
                    newValue,
                    "Set view-model adapter"
                    );
            }
                );

            EditorStyles.label.fontStyle = viewModelAdapterOptionsPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            Type viewModelAdapterType;

            viewModelAdapterOptionsFade.target = ShouldShowAdapterOptions(
                targetScript.ViewModelAdapterTypeName,
                out viewModelAdapterType
                );
            ShowAdapterOptionsMenu(
                "View-model adapter options",
                viewModelAdapterType,
                options => targetScript.ViewModelAdapterOptions = options,
                targetScript.ViewModelAdapterOptions,
                viewModelAdapterOptionsFade.faded
                );

            EditorGUILayout.Space();

            var expectionAdapterTypeNames = GetAdapterTypeNames(
                type => TypeResolver.IsTypeCastableTo(TypeResolver.FindAdapterAttribute(type).InputType, typeof(Exception))
                );

            EditorStyles.label.fontStyle = exceptionPropertyPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            var adaptedExceptionPropertyType = AdaptTypeForward(
                typeof(Exception),
                targetScript.ExceptionAdapterTypeName
                );

            ShowViewModelPropertyMenuWithNone(
                new GUIContent(
                    "Exception property",
                    "Property on the view-model to bind the exception to."
                    ),
                TypeResolver.FindBindableProperties(targetScript),
                updatedValue => targetScript.ExceptionPropertyName = updatedValue,
                targetScript.ExceptionPropertyName,
                prop => TypeResolver.IsTypeCastableTo(prop.PropertyType, adaptedExceptionPropertyType)
                );

            EditorStyles.label.fontStyle = exceptionAdapterPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            ShowAdapterMenu(
                new GUIContent(
                    "Exception adapter",
                    "Adapter that handles exceptions thrown by the view-model adapter"
                    ),
                expectionAdapterTypeNames,
                targetScript.ExceptionAdapterTypeName,
                newValue =>
            {
                if (newValue != targetScript.ExceptionAdapterTypeName)
                {
                    Undo.RecordObject(targetScript, "Set exception adapter options");
                    targetScript.ExceptionAdapterOptions = null;
                }

                UpdateProperty(
                    updatedValue => targetScript.ExceptionAdapterTypeName = updatedValue,
                    targetScript.ExceptionAdapterTypeName,
                    newValue,
                    "Set exception adapter"
                    );
            }
                );

            EditorStyles.label.fontStyle = exceptionAdapterOptionsPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            Type exceptionAdapterType;

            exceptionAdapterOptionsFade.target = ShouldShowAdapterOptions(
                targetScript.ExceptionAdapterTypeName,
                out exceptionAdapterType
                );
            ShowAdapterOptionsMenu(
                "Exception adapter options",
                exceptionAdapterType,
                options => targetScript.ExceptionAdapterOptions = options,
                targetScript.ExceptionAdapterOptions,
                exceptionAdapterOptionsFade.faded
                );

            EditorStyles.label.fontStyle = defaultLabelStyle;

            GUI.enabled = guiPreviouslyEnabled;
        }
        public string GetClassTest(
            Type type,
            string className)
        {
            PropertyFinder finder = new PropertyFinder();

            Dictionary <string, Type> properties = finder.GetProperties(type);

            StringBuilder propertiesText = new StringBuilder();

            CSharpClassNameFormatter formatter = new CSharpClassNameFormatter();

            List <string> keys = properties.Keys.ToList();

            for (int i = 0; i < keys.Count; i++)
            {
                string propertyName = keys[i];
                Type   propertyType = properties[propertyName];

                if (i > 0)
                {
                    propertiesText.Append("\r\n\t\r\n\t");
                }

                propertiesText.Append(
                    $@"public {formatter.GetFullName(propertyType)} {propertyName}
	{{
		get
		{{
			return ({formatter.GetFullName(propertyType)})GetValue(""{propertyName}"");
		}}
	}}"    );
            }

            // TODO: should wrapper class implement any interfaces or extend from any classes
            // that wrapped class implements?

            string classText =
                $@"public sealed class {className}
{{
	private static System.Collections.Generic.Dictionary<string, Func<object, object>> properties = null;
	
	public {className}(object innerObject)
	{{
		if (properties == null)
		{{
			properties = new ReadonlyPropertyAccessor()
				.GetProperties(
					innerObject.GetType());
		}}

		this.InnerObject = innerObject;
	}}

	public object InnerObject {{ get; set; }}
	
	{propertiesText}
	
	private object GetValue(string property)
	{{
		return properties[property](InnerObject);
	}}
}}
";

            return(classText);
        }
        public override void OnInspectorGUI()
        {
            UpdatePrefabModifiedProperties();

            var defaultLabelStyle = EditorStyles.label.fontStyle;

            EditorStyles.label.fontStyle = viewPropertyPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            Type viewPropertyType;

            ShowViewPropertyMenu(
                new GUIContent("View property", "Property on the view to bind to"),
                PropertyFinder.GetBindableProperties(targetScript.gameObject)
                .OrderBy(prop => prop.ViewModelTypeName)
                .ThenBy(prop => prop.MemberName)
                .ToArray(),
                updatedValue => targetScript.ViewPropertyName = updatedValue,
                targetScript.ViewPropertyName,
                out viewPropertyType
                );

            // Don't let the user set anything else until they've chosen a view property.
            var guiPreviouslyEnabled = GUI.enabled;

            if (string.IsNullOrEmpty(targetScript.ViewPropertyName))
            {
                GUI.enabled = false;
            }

            var viewAdapterTypeNames = GetAdapterTypeNames(
                type => viewPropertyType == null ||
                TypeResolver.FindAdapterAttribute(type).OutputType == viewPropertyType
                );

            EditorStyles.label.fontStyle = viewAdapterPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            ShowAdapterMenu(
                new GUIContent(
                    "View adapter",
                    "Adapter that converts values sent from the view-model to the view."
                    ),
                viewAdapterTypeNames,
                targetScript.ViewAdapterTypeName,
                newValue =>
            {
                // Get rid of old adapter options if we changed the type of the adapter.
                if (newValue != targetScript.ViewAdapterTypeName)
                {
                    Undo.RecordObject(targetScript, "Set view adapter options");
                    targetScript.ViewAdapterOptions = null;
                }

                UpdateProperty(
                    updatedValue => targetScript.ViewAdapterTypeName = updatedValue,
                    targetScript.ViewAdapterTypeName,
                    newValue,
                    "Set view adapter"
                    );
            }
                );

            Type adapterType;

            viewAdapterOptionsFade.target = ShouldShowAdapterOptions(
                targetScript.ViewAdapterTypeName,
                out adapterType
                );

            EditorStyles.label.fontStyle = viewAdapterOptionsPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            ShowAdapterOptionsMenu(
                "View adapter options",
                adapterType,
                options => targetScript.ViewAdapterOptions = options,
                targetScript.ViewAdapterOptions,
                viewAdapterOptionsFade.faded
                );

            EditorGUILayout.Space();

            EditorStyles.label.fontStyle = viewModelPropertyPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            var adaptedViewPropertyType = AdaptTypeBackward(
                viewPropertyType,
                targetScript.ViewAdapterTypeName
                );

            ShowViewModelPropertyMenu(
                new GUIContent(
                    "View-model property",
                    "Property on the view-model to bind to."
                    ),
                TypeResolver.FindBindableProperties(targetScript),
                updatedValue => targetScript.ViewModelPropertyName = updatedValue,
                targetScript.ViewModelPropertyName,
                property => property.PropertyType == adaptedViewPropertyType
                );

            GUI.enabled = guiPreviouslyEnabled;

            EditorStyles.label.fontStyle = defaultLabelStyle;
        }
Ejemplo n.º 31
0
        public override void OnInspectorGUI()
        {
            if (CannotModifyInPlayMode())
            {
                GUI.enabled = false;
            }

            UpdatePrefabModifiedProperties();

            var defaultLabelStyle = EditorStyles.label.fontStyle;

            EditorStyles.label.fontStyle = viewPropertyPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            Type viewPropertyType;

            ShowViewPropertyMenu(
                new GUIContent("View property", "Property on the view to bind to"),
                PropertyFinder.GetBindableProperties(targetScript.gameObject)
                .OrderBy(prop => prop.ViewModelTypeName)
                .ThenBy(prop => prop.MemberName)
                .ToArray(),
                updatedValue => targetScript.ViewPropertyName = updatedValue,
                targetScript.ViewPropertyName,
                out viewPropertyType
                );

            // Don't let the user set anything else until they've chosen a view property.
            var guiPreviouslyEnabled = GUI.enabled;

            if (string.IsNullOrEmpty(targetScript.ViewPropertyName))
            {
                GUI.enabled = false;
            }

            var viewAdapterTypeNames = GetAdapterTypeNames(
                type => viewPropertyType == null ||
                TypeResolver.FindAdapterAttribute(type).OutputType == viewPropertyType
                );

            EditorStyles.label.fontStyle = viewAdapterPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            /*
             * for (int i = 0; i < viewAdapterTypeNames.Length; i++)
             * {
             *  var name = viewAdapterTypeNames[i].Split('.').LastOrDefault()?.Replace("Adapter", "");
             *  viewAdapterTypeNames[i] = name == default(string) ? viewAdapterTypeNames[i] : name;
             * }
             */

            ShowAdapterMenu(
                new GUIContent(
                    "View adapter",
                    "Adapter that converts values sent from the view-model to the view."
                    ),
                viewAdapterTypeNames,
                targetScript.ViewAdapterTypeName,
                newValue =>
            {
                // Get rid of old adapter options if we changed the type of the adapter.
                if (newValue != targetScript.ViewAdapterTypeName)
                {
                    Undo.RecordObject(targetScript, "Set view adapter options");
                    targetScript.ViewAdapterOptions = null;
                }

                UpdateProperty(
                    updatedValue => targetScript.ViewAdapterTypeName = updatedValue,
                    targetScript.ViewAdapterTypeName,
                    newValue,
                    "Set view adapter"
                    );
            }
                );

            Type adapterType;

            viewAdapterOptionsFade.target = ShouldShowAdapterOptions(
                targetScript.ViewAdapterTypeName,
                out adapterType
                );

            EditorStyles.label.fontStyle = viewAdapterOptionsPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            ShowAdapterOptionsMenu(
                "View adapter options",
                adapterType,
                options => targetScript.ViewAdapterOptions = options,
                targetScript.ViewAdapterOptions,
                viewAdapterOptionsFade.faded
                );

            EditorGUILayout.Space();

            EditorStyles.label.fontStyle = viewModelPropertyPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            var adaptedViewPropertyType = AdaptTypeBackward(
                viewPropertyType,
                targetScript.ViewAdapterTypeName
                );

            ShowViewModelPropertyMenu(
                new GUIContent(
                    "View-model property",
                    "Property on the view-model to bind to."
                    ),
                TypeResolver.FindBindableProperties(targetScript),
                updatedValue => targetScript.ViewModelPropertyName = updatedValue,
                targetScript.ViewModelPropertyName,
                property => property.PropertyType == adaptedViewPropertyType || adaptedViewPropertyType == typeof(object)
                );

            // About adaptedViewPropertyType == typeof(object) :
            // If the view adapter can take typeof(object) then allow user to select it
            // If the view adapter isn't typeof(object), user wil not be able to select this property.
            // This is awesome to show as string any object with Unity

            GUI.enabled = guiPreviouslyEnabled;

            EditorStyles.label.fontStyle = defaultLabelStyle;
        }