diff --git a/Package/Editor/TMPEffects.Editor.asmdef b/Package/Editor/TMPEffects.Editor.asmdef index afe80a59..86254196 100644 --- a/Package/Editor/TMPEffects.Editor.asmdef +++ b/Package/Editor/TMPEffects.Editor.asmdef @@ -5,7 +5,8 @@ "GUID:96c64e576ede81e46ad482a315c680f9", "GUID:6055be8ebefd69e48b49212b09b47b2f", "GUID:4bd7a8fb744c5fd43886f1e1d2e6bde3", - "GUID:bc50dcdb89ada6249b1b82bd70623a05" + "GUID:bc50dcdb89ada6249b1b82bd70623a05", + "GUID:3af83a76aff21f94faea8408f8eb05d3" ], "includePlatforms": [ "Editor" diff --git a/Package/Runtime/Components/TMPAnimator/AnimationDatabase.cs b/Package/Runtime/Components/TMPAnimator/AnimationDatabase.cs index 3a4c27e2..246d4183 100644 --- a/Package/Runtime/Components/TMPAnimator/AnimationDatabase.cs +++ b/Package/Runtime/Components/TMPAnimator/AnimationDatabase.cs @@ -30,7 +30,7 @@ public AnimationDatabase(TDB database, SerializedObservableDictionary(); if (database != null) database.ObjectChanged += RaiseObjectChanged; - if (sceneAnimations != null) sceneAnimations.PropertyChanged += RaiseObjectChanged; + if (sceneAnimations != null) sceneAnimations.ObjectChanged += RaiseObjectChanged; } public void AddAnimation(string key, ITMPAnimation animation) @@ -78,7 +78,7 @@ public void Dispose() if (disposed) return; disposed = true; if (database != null) database.ObjectChanged -= RaiseObjectChanged; - if (sceneAnimations != null) sceneAnimations.PropertyChanged -= RaiseObjectChanged; + if (sceneAnimations != null) sceneAnimations.ObjectChanged -= RaiseObjectChanged; database = null; sceneAnimations = null; customAnimations = null; diff --git a/Package/Runtime/Effects/TMPSceneAnimations/TMPSceneAnimationBase.cs b/Package/Runtime/Effects/TMPSceneAnimations/TMPSceneAnimationBase.cs index f49de03b..06810f00 100644 --- a/Package/Runtime/Effects/TMPSceneAnimations/TMPSceneAnimationBase.cs +++ b/Package/Runtime/Effects/TMPSceneAnimations/TMPSceneAnimationBase.cs @@ -11,19 +11,29 @@ namespace TMPEffects.TMPSceneAnimations /// /// Base class for all SceneAnimations. /// - public abstract class TMPSceneAnimationBase : MonoBehaviour, ITMPAnimation, INotifyPropertyChanged + public abstract class TMPSceneAnimationBase : MonoBehaviour, ITMPAnimation, INotifyObjectChanged { - public event PropertyChangedEventHandler PropertyChanged; - public abstract void Animate(CharData cData, IAnimationContext context); public abstract object GetNewCustomData(); public abstract void SetParameters(object customData, IDictionary parameters); public abstract bool ValidateParameters(IDictionary parameters); - + + public event ObjectChangedEventHandler ObjectChanged; + protected virtual void OnValidate() { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("")); + RaiseObjectChanged(); + } + + protected virtual void OnDestroy() + { + RaiseObjectChanged(); + } + + protected void RaiseObjectChanged() + { + ObjectChanged?.Invoke(this); } } } diff --git a/Package/Runtime/ObjectChangedEvent/TMPEffects.NotifyObjectChanged.asmdef b/Package/Runtime/ObjectChangedEvent/TMPEffects.NotifyObjectChanged.asmdef new file mode 100644 index 00000000..f1f9f659 --- /dev/null +++ b/Package/Runtime/ObjectChangedEvent/TMPEffects.NotifyObjectChanged.asmdef @@ -0,0 +1,14 @@ +{ + "name": "TMPEffects.NotifyObjectChanged", + "rootNamespace": "", + "references": [], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Package/Runtime/ObjectChangedEvent/TMPEffects.NotifyObjectChanged.asmdef.meta b/Package/Runtime/ObjectChangedEvent/TMPEffects.NotifyObjectChanged.asmdef.meta new file mode 100644 index 00000000..38084266 --- /dev/null +++ b/Package/Runtime/ObjectChangedEvent/TMPEffects.NotifyObjectChanged.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 3af83a76aff21f94faea8408f8eb05d3 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Package/Runtime/SerializedDictionary/Editor/Scripts/SerializedObservableDictionaryDrawer.cs b/Package/Runtime/SerializedDictionary/Editor/Scripts/SerializedObservableDictionaryDrawer.cs index 45e877a1..d25826e7 100644 --- a/Package/Runtime/SerializedDictionary/Editor/Scripts/SerializedObservableDictionaryDrawer.cs +++ b/Package/Runtime/SerializedDictionary/Editor/Scripts/SerializedObservableDictionaryDrawer.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.ComponentModel; +using TMPEffects.ObjectChanged; using UnityEditor; using UnityEngine; @@ -10,8 +11,8 @@ internal class SerializedObservableDictionaryDrawer : PropertyDrawer { public const string KeyName = nameof(SerializedKeyValuePair.Key); public const string ValueName = nameof(SerializedKeyValuePair.Value); - public const string SerializedListName = nameof(SerializedObservableDictionary._serializedList); - public const string LookupTableName = nameof(SerializedObservableDictionary.LookupTable); + public const string SerializedListName = nameof(SerializedObservableDictionary._serializedList); + public const string LookupTableName = nameof(SerializedObservableDictionary.LookupTable); public const int TopHeaderClipHeight = 20; public const int TopHeaderHeight = 19; diff --git a/Package/Runtime/SerializedDictionary/Editor/TMPEffects.SerializedCollections.Editor.asmdef b/Package/Runtime/SerializedDictionary/Editor/TMPEffects.SerializedCollections.Editor.asmdef index db897879..735680e2 100644 --- a/Package/Runtime/SerializedDictionary/Editor/TMPEffects.SerializedCollections.Editor.asmdef +++ b/Package/Runtime/SerializedDictionary/Editor/TMPEffects.SerializedCollections.Editor.asmdef @@ -2,7 +2,8 @@ "name": "TMPEffects.SerializedCollections.Editor", "rootNamespace": "", "references": [ - "GUID:bc50dcdb89ada6249b1b82bd70623a05" + "GUID:bc50dcdb89ada6249b1b82bd70623a05", + "GUID:3af83a76aff21f94faea8408f8eb05d3" ], "includePlatforms": [ "Editor" diff --git a/Package/Runtime/SerializedDictionary/Runtime/Scripts/SerializedDictionary.cs b/Package/Runtime/SerializedDictionary/Runtime/Scripts/SerializedDictionary.cs index 4a9abb21..0d44d589 100644 --- a/Package/Runtime/SerializedDictionary/Runtime/Scripts/SerializedDictionary.cs +++ b/Package/Runtime/SerializedDictionary/Runtime/Scripts/SerializedDictionary.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.ComponentModel; +using TMPEffects.ObjectChanged; using UnityEngine; namespace TMPEffects.SerializedCollections @@ -68,7 +69,7 @@ internal interface ISerializedDictionary : IDictionary : IDictionary, INotifyPropertyChanged, IDisposable where TValue : INotifyPropertyChanged + public class ObservableDictionary : IDictionary, INotifyObjectChanged, IDisposable where TValue : INotifyObjectChanged { protected bool mayRaise = true; private Dictionary _dictionary = new Dictionary(); @@ -91,7 +92,7 @@ public TValue this[TKey key] public bool IsReadOnly => ((ICollection>)_dictionary).IsReadOnly; - public event PropertyChangedEventHandler PropertyChanged; + public event ObjectChangedEventHandler ObjectChanged; public void Add(TKey key, TValue value) { @@ -99,7 +100,7 @@ public void Add(TKey key, TValue value) RaisePropertyChanged(); if (value != null) { - value.PropertyChanged += RaisePropertyChanged; + value.ObjectChanged += RaisePropertyChanged; } } @@ -108,7 +109,7 @@ public void Add(KeyValuePair item) ((ICollection>)_dictionary).Add(item); RaisePropertyChanged(); if (item.Value != null) - item.Value.PropertyChanged += RaisePropertyChanged; + item.Value.ObjectChanged += RaisePropertyChanged; } public void Clear() @@ -116,7 +117,7 @@ public void Clear() foreach (var kvp in _dictionary) { if (kvp.Value != null) - kvp.Value.PropertyChanged -= RaisePropertyChanged; + kvp.Value.ObjectChanged -= RaisePropertyChanged; } _dictionary.Clear(); @@ -147,7 +148,7 @@ public bool Remove(TKey key) { if (_dictionary.ContainsKey(key)) { - _dictionary[key].PropertyChanged -= RaisePropertyChanged; + _dictionary[key].ObjectChanged -= RaisePropertyChanged; if (!_dictionary.Remove(key)) { throw new System.InvalidOperationException("Failed to remove key despite it being present?"); @@ -163,7 +164,7 @@ public bool Remove(KeyValuePair item) { if (((IDictionary)_dictionary).Contains(item)) { - _dictionary[item.Key].PropertyChanged -= RaisePropertyChanged; + _dictionary[item.Key].ObjectChanged -= RaisePropertyChanged; if (!_dictionary.Remove(item.Key)) { throw new System.InvalidOperationException("Failed to remove key despite it being present?"); @@ -192,17 +193,17 @@ public void Dispose() protected void RaisePropertyChanged() { - if (mayRaise) PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("dictionary")); + if (mayRaise) ObjectChanged?.Invoke(this); } - protected void RaisePropertyChanged(object sender, PropertyChangedEventArgs args) + protected void RaisePropertyChanged(object sender) { - if (mayRaise) PropertyChanged?.Invoke(this, args); + if (mayRaise) ObjectChanged?.Invoke(this); } } [System.Serializable] - public partial class SerializedObservableDictionary : ObservableDictionary, ISerializedDictionary, ISerializationCallbackReceiver where TValue : INotifyPropertyChanged + public partial class SerializedObservableDictionary : ObservableDictionary, ISerializedDictionary, ISerializationCallbackReceiver where TValue : INotifyObjectChanged { public List> SerializedList { diff --git a/Package/Runtime/SerializedDictionary/Runtime/TMPEffects.SerializedCollections.asmdef b/Package/Runtime/SerializedDictionary/Runtime/TMPEffects.SerializedCollections.asmdef index 6b8a392a..b0d36551 100644 --- a/Package/Runtime/SerializedDictionary/Runtime/TMPEffects.SerializedCollections.asmdef +++ b/Package/Runtime/SerializedDictionary/Runtime/TMPEffects.SerializedCollections.asmdef @@ -1,7 +1,7 @@ { "name": "TMPEffects.SerializedCollections", "rootNamespace": "", - "references": [], + "references": ["GUID:3af83a76aff21f94faea8408f8eb05d3"], "includePlatforms": [], "excludePlatforms": [], "allowUnsafeCode": false, diff --git a/Package/Runtime/TMPEffects.asmdef b/Package/Runtime/TMPEffects.asmdef index 2b618e89..fb887d88 100644 --- a/Package/Runtime/TMPEffects.asmdef +++ b/Package/Runtime/TMPEffects.asmdef @@ -3,7 +3,8 @@ "rootNamespace": "", "references": [ "GUID:6055be8ebefd69e48b49212b09b47b2f", - "GUID:bc50dcdb89ada6249b1b82bd70623a05" + "GUID:bc50dcdb89ada6249b1b82bd70623a05", + "GUID:3af83a76aff21f94faea8408f8eb05d3" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Package/Tests/TMPEffects.Tests.asmdef b/Package/Tests/TMPEffects.Tests.asmdef index f3b628ba..120cc109 100644 --- a/Package/Tests/TMPEffects.Tests.asmdef +++ b/Package/Tests/TMPEffects.Tests.asmdef @@ -8,7 +8,8 @@ "Unity.PerformanceTesting.Editor", "TMPEffects", "Unity.TextMeshPro", - "TMPEffects.Editor" + "TMPEffects.Editor", + "TMPEffects.NotifyObjectChanged" ], "includePlatforms": [ "Editor"