/// ---------------------------------------------
/// Ultimate Character Controller
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.UltimateCharacterController.StateSystem
{
using Opsive.Shared.Utility;
using System.Collections.Generic;
using System.Reflection;
///
/// Used by the state system for the default preset. The default preset will only set the property value when there has been a change from another preset.
///
public class DefaultPreset : Preset
{
private Dictionary m_DelegateIndexMap;
///
/// Creates a default preset.
///
/// The created preset.
public static DefaultPreset CreateDefaultPreset()
{
var preset = CreateInstance();
preset.hideFlags = UnityEngine.HideFlags.HideAndDontSave;
return preset;
}
///
/// Initializes the preset with the specified visiblity. The preset must be initialized before the preset values are applied so the delegates can be created.
///
/// The object to map the delegates to.
/// Specifies the visibility of the field/properties that should be retrieved.
public override void Initialize(object obj, MemberVisibility visibility)
{
base.Initialize(obj, visibility);
m_DelegateIndexMap = new Dictionary();
for (int i = 0; i < m_Delegates.Length; ++i) {
m_DelegateIndexMap.Add(m_Delegates[i].SetMethod, i);
}
}
///
/// Applies the values to the component specified by the delegates.
///
/// The properties that were changed.
public override void ApplyValues(BaseDelegate[] delegates)
{
// Only apply the properties that were changed. This is determined by the delegates array.
for (int i = 0; i < delegates.Length; ++i) {
var index = m_DelegateIndexMap[delegates[i].SetMethod];
m_Delegates[index].ApplyValue();
}
}
}
}