Axiom.Serialization.MaterialSerializer.ParseColorOpEx C# (CSharp) Метод

ParseColorOpEx() приватный Метод

private ParseColorOpEx ( string parameters, MaterialScriptContext context ) : bool
parameters string
context MaterialScriptContext
Результат bool
		protected static bool ParseColorOpEx( string parameters, MaterialScriptContext context )
		{
			string[] values = parameters.ToLower().Split( new char[] { ' ', '\t' } );

			if ( values.Length < 3 || values.Length > 10 )
			{
				LogParseError( context, "Bad color_op_ex attribute, wrong number of parameters (expected 3 or 10)." );
				return false;
			}

			LayerBlendOperationEx op = 0;
			LayerBlendSource src1 = 0;
			LayerBlendSource src2 = 0;
			float manual = 0.0f;
			ColorEx colSrc1 = ColorEx.White;
			ColorEx colSrc2 = ColorEx.White;

			try
			{
				op = (LayerBlendOperationEx)ScriptEnumAttribute.Lookup( values[ 0 ], typeof( LayerBlendOperationEx ) );
				src1 = (LayerBlendSource)ScriptEnumAttribute.Lookup( values[ 1 ], typeof( LayerBlendSource ) );
				src2 = (LayerBlendSource)ScriptEnumAttribute.Lookup( values[ 2 ], typeof( LayerBlendSource ) );

				if ( op == LayerBlendOperationEx.BlendManual )
				{
					if ( values.Length < 4 )
					{
						LogParseError( context, "Bad color_op_ex attribute, wrong number of parameters (expected 4 params for manual blending)." );
						return false;
					}

					manual = int.Parse( values[ 3 ] );
				}

				if ( src1 == LayerBlendSource.Manual )
				{
					int paramIndex = 3;
					if ( op == LayerBlendOperationEx.BlendManual )
					{
						paramIndex++;
					}

					if ( values.Length < paramIndex + 3 )
					{
						LogParseError( context, "Bad color_op_ex attribute, wrong number of parameters (expected {0}).", paramIndex + 3 );
						return false;
					}

					colSrc1.r = StringConverter.ParseFloat( values[ paramIndex++ ] );
					colSrc1.g = StringConverter.ParseFloat( values[ paramIndex++ ] );
					colSrc1.b = StringConverter.ParseFloat( values[ paramIndex ] );

					if ( values.Length > paramIndex )
					{
						colSrc1.a = StringConverter.ParseFloat( values[ paramIndex ] );
					}
					else
					{
						colSrc1.a = 1.0f;
					}
				}

				if ( src2 == LayerBlendSource.Manual )
				{
					int paramIndex = 3;

					if ( op == LayerBlendOperationEx.BlendManual )
					{
						paramIndex++;
					}

					if ( values.Length < paramIndex + 3 )
					{
						LogParseError( context, "Bad color_op_ex attribute, wrong number of parameters (expected {0}).", paramIndex + 3 );
						return false;
					}

					colSrc2.r = StringConverter.ParseFloat( values[ paramIndex++ ] );
					colSrc2.g = StringConverter.ParseFloat( values[ paramIndex++ ] );
					colSrc2.b = StringConverter.ParseFloat( values[ paramIndex++ ] );

					if ( values.Length > paramIndex )
					{
						colSrc2.a = StringConverter.ParseFloat( values[ paramIndex ] );
					}
					else
					{
						colSrc2.a = 1.0f;
					}
				}
			}
			catch ( Exception ex )
			{
				LogParseError( context, "Bad color_op_ex attribute, {0}.", ex.Message );
				return false;
			}

			context.textureUnit.SetColorOperationEx( op, src1, src2, colSrc1, colSrc2, manual );

			return false;
		}