예제 #1
0
    /// <summary>
    /// Takes the names, types etc. in DisplayBindings and uses reflection to find a PropertyInfo for them.
    /// Only call on start, or when something has been changed in the editor (NOT every frame) as it's heavy.
    /// </summary>
    public void BindToReflectedProperties()
    {
        //Call reflection once to get references to the properties for the displayers that aren't heavy later.
        for (int i = 0; i < _displayBindings.Count; i++)
        {
            //We have to replace the struct with a new one because we're stuck with structs because serialization.
            PropertyInfo newinfo = PartType.GetProperty(_displayBindings[i].PropertyName);

            DisplayPropBinding newbinding = new DisplayPropBinding
            {
                PropertyName       = _displayBindings[i].PropertyName,
                Display            = _displayBindings[i].Display,
                PropertyTypeString = _displayBindings[i].PropertyTypeString,
                Info = newinfo
            };
            _displayBindings[i] = newbinding;
        }

        //Now call reflection for the control properties
        //ClearControlActionsByPart();
        //Note that if this isn't done at start, you should've called ClearControlActionsByPart first so you don't get duplicates or leave actions on parts no longer bound.

        for (int i = 0; i < _controlBindings.Count; i++)
        {
            //We have to replace the struct with a new one because we're stuck with structs because serialization.
            PropertyInfo newinfo = PartType.GetProperty(_controlBindings[i].PropertyName);

            ControlPropBinding newbinding = new ControlPropBinding
            {
                PropertyName       = _controlBindings[i].PropertyName,
                Control            = _controlBindings[i].Control,
                PropertyTypeString = _controlBindings[i].PropertyTypeString,
                Info = newinfo
            };
            _controlBindings[i] = newbinding;

            //Create and assign an action for setting the property to the control, if there is one.
            //TODO: Clean up past assignments.
            if (newbinding.Control) //
            {
                AssignSetterToControl(newbinding);
            }
        }
    }