Ejemplo n.º 1
0
        public override LambdaExpression GetBindExpression()
        {
            bool sourceIsQueryable    = SourceValueType.IsGenericQueryable();
            bool targetIsQueryable    = TargetValueType.IsGenericQueryable();
            var  selectMethod         = sourceIsQueryable ? MethodFinder.GetQuerybleSelect <TSourceValueItem, TTargetValueItem>() : MethodFinder.GetEnumerableSelect <TSourceValueItem, TTargetValueItem>();
            var  callSelectExpression = Expression.Call(selectMethod, this.SourceExpression.Body, GetAssignExpression());
            var  toResultExpression   = GetResultExpression(callSelectExpression, sourceIsQueryable, targetIsQueryable);
            // 需要处理source为null的情况
            var resultExpression = Expression.Condition(
                Expression.Equal(this.SourceExpression.Body, Expression.Constant(null))
                , Expression.Constant(null, this.TargetValueType), toResultExpression);

            return(Expression.Lambda(resultExpression, this.SourceExpression.Parameters.First()));
        }
        private Expression GetResultExpression(Expression selectExpression, bool sourceIsQueryable, bool targetIsQueryable)
        {
            if (sourceIsQueryable && targetIsQueryable)
            {
                return(selectExpression);
            }

            if (!sourceIsQueryable && targetIsQueryable)
            {
                return(Expression.Call(
                           MethodFinder.GetAsQueryable(TargetValueType.GetQueryableItemType()),
                           selectExpression));
            }

            var toResultMethod = this.TargetValueType.IsArray ? MethodFinder.GetEnumerableToArray <TTargetValueItem>() : MethodFinder.GetEnumerableToList <TTargetValueItem>();

            return(Expression.Call(toResultMethod, selectExpression));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// sets the appropriate start value and calculates the diffValue
        /// </summary>
        internal void prepareForUse()
        {
            if( easeFunction == null )
                easeFunction = defaultEaseFunction;

            switch( tweenType )
            {
                case TweenType.Position:
                    targetValueType = TargetValueType.Vector3;
                    _startVector = transform.position;
                    break;
                case TweenType.LocalPosition:
                    targetValueType = TargetValueType.Vector3;
                    _startVector = transform.localPosition;
                    break;
                case TweenType.Scale:
                    targetValueType = TargetValueType.Vector3;
                    _startVector = transform.localScale;
                    break;
                case TweenType.Rotation:
                    targetValueType = TargetValueType.Vector3;
                    _startVector = transform.rotation.eulerAngles;

                    if( isRelativeTween )
                        _diffVector = targetVector;
                    else
                        _diffVector = new Vector3( Mathf.DeltaAngle( _startVector.x, targetVector.x ), Mathf.DeltaAngle( _startVector.y, targetVector.y ), Mathf.DeltaAngle( _startVector.z, targetVector.z ) );
                    break;
                case TweenType.LocalRotation:
                    targetValueType = TargetValueType.Vector3;
                    _startVector = transform.localRotation.eulerAngles;

                    if( isRelativeTween )
                        _diffVector = targetVector;
                    else
                        _diffVector = new Vector3( Mathf.DeltaAngle( _startVector.x, targetVector.x ), Mathf.DeltaAngle( _startVector.y, targetVector.y ), Mathf.DeltaAngle( _startVector.z, targetVector.z ) );
                    break;
                case TweenType.Color:
                    targetValueType = TargetValueType.Color;
                    break;
                case TweenType.Action:
                    targetValueType = TargetValueType.None;
                    break;
            }

            _elapsedTime = -delay;

            // we have to be careful with rotations because we always want to rotate in the shortest angle so we set the diffValue with that in mind
            if( targetValueType == TargetValueType.Vector3 && tweenType != TweenType.Rotation && tweenType != TweenType.LocalRotation)
            {
                if( isRelativeTween )
                    _diffVector = targetVector;
                else
                    _diffVector = targetVector - _startVector;
            }
            else if( targetValueType == TargetValueType.Color )
            {
                _material = transform.renderer.material;
                _startColor = _material.color;

                if( isRelativeTween )
                    _diffColor = targetColor;
                else
                    _diffColor = targetColor - _startColor;
            }
        }
Ejemplo n.º 4
0
            /// <summary>
            /// sets the appropriate start value and calculates the diffValue
            /// </summary>
            internal void prepareForUse()
            {
                switch( tweenType )
                {
                    case TweenType.Position:
                        targetValueType = TargetValueType.Vector3;
                        _startVector = transform.position;
                        break;
                    case TweenType.LocalPosition:
                        targetValueType = TargetValueType.Vector3;
                        _startVector = transform.localPosition;
                        break;
                    case TweenType.Scale:
                        targetValueType = TargetValueType.Vector3;
                        _startVector = transform.localScale;
                        break;
                    case TweenType.Rotation:
                        targetValueType = TargetValueType.Vector3;
                        _startVector = transform.rotation.eulerAngles;

                        if( isRelativeTween )
                            _diffVector = targetVector;
                        else
                            _diffVector = new Vector3( Mathf.DeltaAngle( _startVector.x, targetVector.x ), Mathf.DeltaAngle( _startVector.y, targetVector.y ), Mathf.DeltaAngle( _startVector.z, targetVector.z ) );
                        break;
                    case TweenType.LocalRotation:
                        targetValueType = TargetValueType.Vector3;
                        _startVector = transform.localRotation.eulerAngles;

                        if( isRelativeTween )
                            _diffVector = targetVector;
                        else
                            _diffVector = new Vector3( Mathf.DeltaAngle( _startVector.x, targetVector.x ), Mathf.DeltaAngle( _startVector.y, targetVector.y ), Mathf.DeltaAngle( _startVector.z, targetVector.z ) );
                        break;
                    case TweenType.RectTransformPosition:
                        targetValueType = TargetValueType.Vector3;
                        _startVector = rectTransform.anchoredPosition3D;
                        break;
                    case TweenType.Color:
                        targetValueType = TargetValueType.Color;
                        break;
                    case TweenType.Action:
                        targetValueType = TargetValueType.None;
                        break;
                    case TweenType.Property:
                        targetValueType = TargetValueType.None;
                        propertyTween.prepareForUse();
                        break;
                }

                _elapsedTime = -delay;

                // we have to be careful with rotations because we always want to rotate in the shortest angle so we set the diffValue with that in mind
                if( targetValueType == TargetValueType.Vector3 && tweenType != TweenType.Rotation && tweenType != TweenType.LocalRotation )
                {
                    if( isRelativeTween )
                        _diffVector = targetVector;
                    else
                        _diffVector = targetVector - _startVector;
                }
                else if( targetValueType == TargetValueType.Color )
                {
                    _material = transform.GetComponent<Renderer>().material;
                    _startColor = _material.GetColor( materialProperty );

                    if( isRelativeTween )
                        _diffColor = targetColor;
                    else
                        _diffColor = targetColor - _startColor;
                }
            }
Ejemplo n.º 5
0
            /// <summary>
            /// sets the appropriate start value and calculates the diffValue
            /// </summary>
            internal void prepareForUse()
            {
                if (easeFunction == null)
                {
                    easeFunction = defaultEaseFunction;
                }

                switch (tweenType)
                {
                case TweenType.Position:
                    targetValueType = TargetValueType.Vector3;
                    _startVector    = transform.position;
                    break;

                case TweenType.LocalPosition:
                    targetValueType = TargetValueType.Vector3;
                    _startVector    = transform.localPosition;
                    break;

                case TweenType.Scale:
                    targetValueType = TargetValueType.Vector3;
                    _startVector    = transform.localScale;
                    break;

                case TweenType.Rotation:
                    targetValueType = TargetValueType.Vector3;
                    _startVector    = transform.rotation.eulerAngles;

                    if (isRelativeTween)
                    {
                        _diffVector = targetVector;
                    }
                    else
                    {
                        _diffVector = new Vector3(Mathf.DeltaAngle(_startVector.x, targetVector.x), Mathf.DeltaAngle(_startVector.y, targetVector.y), Mathf.DeltaAngle(_startVector.z, targetVector.z));
                    }
                    break;

                case TweenType.LocalRotation:
                    targetValueType = TargetValueType.Vector3;
                    _startVector    = transform.localRotation.eulerAngles;

                    if (isRelativeTween)
                    {
                        _diffVector = targetVector;
                    }
                    else
                    {
                        _diffVector = new Vector3(Mathf.DeltaAngle(_startVector.x, targetVector.x), Mathf.DeltaAngle(_startVector.y, targetVector.y), Mathf.DeltaAngle(_startVector.z, targetVector.z));
                    }
                    break;

                case TweenType.RectTransformPosition:
                    targetValueType = TargetValueType.Vector3;
                    _startVector    = rectTransform.anchoredPosition3D;
                    break;

                case TweenType.Color:
                    targetValueType = TargetValueType.Color;
                    break;

                case TweenType.Action:
                    targetValueType = TargetValueType.None;
                    break;

                case TweenType.Property:
                    targetValueType = TargetValueType.None;
                    propertyTween.prepareForUse();
                    break;
                }

                _elapsedTime = -delay;

                // we have to be careful with rotations because we always want to rotate in the shortest angle so we set the diffValue with that in mind
                if (targetValueType == TargetValueType.Vector3 && tweenType != TweenType.Rotation && tweenType != TweenType.LocalRotation)
                {
                    if (isRelativeTween)
                    {
                        _diffVector = targetVector;
                    }
                    else
                    {
                        _diffVector = targetVector - _startVector;
                    }
                }
                else if (targetValueType == TargetValueType.Color)
                {
                    _material   = transform.GetComponent <Renderer>().material;
                    _startColor = _material.GetColor(materialProperty);

                    if (isRelativeTween)
                    {
                        _diffColor = targetColor;
                    }
                    else
                    {
                        _diffColor = targetColor - _startColor;
                    }
                }
            }