Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.24 KB | None | 0 0
  1. public void Mutate()
  2.     {
  3.         foreach (MutatableProperty prop in MutatableProperties)
  4.         {
  5.             if (Random.Range(0f, 1f) <= prop.MutationProbability)
  6.             {
  7.                 AnimationCurve curve = prop.MutationCurve;
  8.                 int keynumberincurve = prop.MutationCurve.length;
  9.                 float mutationmodifer = prop.MutationCurve.Evaluate(Random.Range(curve.keys[0].time, curve.keys[keynumberincurve-1].time));
  10.                 PropertyInfo propinfo = MutatableObject.GetType().GetProperty(prop.PropertyName);       //https://stackoverflow.com/questions/6637679/reflection-get-attribute-name-and-value-on-property
  11.                 object unkownValue = propinfo.GetValue(MutatableObject);                                //https://stackoverflow.com/questions/26382810/how-do-you-get-the-value-of-a-property-from-propertyinfo
  12.  
  13.                 ChangeValues(unkownValue, mutationmodifer, propinfo.Name);
  14.  
  15.                 foreach (Constraint constraint in prop.Constrains) //handle constraints
  16.                 {
  17.                     PropertyInfo ConstrPropInfo = MutatableObject.GetType().GetProperty(prop.PropertyName);
  18.                     object temp2 = propinfo.GetValue(MutatableObject);
  19.                 }
  20.             }
  21.         }
  22.     }
  23.  
  24.     public void ChangeValues(object valueToChange, float mutationmodifer, string variablename) //remove variablename and debugs later
  25.     {
  26.         switch (valueToChange)                                                                           //https://stackoverflow.com/questions/298976/is-there-a-better-alternative-than-this-to-switch-on-type
  27.         {
  28.             case float f:
  29.                 f *= 1 + mutationmodifer;
  30.                 Debug.Log($"As mutationvalue is {mutationmodifer} new Value of {variablename} is {f}.");
  31.                 break;
  32.  
  33.             case int i:
  34.                 i = (int)(i * (1 + mutationmodifer));
  35.                 Debug.Log($"As mutationvalue is {mutationmodifer} new Value of {variablename} is {i}."); break;
  36.  
  37.             case string s:
  38.                 Debug.Log("string is unsupported");
  39.                 break;
  40.  
  41.             default:
  42.                 Debug.Log($"Unsupported datatype : {nameof(valueToChange)}");
  43.                 break;
  44.         }
  45.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement