コード例 #1
0
    //return component is changes have been made
    public Component RestoreSettings()
    {
        Component resultChangedComponent = null;

        if (!_isComponentObjectNull)
        {
            ComponentObject = EditorUtility.InstanceIDToObject(ComponentObject.GetInstanceID()) as Component;
        }
        else
        {
            ComponentObject = null;
        }

        if (ComponentObject != null && _values != null)
        {
            foreach (var name in _values.Keys)
            {
                var newValue = _values[name];

                var property = ComponentObject.GetType().GetProperty(name);

                if (null != property)
                {
                    var currentValue = property.GetValue(ComponentObject, null);

                    if (!HasValueChanged(newValue, currentValue))
                    {
                        continue;
                    }
                    property.SetValue(ComponentObject, newValue, null);
                    resultChangedComponent = ComponentObject;
                }
                else
                {
                    var field        = ComponentObject.GetType().GetField(name);
                    var currentValue = field.GetValue(ComponentObject);

                    if (!HasValueChanged(newValue, currentValue))
                    {
                        continue;
                    }

                    field.SetValue(ComponentObject, newValue);
                    resultChangedComponent = ComponentObject;
                }
            }
        }

        _values = null;

        return(resultChangedComponent);
    }
コード例 #2
0
    public void RestoreSettings()
    {
        if (ComponentObject != null)
        {
            ComponentObject = EditorUtility.InstanceIDToObject(ComponentObject.GetInstanceID()) as Component;
        }

        if (IsSavingSettings && null != ComponentObject && null != values)
        {
            foreach (string name in values.Keys)
            {
                object newValue = values[name];

                PropertyInfo property = ComponentObject.GetType().GetProperty(name);

                if (null != property)
                {
                    object currentValue = property.GetValue(ComponentObject, null);

                    if (HasValueChanged(newValue, currentValue))
                    {
                        property.SetValue(ComponentObject, newValue, null);
                    }
                }
                else
                {
                    FieldInfo field        = ComponentObject.GetType().GetField(name);
                    object    currentValue = field.GetValue(ComponentObject);

                    if (HasValueChanged(newValue, currentValue))
                    {
                        field.SetValue(ComponentObject, newValue);
                    }
                }
            }
        }

        values = null;
    }
コード例 #3
0
    //return component is changes have been made
    public Component RestoreSettings()
    {
        Component resultChangedComponent = null;

        if (!_isComponentObjectNull)
        {
            ComponentObject = EditorUtility.InstanceIDToObject(ComponentObject.GetInstanceID()) as Component;
        }
        else
        {
            ComponentObject = null;
        }

        if (ComponentObject != null && _values != null)
        {
            foreach (var name in _values.Keys)
            {
                var newValue = _values[name];

                var property = ComponentObject.GetType().GetProperty(name);

                if (null != property)
                {
                    var currentValue = property.GetValue(ComponentObject, null);

                    if (!HasValueChanged(newValue, currentValue))
                    {
                        continue;
                    }

                    property.SetValue(ComponentObject, newValue, null);
                    resultChangedComponent = ComponentObject;
                }
                else
                {
                    var field        = ComponentObject.GetType().GetField(name);
                    var currentValue = field.GetValue(ComponentObject);

                    if (!HasValueChanged(newValue, currentValue))
                    {
                        continue;
                    }

                    if (ComponentObject.ToString().Contains("DarkTonic.MasterAudio.MasterAudio"))
                    {
                        switch (field.Name)
                        {
                        case "customEvents":
                            FilterOutDGSCCustomEvents(ref newValue);
                            break;

                        case "customEventCategories":
                            FilterOutDGSCCustomEventCategories(ref newValue);
                            break;

                        case "musicPlaylists":
                            FilterOutDGSCPlaylists(ref newValue);
                            break;

                        case "groupBuses":
                            FilterOutDGSCBuses(ref newValue);
                            break;

                        case "musicDuckingSounds":
                            FilterOutDGSCDuckGroups(ref newValue);
                            break;
                        }
                    }
                    field.SetValue(ComponentObject, newValue);
                    resultChangedComponent = ComponentObject;
                }
            }
        }

        _values = null;
        return(resultChangedComponent);
    }