Ejemplo n.º 1
0
        /// <summary>
        /// Tries to ensure the property has a target by either finding one or by (guessing)
        /// and creating a wrapper for one of the PropertyBinding's sibling components,
        /// e.g. if the PropertyBinding is PropertyBinding<HasColor> and there's a sibling component of type Image
        /// then may wrap that image as an IHasValue<Color> with a GraphicColor component.
        /// </summary>
        private void TryEnsurePropertyHasTarget()
        {
            var tgtPropAssignmentProp = FindTargetPropertyAssignmentProp(this.serializedObject);

            if ((TargetPropertyAssignmentType)tgtPropAssignmentProp.intValue == TargetPropertyAssignmentType.FindOnGameObject)
            {
                // if configuration has been set to find the target property on some (external) GameObject, then we don't want to mess with that
                return;
            }

            Type valueType;

            if ((this.target as PropertyBinding).GetPropertyValueType(out valueType))
            {
                // if the propertyinterface targets an IHasValue<ValueType> then find/create a component that implements that IHasValue<ValueType>
                PropertyBindingEditor.HandleDrivenProperty(valueType, this.target, FindPropertyProp(this.serializedObject), false);
                this.serializedObject.ApplyModifiedProperties();
            }
        }
        override public void OnInspectorGUI()
        {
            EditorGUI.BeginChangeCheck();

            var driverProp = this.serializedObject.FindProperty("m_driver");

            EditorGUILayout.PropertyField(driverProp, new GUIContent("Driver", "Source property for the color"));

            var userAssetForDefaultProp = this.serializedObject.FindProperty("m_useAssetForDefaultValue");

            if (userAssetForDefaultProp.boolValue)
            {
                var assetProp = this.serializedObject.FindProperty("m_defaultValueAsset");
                EditorGUILayout.PropertyField(assetProp, new GUIContent("Color", "a shared ColorAsset for places where you want consistency"));
            }
            else
            {
                var defaultColorProp = this.serializedObject.FindProperty("m_defaultValue");
                EditorGUILayout.PropertyField(defaultColorProp);
            }

            EditorGUILayout.PropertyField(userAssetForDefaultProp,
                                          new GUIContent("Use Asset For Default", "For default color, use a shared color asset or a local color property?"));

            EditorGUILayout.PropertyField(this.serializedObject.FindProperty("m_disableAutoSync"));
            EditorGUILayout.PropertyField(this.serializedObject.FindProperty("m_logWarningOnNoDriver"));
            EditorGUILayout.PropertyField(this.serializedObject.FindProperty("m_debug"));


            PropertyBindingEditor.HandleAssignProperty <HasColor, Color> (this.serializedObject, this.target);

            this.serializedObject.ApplyModifiedProperties();

            if (EditorGUI.EndChangeCheck())
            {
                (this.target as BindColorToColor).UpdateProperty();
            }
        }
Ejemplo n.º 3
0
        override public void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            var propBinding       = this.target as PropertyBinding;
            var propertyInterface = propBinding.propertyInterface;

            //Debug.LogWarning("[" + Time.frameCount + "] OnInspectorGUI for " + propBinding.GetType().Name);

            Type propertyUnityAssignableType;

            propBinding.GetPropertyUnityAssignableType(out propertyUnityAssignableType);

            Type valueType;

            if (propBinding.GetPropertyValueType(out valueType))
            {
                PropertyBindingEditor.HandleAssignProperty(propertyUnityAssignableType, propertyInterface, valueType, this.serializedObject, this.target);
            }
            else
            {
                Debug.LogWarning("[" + Time.frameCount + "] unable to get value type for propertybinding " + propBinding.GetType().Name);
            }
        }