using System.Collections.Generic; using System.Text; using UnityEditor; namespace TouchScript.Editor.Utils { internal sealed class SerializedPropertyUserData where TUserData : class { public static SerializedPropertyUserData Instance { get { return instance; } } private static SerializedPropertyUserData instance = new SerializedPropertyUserData(); private static StringBuilder sb = new StringBuilder(); private Dictionary storage = new Dictionary(); internal TUserData this[SerializedProperty property] { get { var key = MakeKey(property); TUserData data; if (!storage.TryGetValue(key, out data)) return null; return data; } set { var key = MakeKey(property); storage[key] = value; } } private string MakeKey(SerializedProperty property) { if (property == null) throw new System.ArgumentException(); var so = property.serializedObject; if (so == null) throw new System.ArgumentException(); var to = so.targetObject; if (to == null) throw new System.ArgumentException(); sb.Length = 0; sb.Append(to.GetInstanceID().ToString()); sb.Append(property.propertyPath); return sb.ToString(); } } }