/// <summary> /// Get a field from a script and set this value in a hero object list. /// </summary> /// <param name="heroKitObject">The hero kit object that contains the data for this action.</param> /// <param name="actionFieldIDB">ID assigned to action field B.</param> /// <param name="field">The field in the script.</param> /// <param name="component">The script component on the hero kit object.</param> private static void SetFieldOnHero(HeroKitObject heroKitObject, int actionFieldIDB, FieldInfo field, MonoBehaviour component) { // Get value type on the target instance. object valueType = field.FieldType; // Test value type. if (valueType == typeof(int)) { int value = (int)field.GetValue(component); IntegerFieldValue.SetValueB(heroKitObject, actionFieldIDB, value); } else if (valueType == typeof(float)) { float value = (float)field.GetValue(component);; FloatFieldValue.SetValueB(heroKitObject, actionFieldIDB, value); } else if (valueType == typeof(string)) { string value = (string)field.GetValue(component);; StringFieldValue.SetValueB(heroKitObject, actionFieldIDB, value); } else if (valueType == typeof(bool)) { bool value = (bool)field.GetValue(component);; BoolFieldValue.SetValueB(heroKitObject, actionFieldIDB, value); } else if (valueType == typeof(HeroKitObject)) { HeroKitObject value = (HeroKitObject)field.GetValue(component);; List <HeroKitObject> hko = new List <HeroKitObject>(); hko.Add((HeroKitObject)value); HeroObjectFieldValue.SetValueB(heroKitObject, actionFieldIDB, hko); } else if (valueType == typeof(GameObject)) { GameObject value = (GameObject)field.GetValue(component);; GameObjectFieldValue.SetValueB(heroKitObject, actionFieldIDB, value); } }
/// <summary> /// Get a property from a script and set this value in a hero object list. /// </summary> /// <param name="heroKitObject">The hero kit object that contains the data for this action.</param> /// <param name="actionFieldIDB">ID assigned to action field B.</param> /// <param name="property">The property in the script.</param> /// <param name="component">The script component on the hero kit object.</param> public static void SetPropertyOnHero(HeroKitObject heroKitObject, int actionFieldIDB, PropertyInfo property, MonoBehaviour component) { // Get value type on the target instance. object valueType = property.PropertyType; // Test value type. if (valueType == typeof(int)) { int value = (int)property.GetValue(component, null); IntegerFieldValue.SetValueB(heroKitObject, actionFieldIDB, value); } else if (valueType == typeof(float)) { float value = (float)property.GetValue(component, null);; FloatFieldValue.SetValueB(heroKitObject, actionFieldIDB, value); } else if (valueType == typeof(string)) { string value = (string)property.GetValue(component, null);; StringFieldValue.SetValueB(heroKitObject, actionFieldIDB, value); } else if (valueType == typeof(bool)) { bool value = (bool)property.GetValue(component, null);; BoolFieldValue.SetValueB(heroKitObject, actionFieldIDB, value); } else if (valueType == typeof(HeroKitObject)) { HeroKitObject value = (HeroKitObject)property.GetValue(component, null);; List <HeroKitObject> hko = new List <HeroKitObject>(); hko.Add((HeroKitObject)value); HeroObjectFieldValue.SetValueB(heroKitObject, actionFieldIDB, hko); } else if (valueType == typeof(GameObject)) { GameObject value = (GameObject)property.GetValue(component, null);; GameObjectFieldValue.SetValueB(heroKitObject, actionFieldIDB, value); } }
// -------------------------------------------------------------- // Helpers // -------------------------------------------------------------- /// <summary> /// Get a value from a hero object list and set this value for a field in a script. /// </summary> /// <param name="heroKitObject">The hero kit object that contains the data for this action.</param> /// <param name="actionFieldIDB">ID assigned to action field B.</param> /// <param name="field">The field in the script.</param> /// <param name="component">The script component on the hero kit object.</param> private static void SetFieldOnScript(HeroKitObject heroKitObject, int actionFieldIDB, FieldInfo field, MonoBehaviour component) { // Get value on the target instance. object value = field.FieldType; // Test value type. if (value == typeof(int)) { int newValue = IntegerFieldValue.GetValueA(heroKitObject, actionFieldIDB); field.SetValue(component, newValue); } else if (value == typeof(float)) { float newValue = FloatFieldValue.GetValueA(heroKitObject, actionFieldIDB); field.SetValue(component, newValue); } else if (value == typeof(string)) { string newValue = StringFieldValue.GetValueA(heroKitObject, actionFieldIDB); field.SetValue(component, newValue); } else if (value == typeof(bool)) { bool newValue = BoolFieldValue.GetValueA(heroKitObject, actionFieldIDB); field.SetValue(component, newValue); } else if (value == typeof(HeroKitObject)) { HeroKitObject newValue = HeroObjectFieldValue.GetValueA(heroKitObject, actionFieldIDB)[0]; field.SetValue(component, newValue); } else if (value == typeof(GameObject)) { GameObject newValue = GameObjectFieldValue.GetValueA(heroKitObject, actionFieldIDB); field.SetValue(component, newValue); } }
/// <summary> /// Get a value from a hero object list and set this value for a property in a script. /// </summary> /// <param name="heroKitObject">The hero kit object that contains the data for this action.</param> /// <param name="actionFieldIDB">ID assigned to action field B.</param> /// <param name="property">The property in the script.</param> /// <param name="component">The script component on the hero kit object.</param> public static void SetPropertyOnScript(HeroKitObject heroKitObject, int actionFieldIDB, PropertyInfo property, MonoBehaviour component) { // Get value on the target instance. object value = property.PropertyType; // Test value type. if (value == typeof(int)) { int newValue = IntegerFieldValue.GetValueA(heroKitObject, actionFieldIDB); property.SetValue(component, newValue, null); } else if (value == typeof(float)) { float newValue = FloatFieldValue.GetValueA(heroKitObject, actionFieldIDB); property.SetValue(component, newValue, null); } else if (value == typeof(string)) { string newValue = StringFieldValue.GetValueA(heroKitObject, actionFieldIDB); property.SetValue(component, newValue, null); } else if (value == typeof(bool)) { bool newValue = BoolFieldValue.GetValueA(heroKitObject, actionFieldIDB); property.SetValue(component, newValue, null); } else if (value == typeof(HeroKitObject)) { HeroKitObject newValue = HeroObjectFieldValue.GetValueA(heroKitObject, actionFieldIDB)[0]; property.SetValue(component, newValue, null); } else if (value == typeof(GameObject)) { GameObject newValue = GameObjectFieldValue.GetValueA(heroKitObject, actionFieldIDB); property.SetValue(component, newValue, null); } }