public void Reflect(Object obj, Attribute attribute, bool initialize = false) { int vid = m_config.m_reflection_property; if (vid != 0) { int component_type_id = ComponentTypeRegistry.GetVariableOwnerComponentID(vid); if (component_type_id != 0) { Component component = obj.GetComponent(component_type_id); if (component != null) { FixPoint old_value = component.GetVariable(vid); FixPoint new_value = attribute.Value; if (old_value != new_value) { component.SetVariable(vid, attribute.Value); } } } } vid = m_config.m_clamp_property; if (vid != 0) { int component_type_id = ComponentTypeRegistry.GetVariableOwnerComponentID(vid); if (component_type_id != 0) { Component component = obj.GetComponent(component_type_id); if (component != null) { FixPoint old_value = component.GetVariable(vid); if (initialize) { if (old_value < m_config.m_clamp_min_value) //ZZWTODO tricky { component.SetVariable(vid, attribute.Value); } } else { FixPoint new_value = FixPoint.Clamp(old_value, m_config.m_clamp_min_value, attribute.Value); if (old_value != new_value) { component.SetVariable(vid, new_value); } } } } } //END }
public static FixPoint GetVariable(Object obj, int vid) { int component_type_id = ComponentTypeRegistry.GetVariableOwnerComponentID(vid); if (component_type_id == 0) { return(FixPoint.Zero); } while (obj != null) { Component component = obj.GetComponent(component_type_id); if (component != null) { FixPoint value; if (component.GetVariable(vid, out value)) { return(value); } } obj = obj.GetOwnerObject(); } return(FixPoint.Zero); }