Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Mutate()
- {
- foreach (MutatableProperty prop in MutatableProperties)
- {
- if (Random.Range(0f, 1f) <= prop.MutationProbability)
- {
- AnimationCurve curve = prop.MutationCurve;
- int keynumberincurve = prop.MutationCurve.length;
- float mutationmodifer = prop.MutationCurve.Evaluate(Random.Range(curve.keys[0].time, curve.keys[keynumberincurve-1].time));
- PropertyInfo propinfo = MutatableObject.GetType().GetProperty(prop.PropertyName); //https://stackoverflow.com/questions/6637679/reflection-get-attribute-name-and-value-on-property
- object unkownValue = propinfo.GetValue(MutatableObject); //https://stackoverflow.com/questions/26382810/how-do-you-get-the-value-of-a-property-from-propertyinfo
- ChangeValues(unkownValue, mutationmodifer, propinfo.Name);
- foreach (Constraint constraint in prop.Constrains) //handle constraints
- {
- PropertyInfo ConstrPropInfo = MutatableObject.GetType().GetProperty(prop.PropertyName);
- object temp2 = propinfo.GetValue(MutatableObject);
- }
- }
- }
- }
- public void ChangeValues(object valueToChange, float mutationmodifer, string variablename) //remove variablename and debugs later
- {
- switch (valueToChange) //https://stackoverflow.com/questions/298976/is-there-a-better-alternative-than-this-to-switch-on-type
- {
- case float f:
- f *= 1 + mutationmodifer;
- Debug.Log($"As mutationvalue is {mutationmodifer} new Value of {variablename} is {f}.");
- break;
- case int i:
- i = (int)(i * (1 + mutationmodifer));
- Debug.Log($"As mutationvalue is {mutationmodifer} new Value of {variablename} is {i}."); break;
- case string s:
- Debug.Log("string is unsupported");
- break;
- default:
- Debug.Log($"Unsupported datatype : {nameof(valueToChange)}");
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement