4 using System.Collections.Generic;
7 using SiliconStudio.Core;
8 using SiliconStudio.Core.Serialization;
9 using SiliconStudio.Paradox.Effects;
11 namespace SiliconStudio.Paradox.Assets.Effect.ValueGenerators
23 [DataContract(
"!fx.generator.standard")]
24 [SiliconStudio.Core.Serialization.Serializers.DataSerializer(typeof(EffectParameterKeyStandardGeneratorSerializer))]
29 foreach (var item
in this)
32 if (collectionGenerator != null)
34 foreach (var effectParameterValueGenerator
in collectionGenerator)
36 foreach (var value
in effectParameterValueGenerator.GenerateValues(item.Key))
38 yield
return CreateKeyValue(item.Key, value);
45 if (valueGenerator != null)
47 foreach (var value
in valueGenerator.GenerateValues(item.Key))
49 yield
return CreateKeyValue(item.Key, value);
54 var directValues = item.Value as IList<object>;
55 if (directValues != null)
57 foreach (var value
in directValues)
59 yield
return CreateKeyValue(item.Key, value);
64 yield
return CreateKeyValue(item.Key, item.Value);
72 private KeyValuePair<ParameterKey, object> CreateKeyValue(
ParameterKey key,
object value)
76 var keyName= key.Name;
77 key = ParameterKeys.FindByName(keyName);
80 throw new InvalidOperationException(
"ParameterKey [{0}] was not found from assemblies".ToFormat(keyName));
83 return new KeyValuePair<ParameterKey, object>(key, key.ConvertValue(value));
87 internal static class EffectParameterGeneratorExtensions
89 private static readonly IList<KeyValuePair<ParameterKey, List<object>>> EmptyKeyValuePairs =
new List<KeyValuePair<ParameterKey, List<object>>>().AsReadOnly();
91 public static IList<KeyValuePair<ParameterKey, List<object>>> GenerateKeyValues(
this IEffectParameterGenerator generator)
93 if (generator == null)
95 return EmptyKeyValuePairs;
98 var keyValues =
new Dictionary<ParameterKey, List<object>>();
99 foreach (var keyValue
in generator.Generate())
102 if (!keyValues.TryGetValue(keyValue.Key, out values))
104 values =
new List<object>();
105 keyValues.Add(keyValue.Key, values);
107 values.Add(keyValue.Value);
109 return keyValues.ToList();
113 internal class EffectParameterKeyStandardGeneratorSerializer :
DataSerializer<EffectParameterKeyStandardGenerator>
120 stream.Write(obj.Count);
121 foreach (var item
in obj)
123 stream.SerializeExtended(item.Key, mode);
124 var valueType = item.Value.GetType();
125 if (valueType.IsGenericType && valueType.GetGenericTypeDefinition() == typeof(EffectParameterValuesGenerator<>))
127 var value = (IEffectParameterValueGenerator)item.Value;
128 var
count = value.GenerateValues(item.Key).Count();
130 foreach (var item2
in value.GenerateValues(item.Key))
132 stream.SerializeExtended(item2, mode);
137 stream.SerializeExtended(item.Value, mode);
143 throw new NotImplementedException();
Key of an effect parameter.
Generates key-value permutations.
Default implementation for a IEffectParameterGenerator using a dictionary of ParameterKey associated ...
Base class for implementation of SerializationStream.
IEnumerable< KeyValuePair< ParameterKey, object > > Generate()
Generates key-value permutations.
A list of IEffectParameterValueGenerator.
Describes how to serialize and deserialize an object without knowing its type. Used as a common base ...
ArchiveMode
Enumerates the different mode of serialization (either serialization or deserialization).
Generates values for a specific key.