bool VisitEnum <TContainer, TValue>( InspectorContext inspectorContext, IProperty <TContainer> property, ref TValue value, PropertyPath path, bool isWrapper) { var inspector = GetCustomInspector(property, ref value, path, isWrapper); if (null == inspector) { if (RuntimeTypeInfoCache <TValue> .IsEnumFlags) { GuiFactory.FlagsField(property, ref value, path, inspectorContext); } else { GuiFactory.EnumField(property, ref value, path, inspectorContext); } } else { using (inspectorContext.MakeIgnoreInspectorScope()) { var customInspector = new CustomInspectorElement(path, inspector, inspectorContext.Root); inspectorContext.Parent.contentContainer.Add(customInspector); } } return(true); }
public VisitStatus Visit <TContainer>(Property <TContainer, KeyValuePair <TKey, TValue> > property, ref TContainer container, ref KeyValuePair <TKey, TValue> value) { var visitor = DictionaryElement.GetVisitor(); visitor.AddToPath(property); try { var inspector = (IInspector <KeyValuePair <TKey, TValue> >) new KeyValuePairInspector <TDictionary, TKey, TValue> { DictionaryElement = DictionaryElement }; inspector.Context = new InspectorContext <KeyValuePair <TKey, TValue> >( visitor.VisitorContext.Root, visitor.GetCurrentPath(), property ); var customInspector = new CustomInspectorElement( visitor.GetCurrentPath(), inspector, visitor.VisitorContext.Root); visitor.VisitorContext.Parent.contentContainer.Add(customInspector); } finally { visitor.RemoveFromPath(property); } return(VisitStatus.Stop); }
protected override void VisitProperty <TContainer, TValue>(Property <TContainer, TValue> property, ref TContainer container, ref TValue value) { if (!RuntimeTypeInfoCache.IsContainerType(value.GetType())) { return; } var isWrapper = typeof(PropertyWrapper <TValue>).IsInstanceOfType(container); if (!isWrapper) { AddToPath(property); } try { var path = GetCurrentPath(); using (var references = VisitorContext.MakeVisitedReferencesScope(this, ref value, path)) { if (references.VisitedOnCurrentBranch) { VisitorContext.Parent.Add(new CircularReferenceElement <TValue>(VisitorContext.Root, property, value, path, references.GetReferencePath())); return; } var inspector = default(IInspector); if (!path.Empty || EnableRootCustomInspectors) { var visitor = new CustomInspectorVisitor <TValue>(); visitor.PropertyPath = path; visitor.Root = VisitorContext.Root; visitor.Property = property; PropertyContainer.Visit(ref value, visitor); inspector = visitor.Inspector; } var old = EnableRootCustomInspectors; EnableRootCustomInspectors = true; if (null != inspector) { var customInspector = new CustomInspectorElement(path, inspector, VisitorContext.Root); VisitorContext.Parent.contentContainer.Add(customInspector); } else { RecurseProperty(ref value, property, path); } EnableRootCustomInspectors = old; } } finally { if (!isWrapper) { RemoveFromPath(property); } } }
VisitStatus VisitPrimitive <TContainer, TValue, TElement>( IProperty <TContainer> property, ref TValue value, DrawHandler <TContainer, TValue, TElement> handler ) { Visitor.AddToPath(property); try { var path = Visitor.GetCurrentPath(); var inspector = AllowInspector ? GetPropertyDrawer <TValue>(property, Visitor.VisitorContext.Root, path) : null; NoReentrace = true; if (null == inspector) { handler(property, ref value, path, VisitorContext); } else { var customInspector = new CustomInspectorElement(path, inspector, Visitor.VisitorContext.Root); Visitor.VisitorContext.Parent.contentContainer.Add(customInspector); } } finally { Visitor.RemoveFromPath(property); NoReentrace = false; } return(VisitStatus.Stop); }
public VisitStatus Visit <TContainer, TValue>(Property <TContainer, TValue> property, ref TContainer container, ref TValue value) { if (RuntimeTypeInfoCache <TValue> .IsEnum) { Visitor.AddToPath(property); try { var path = Visitor.GetCurrentPath(); var inspector = AllowInspector ? GetInspector <TValue>(property, VisitorContext.Root, path) : null; NoReentrace = true; if (null != inspector) { var customInspector = new CustomInspectorElement(path, inspector, Visitor.VisitorContext.Root); Visitor.VisitorContext.Parent.contentContainer.Add(customInspector); return(VisitStatus.Stop); } } finally { NoReentrace = false; Visitor.RemoveFromPath(property); } return(RuntimeTypeInfoCache <TValue> .IsEnumFlags ? VisitPrimitive(property, ref value, GuiFactory.FlagsField) : VisitPrimitive(property, ref value, GuiFactory.EnumField)); } return(VisitStatus.Unhandled); }
bool TryVisitWithCustomInspector <TDeclaredValue>(ref TDeclaredValue value, PropertyPath path, IProperty property) { var inspector = GetCustomInspector(ref value, path, property); var old = EnableRootCustomInspectors; EnableRootCustomInspectors = true; if (null != inspector) { var customInspector = new CustomInspectorElement(path, inspector, VisitorContext.Root); VisitorContext.Parent.contentContainer.Add(customInspector); return(true); } EnableRootCustomInspectors = old; return(false); }
public bool Visit <TContainer>(InspectorVisitor.InspectorContext inspectorContext, IProperty <TContainer> property, ref KeyValuePair <TKey, TValue> value, PropertyPath path) { var visitor = DictionaryElement.GetVisitor(); var inspector = (IInspector <KeyValuePair <TKey, TValue> >) new KeyValuePairPropertyInspector <TDictionary, TKey, TValue> { DictionaryElement = DictionaryElement }; inspector.Context = new InspectorContext <KeyValuePair <TKey, TValue> >( visitor.Context.Root, path, property ); var customInspector = new CustomInspectorElement( path, inspector, visitor.Context.Root); visitor.Context.Parent.contentContainer.Add(customInspector); return(true); }
bool PrimitiveVisit <TValue, TElement>( InspectorContext inspectorContext, IProperty property, ref TValue value, PropertyPath path, FactoryHandler <TValue, TElement> handler) { var inspector = GetAttributeDrawer(property, ref value, path); if (null == inspector) { handler(property, ref value, path, inspectorContext); } else { using (inspectorContext.MakeIgnoreInspectorScope()) { var customInspector = new CustomInspectorElement(path, inspector, inspectorContext.Root); inspectorContext.Parent.contentContainer.Add(customInspector); } } return(true); }
void IPropertyVisitor.Visit <TContainer, TValue>( Property <TContainer, TValue> property, ref TContainer container) { if (IsExcluded(property)) { return; } var value = property.GetValue(ref container); var isWrapper = container is PropertyWrapper <TValue>; Context.IsRootObject = isWrapper; // Null values if (RuntimeTypeInfoCache <TValue> .CanBeNull && ShouldBeTreatedAsNull(property, ref container, ref value) && ShouldStayNull(property, ref container, ref value)) { using (Context.MakePathScope(property)) { if (VisitNull(Context, property, ref value, Context.CopyCurrentPath())) { return; } } } foreach (var adapter in m_AdapterOverrides) { if (!(adapter is IInspectorVisit <TValue> partiallyTyped)) { continue; } using (Context.MakePathScope(property)) { if (partiallyTyped.Visit(Context, property, ref value, Context.CopyCurrentPath())) { return; } } } // Primitives if (this is IInspectorVisit <TValue> typed) { using (Context.MakePathScope(property)) { if (typed.Visit(Context, property, ref value, Context.CopyCurrentPath())) { return; } } } // UnityEngine.Object if (this is IInspectorContravariantVisit <TValue> contravariant) { using (Context.MakePathScope(property)) { if (contravariant.Visit(Context, property, value, Context.CopyCurrentPath())) { return; } } } // Enums if (RuntimeTypeInfoCache <TValue> .IsEnum) { using (Context.MakePathScope(property)) { if (VisitEnum(Context, property, ref value, Context.CopyCurrentPath(), isWrapper)) { return; } } } try { // Regular visit if (!isWrapper) { Context.AddToPath(property); } var path = Context.CopyCurrentPath(); using (var references = Context.MakeVisitedReferencesScope(ref value, path)) { if (references.VisitedOnCurrentBranch) { Context.Parent.Add(new CircularReferenceElement <TValue>(Context.Root, property, value, path, references.GetReferencePath())); return; } var inspector = GetCustomInspector(property, ref value, path, isWrapper); if (null != inspector) { var customInspector = new CustomInspectorElement(path, inspector, Context.Root); Context.Parent.contentContainer.Add(customInspector); return; } if (path.PartsCount > 0) { if (string.IsNullOrEmpty(GuiFactory.GetDisplayName(property))) { PropertyContainer.TryAccept(this, ref value); } else { // Give a chance for different property bags to handle themselves if (PropertyBagStore.TryGetPropertyBagForValue(ref value, out var valuePropertyBag)) { switch (valuePropertyBag) { case IDictionaryPropertyAccept <TValue> accept: accept.Accept(this, property, ref container, ref value); break; case IListPropertyAccept <TValue> accept: accept.Accept(this, property, ref container, ref value); break; case ISetPropertyAccept <TValue> accept: accept.Accept(this, property, ref container, ref value); break; case ICollectionPropertyAccept <TValue> accept: accept.Accept(this, property, ref container, ref value); break; default: var foldout = GuiFactory.Foldout <TValue>(property, path, Context); using (Context.MakeParentScope(foldout)) PropertyContainer.TryAccept(this, ref value); break; } } } } else { PropertyContainer.TryAccept(this, ref value); } } } finally { if (!isWrapper) { Context.RemoveFromPath(property); } } }