private void CacheBindingCollections(SerializedProperty property, DrawerCache cache) { cache.BindingMap = new Dictionary <string, BindingEntry>(); List <string> optionIds = new List <string>(); List <string> options = new List <string>(); optionIds.Add("None"); options.Add("None"); foreach (Juice.BindingEntry current in BindingUtils.GetBindings(cache.BaseComponent.transform, ResolveTarget(property).Type)) { if (current.ViewModelComponent != cache.BaseComponent) { string id = GenerateBindingId(current.ViewModelComponent, current.PropertyName); BindingEntry entry = new BindingEntry( optionIds.Count, current.ViewModelComponent, current.PropertyName, current.ObservableType, current.GenericArgument, current.NeedsToBeBoxed); cache.BindingMap.Add(id, entry); optionIds.Add(id); options.Add(GenerateOptionString(id, entry)); } } cache.CachedOptionIds = optionIds.ToArray(); cache.CachedOptions = options.ToArray(); }
private static void AddTypeToCache(Type type, string newId, DrawerCache cache) { if (cache.TypeMapByType.TryGetValue(type, out string currentId) == false || newId.Length > currentId.Length) { cache.TypeMapByType[type] = newId; cache.TypeMapByString[newId] = type; } }
private void CacheBaseComponent(SerializedProperty property, DrawerCache cache) { cache.BaseComponent = property.serializedObject.targetObject as Component; if (cache.BaseComponent) { cache.LastParent = cache.BaseComponent.transform.parent; } }
public override bool Draw(string label, ref AssetRef <T> obj, RenderContext rc) { object assetName = obj.ID.Value; if (DrawerCache.GetDrawer(typeof(string)).Draw(label, ref assetName, rc)) { obj = new AssetRef <T>((string)assetName); return(true); } return(false); }
private void SetupCache(SerializedProperty property) { string id = $"{property.serializedObject.targetObject.GetInstanceID().ToString()}{property.propertyPath}"; if (CacheMap.TryGetValue(id, out cache) == false) { cache = new DrawerCache(); CacheTypeCollections(cache); CacheMap[id] = cache; } }
private void CacheTypeCollections(DrawerCache cache) { var typeConstraint = fieldInfo.GetCustomAttribute <TypeConstraintAttribute>(); cache.TypeMapByType = new Dictionary <Type, string>(); cache.TypeMapByString = new Dictionary <string, Type>(); var matchingGroups = new Dictionary <string, List <Type> >(); foreach (Type current in TypeCache.GetTypesDerivedFrom(typeConstraint.BaseType)) { if (IsMatchingType(current, typeConstraint)) { AddTypeToCache(cache, current, matchingGroups); } } }
private void CacheData(SerializedProperty property) { string id = property.GetUniqueId(); SerializedProperty listProperty = property.FindPropertyRelative("bindingInfoList"); if (CacheMap.TryGetValue(id, out cache)) { cache.ReorderableList.serializedProperty = listProperty; } else { cache = new DrawerCache(); cache.Target = property.GetValue <BindingInfoList>(); cache.ReorderableList = CreateList(listProperty, cache.Target); CacheMap[id] = cache; } }
private static void FixMatchingTypeIds(DrawerCache cache, List <Type> group) { for (int i = 0; i < group.Count; i++) { Type target = group[i]; for (int j = i + 1; j < group.Count; j++) { Type other = group[j]; string targetId = GetDistinctName(target, other); AddTypeToCache(target, targetId, cache); string otherId = GetDistinctName(other, target); AddTypeToCache(other, otherId, cache); } } }
private static void AddTypeToCache(DrawerCache cache, Type current, Dictionary <string, List <Type> > matchingGroups) { string typeId = current.GetPrettifiedName(); if (matchingGroups.TryGetValue(typeId, out List <Type> group)) { group.Add(current); FixMatchingTypeIds(cache, group); } else { var newGroup = new List <Type> { current }; matchingGroups.Add(typeId, newGroup); AddTypeToCache(current, typeId, cache); } }
private void SetupCache(SerializedProperty property) { string cacheId = $"{property.serializedObject.targetObject.GetInstanceID().ToString()}{property.propertyPath}"; CacheMap.TryGetValue(cacheId, out cache); if (cache != null && (cache.BaseComponent == null || cache.BaseComponent.transform.parent != cache.LastParent)) { cache = null; } if (cache == null) { cache = new DrawerCache(); CacheBaseComponent(property, cache); CacheBindingCollections(property, cache); CacheMap[cacheId] = cache; } }
private void CacheData(SerializedProperty property) { string id = property.GetUniqueId(); object[] listProperty = property.FindPropertyRelative(KeysName).GetPropertyValueArray(); if (CacheMap.TryGetValue(id, out cache)) { cache.ReorderableList.list = listProperty; } else { cache = new DrawerCache(); cache.ReorderableList = CreateList(listProperty); CacheMap[id] = cache; } cache.DictionaryProperty = property; }