using System;
using System.Collections.Generic;
using UnityEngine.Localization.Settings;
namespace UnityEngine.Localization
{
#if UNITY_EDITOR
///
/// Driver for properties that are modified by event calls.
///
internal class LocalizationPropertyDriver : PropertyDriver
{
///
/// When making a change using a UnityEvent we need to determine what serialized property this change will affect In order to register the property as driven.
/// This maps known UnityEvent target types and method names to their serialized property paths so that they can be marked as driven.
///
internal static Dictionary<(Type targetType, string methodName), string> UnityEventDrivenPropertiesLookup { get; } = new Dictionary<(Type targetType, string methodName), string>();
}
#endif
///
/// Allows for making temporary changes to Components in a scene whilst previewing a Locale.
/// Any changes made to a property that is marked as driven will be ignored when saving the scene
/// and reverted when the property is unregistered or is set to .
///
public static class EditorPropertyDriver
{
///
/// Mark the property as Driven in the editor.
/// When a property is marked as driven it is considered to be a temporary change, that is the new values applied to the property
/// will be ignored and not saved into the scene. The value will revert back to its original value when
/// is called or is set to .
/// Calling this method in play mode or a player build will do nothing.
///
///
/// This shows how to support non-destructive Edit Mode changes using .
///
///
/// The object that the property is part of.
/// The serialized property path. The value that would be used to access using a [SerializedProperty](https://docs.unity3d.com/ScriptReference/SerializedProperty.html)
public static void RegisterProperty(Object target, string propertyPath)
{
#if UNITY_EDITOR
if (!LocalizationSettings.Instance.IsPlayingOrWillChangePlaymode)
LocalizationPropertyDriver.RegisterProperty(target, propertyPath);
#endif
}
///
/// Removed the property tracking and reverts the value back to the original value it was before was called.
/// In most cases you will not need to call this unless the driven properties are likely to change dynamically.
/// Calling this method in play mode or a player build will do nothing.
///
/// The object that the property is part of.
/// The serialized property path. The value that would be used to access using a [SerializedProperty](https://docs.unity3d.com/ScriptReference/SerializedProperty.html)
public static void UnregisterProperty(Object target, string propertyPath)
{
#if UNITY_EDITOR
if (!LocalizationSettings.Instance.IsPlayingOrWillChangePlaymode)
LocalizationPropertyDriver.RegisterProperty(target, propertyPath);
#endif
}
}
}